Asterisk h extension

The h extension


Gets executed after a call has been terminated.

Use DeadAGI instead of AGI here.
Do not call Hangup from within the h extension.

When the 'h' extension is running, the call legs have already been torn down. There is no way to delay this happening, and you can't do anything in the 'h' extension that needs to read audio from the channel (since no audio will appear, the first time it tries to read audio it will abort). Thus Playback() or Background(), for example, does not work. Essentially, the only things that make sense to use in the 'h' extension are those that don't have anything to do with the external channel that was involved before the hangup. No audio, no DTMF, etc.

June 2010: Wait() could be modified to work on a dead channel, but as it stands right now the code assumes the channel is alive, and to ensure that things work properly, it has to read incoming media from the channel so it can be discarded... and if at any time waiting for or reading media from the channel fails, it exits, because there's no point in continuing to wait since the call is gone. Instead of Wait() use something like "System(sleep 3)".

Note

Use with great care: Apparently some channel variables get destroyed when the call is hung up, and those variables aren't available anymore (or have inconsistent values) when the h extension is being called. Therefore you shouldn't rely on this special extension for billing/calling card purposes.

THE HIGHLIGHTED STATEMENT ABOVE NEEDS TO BE REVIEWED. I HAVE ROUTINELY USED ALL CHANNEL VARIABLES SUCCESSFULLY IN THE h EXTENSION WITHOUT ANY TROUBLE. IN FACT, I AM USING IT FOR BILLING (BY LAUNCHING AN AGI SCRIPT THAT WRITES THE CDR IN A CUSTOM DB)

${CHANNEL} correctly delivers the channel that was/is to be hung up
${EXTEN} shows 'h', so that's probably not what you are interested in

Be aware: Macros require their own h extension as they do not make use of the calling context's h extension!

Update:
With bug/patch 6193 Asterisk 1.4 will now close the CDR before entering the h extension if the corresponding option has been set. This means that e.g. a DeadAGI() script called from h is able to access and act on the call's CDR data.

add an option to cdr.conf that enables ending CDRs before executing the "h" extension as opposed to afterwards


See also

  • Monitor with option 'm' to trigger an action after the monitored call has been completed


Go back to Asterisk standard extensions

The h extension


Gets executed after a call has been terminated.

Use DeadAGI instead of AGI here.
Do not call Hangup from within the h extension.

When the 'h' extension is running, the call legs have already been torn down. There is no way to delay this happening, and you can't do anything in the 'h' extension that needs to read audio from the channel (since no audio will appear, the first time it tries to read audio it will abort). Thus Playback() or Background(), for example, does not work. Essentially, the only things that make sense to use in the 'h' extension are those that don't have anything to do with the external channel that was involved before the hangup. No audio, no DTMF, etc.

June 2010: Wait() could be modified to work on a dead channel, but as it stands right now the code assumes the channel is alive, and to ensure that things work properly, it has to read incoming media from the channel so it can be discarded... and if at any time waiting for or reading media from the channel fails, it exits, because there's no point in continuing to wait since the call is gone. Instead of Wait() use something like "System(sleep 3)".

Note

Use with great care: Apparently some channel variables get destroyed when the call is hung up, and those variables aren't available anymore (or have inconsistent values) when the h extension is being called. Therefore you shouldn't rely on this special extension for billing/calling card purposes.

THE HIGHLIGHTED STATEMENT ABOVE NEEDS TO BE REVIEWED. I HAVE ROUTINELY USED ALL CHANNEL VARIABLES SUCCESSFULLY IN THE h EXTENSION WITHOUT ANY TROUBLE. IN FACT, I AM USING IT FOR BILLING (BY LAUNCHING AN AGI SCRIPT THAT WRITES THE CDR IN A CUSTOM DB)

${CHANNEL} correctly delivers the channel that was/is to be hung up
${EXTEN} shows 'h', so that's probably not what you are interested in

Be aware: Macros require their own h extension as they do not make use of the calling context's h extension!

Update:
With bug/patch 6193 Asterisk 1.4 will now close the CDR before entering the h extension if the corresponding option has been set. This means that e.g. a DeadAGI() script called from h is able to access and act on the call's CDR data.

add an option to cdr.conf that enables ending CDRs before executing the "h" extension as opposed to afterwards


See also

  • Monitor with option 'm' to trigger an action after the monitored call has been completed


Go back to Asterisk standard extensions

Created by: JustRumours, Last modification: Mon 07 of Feb, 2011 (04:11 UTC) by asiby
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+