Asterisk Dialplan: How to detect when a call has been successfully answered?

5.6k views Asked by At

I'm having a really hard time figuring out if there is a trigger or a way to continue from the Dial action that allows you to detect if the call is answered. It seems like Dial doesn't respond until hangup, busy, or congested. What action or event am I missing that would tell me when the other end of the line actually answers the call? Hoping there is something like this available that I'm just missing:

exten => s,7,Dial(${ARG1},20,rt)       ; Ring the interface, 20 seconds maximum
exten => s,8,Goto(s-${DIALSTATUS},1)                    
; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
exten => s-ANSWER(do something)
2

There are 2 answers

2
Jb1128 On

Finally figured it out. It involves calling the M flag in the Dial action call. By calling the M flag, you can call a custom macro that will execute immediately after the call is connected/answered.

Ex: Dial(SIP/200,60,M(myCustomMacro))

Hope this helps for any that were also curious.

0
viktike On

You can also do a Gosub when call is answered:

asterisk*cli> core show application Dial
...
    U(x[^arg[^...]]):
        x - Name of the subroutine to execute via Gosub
        arg - Arguments for the Gosub routine
Execute via Gosub the routine <x> for the *called* channel before connecting to
the calling channel. Arguments can be specified to the Gosub using '^' as a
delimiter. The Gosub routine can set the variable ${GOSUB_RESULT} to specify
the following actions after the Gosub returns