Upgrade 3CX to v18 and get it hosted free!

Asterisk h extension

Author image

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 Asterisk cmd 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


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.