I’m facing a very small problem with Dial() functionality, I want to run custom API on remote server when Dial() transfer call is answered at agent end.
Let me explain in more details
When incoming call is answered on Asterisk Server then Dial() functionality pick only mapped agent number and bridge the incoming call to the respective agents
My requirement is to run custom API on Remote Server when agent answered that call.
Presuming you are using Dial (and not Queue) application to connect to an Agent, you can use option U with Dial.
U( x^arg ) - 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.
NOTE: You cannot use any additional action post answer options in conjunction with this option. Also, pbx services are run on the called channel, so you will not be able to set timeouts via the TIMEOUT() function in this routine.
GOSUB_RESULT
ABORT - Hangup both legs of the call.
CONGESTION - Behave as if line congestion was encountered.
BUSY - Behave as if a busy signal was encountered.
CONTINUE - Hangup the called party and allow the calling party to continue dialplan execution at the next priority.
GOTO:[[<CONTEXT>^]<EXTEN>^]<PRIORITY> - Transfer the call to the specified destination.
x - Name of the subroutine context to execute via Gosub. The subroutine execution starts in the named context at the s exten and priority 1.
arg[^arg...] - Arguments for the Gosub routine
Note -> Here I’m repeating my requirement again When Dialing event have initiated by using Asterisk Dial(SIP/XXXXXXXXX,50,Options) function after successful call is connected via SIP Protocol to the agent Phone then I want to run custom API on remote server
You should be using option U with Dial if you want something to get executed on answer. G,b and B options are for some other purposes.
b( context^exten^priority ) - Before initiating an outgoing call, Gosub to the specified location using the newly created channel. The Gosub will be executed for each destination channel.
context
exten
priority( params )
arg1[^arg1...]
argN
B( context^exten^priority ) - Before initiating the outgoing call(s), Gosub to the specified location using the current channel.
context
exten
priority( params )
arg1[^arg1...]
argN
G( context^exten^priority ) - If the call is answered, transfer the calling party to the specified priority and the called party to the specified priority plus one.
NOTE: You cannot use any additional action post answer options in conjunction with this option.
context
exten
priority
Thanks for your quick support
Doing this is helping to run API on remote server but second problem has been raised
I’m running Hangup Extension on incoming context when user (Agent) disconnect the calls still channel is connected and call is being connected.
Below is the code sample :
[macro-livecall]
exten => s,1,NoOp(ARG1={ARG1} ARG2={ARG2})
same => n,AGI(agiWrapper.agi,ADG^liveapi_call_details)
same => n,Return()
[macro-To-IBD-Call-Flow]
exten => s,1,Set(date_time={STRFTIME({EPOCH},%Y%m%d-%H%M%S)})
same => n,Dial(SIP/${adg_transfer_number}@outgoing,50,U(macro-livecall^1^2))
[macro-Hangup-Call-Flow]
exten => h,1,Verbose(1,In Hangup State… Posting CDR)
same => n,AGI(agiWrapper.agi,ADG^liveapi_call_details)
same => n, Hangup()
same => n,Dial(SIP/{transfer_number}@outgoing,50,U(macro-livecall^{session}^{transfer_number}^{call_flow}^{CDR(start)}^{calling_no}^{DIALSTATUS}^{virtual_transfer_number}^{DIALEDPEERNUMBER:0:-8}^{UNIQUEID}))
{DIALSTATUS}** This is for Call status wither Answered or No Answer
**{DIALEDPEERNUMBER:0:-8} This is for picked CC number details
I’m not able to capture {DIALSTATUS} And {DIALEDPEERNUMBER:0:-8} using
same => n,Dial(SIP/alice,U(my_gosub_routine^my_gosub_arg1^my_gosub_arg2))
Let me share working code
[incoming]
exten => _X.,1,macro(To-IBD-Call-Flow)
exten => h,1,GoTo(macro-Hangup-Call-Flow,h,1)
[macro-To-IBD-Call-Flow]
exten => s,1,Set(date_time={STRFTIME({EPOCH},%Y%m%d-%H%M%S)})
same => n,AGI(SetSessionID.agi)
sample line of codes …
…
…
same => n,Dial(SIP/{transfer_number}@incoming,50,U(macro-livecall^{id_session}^{number}^{call_flow}^{CDR(start)}^{calling_no}^{DIALSTATUS}^{transfer_number}^{DIALEDPEERNUMBER:0:-8}^{UNIQUEID}))
sample line of codes …
…
…
[macro-livecall]
exten => s,1,Set(id_session=${ARG1})
same => n,Set(number=${ARG2})
same => n,Set(call_flow=${ARG3})
same => n,Set(start_date_time=${ARG4})
same => n,Set(calling_no=${ARG5})
same => n,Set(b_call_status=${ARG6})
same => n,Set(transfer_number=${ARG7})
same => n,Set(agent_call_received=${ARG8})
same => n,Set(unique_id=${ARG9})
same => n,AGI(agiWrapper.agi,API^live_cdr_details)
same => n,Return()
I want to capture DIALSTATUS And DIALEDPEERNUMBER:0:-8 (whose pick the call when we have multiple numbers) on answered call at agent end
DIALSTATUS doesn’t exist because Dial() hasn’t been called at the point when the variable is substituted. DIALEDPEERNUMBER is the same.
DIALSTATUS is pointless, as the subroutine will only get called if the call has been answered.
You need to read the variable directly, in the subroutine, although I don’t think DIALSTATUS will be set on the B leg, and may not yet be set on the A leg.
${<variablename>} or, as you are probably not running on the channel that has the variable, ${IMPORT(<channel>,<variablename>)}. Angle brackets are not literal; they indicate a meta-name.
You can also make copies which inherit across the Dial, by doing Set(_<variablename2>=${<variablename1>}).
You mean to say that I can use variable on next dial-plan once call has received
[macro-livecall]
exten => s,1,Set(id_session=${ARG1})
same => n,Set(number=${ARG2})
same => n,Set(call_flow=${ARG3})
same => n,Set(start_date_time=${ARG4})
same => n,Set(calling_no=${ARG5})
same => n,Set(b_call_status=${ARG6})
same => n,Set(transfer_number=${ARG7})
same => n,Set(agent_call_received=${ARG8})
same => n,Set(unique_id=${ARG9})
same => n,AGI(agiWrapper.agi,API^live_cdr_details)
same => n,Return()
You can do, but I meant that you can use them on the right hand side of the = (or without the Set). Normal variables have channel or global scope.
I won’t give specific examples, because, firstly, my aim is to teach you how to fish, not to give you fish, and, secondly, I would have to do significant work to check that all the variables in my example were actually set at the time the subroutine was run.