Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: fix bad 'same=>s,1' in examples

...

The following example shows one way of accessing the channels that have hangup cause related information after a Dial has completed. In this particular example, a parallel dial occurs to both SIP/foo and SIP/bar. A hangup handler has been attached to the calling channel, which executes the subroutine at handler,s,1 when the channel is hung up. This queries the HANGUPCAUSE_KEYS function for the channels with hangup cause information and prints the information as a Verbose message. On the CLI, this would look something like:

Code Block

Channels with hangup cause information: SIP/bar-00000002,SIP/foo-00000001
Code Block

[default]

exten => s,1,NoOp()
 same => n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
 same => n,Dial(SIP/foo&SIP/bar,10)
 same => n,Hangup()

[handler]

sameexten => s,1,NoOp()
 same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
 same => n,Verbose(0, Channels with hangup cause information: ${HANGUPCAUSE_STRING})
 same => n,Return()

HANGUPCAUSE

...

This example illustrates obtaining hangup cause information for a parallel dial to SIP/foo and SIP/bar. A hangup handler has been attached to the calling channel, which executes the subroutine at handler,s,1 when the channel is hung up. This queries the hangup cause information using the HANGUPCAUSE_KEYS function and the HANGUPCAUSE function. The channels returned from HANGUPCAUSE_KEYS are parsed out, and each is queried for their hangup cause information. The technology specific cause code as well as the Asterisk cause code are printed to the CLI.

Code Block

[default]

exten => s,1,NoOp()
 same => n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
 same => n,Dial(SIP/foo&SIP/bar,10)
 same => n,Hangup()

[handler]

exten => s,1,NoOp()

same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})

; start loop
same => n(hu_begin),NoOp()

; check exit condition (no more array to check)
same => n,GotoIf($[${LEN(${HANGUPCAUSE_STRING})}=0]?hu_exit)

; pull the next item
same => n,Set(ARRAY(item)=${HANGUPCAUSE_STRING})
same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:${LEN(${item})}})

; display the channel name and cause codes
same => n,Verbose(0, Got Channel ID ${item} with Technology Cause Code ${HANGUPCAUSE(${item},tech)}, Asterisk Cause Code ${HANGUPCAUSE(${item},ast)})

; check exit condition (no more array to check)
same => n,GotoIf($[${LEN(${HANGUPCAUSE_STRING})}=0]?hu_exit)

; we still have entries to process, so strip the leading comma
same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:1})

; go back to the beginning of the loop
same => n,Goto(hu_begin)

same => n(hu_exit),NoOp()
same => n,Return()

...

The following example clears the hangup cause information from the channel if SIP/foo fails to answer and execution continues in the dialplan. The hangup handler attached to the channel will thus only report the the name of the last channel dialled.

Code Block

exten => s,1,NoOp()
 same => n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
 same => n,Dial(SIP/foo,10)
 same => n,HangupCauseClear()
 same => n,Dial(SIP/bar,10)
 same => n,Hangup()

[handler]

sameexten => s,1,NoOp()
 same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
 same => n,Verbose(0, Channels with hangup cause information: ${HANGUPCAUSE_STRING})
 same => n,Return()