Dial two extensions and execute routine in first pick up [solved]


I’m working with Asterisk 1.8.13

I have a queue that dials two extensions, and it’s needed that the answering extension calls to an external app through curl. The curl call is executed by the “e” option from dial.

This is a test dial plan,


exten => 200,1,Dial(Local/101@test&Local/102@test,20,Ttme)
exten => 200,n,Hangup

exten => _X.,1,Dial(SIP/${EXTEN},150,U(curl,${EXTEN},${CALLERID(number)}))
same => n,Hangup

exten => s,1,Set(CURLOPT(conntimeout)=1)
same => n,Set(CURLOPT(httptimeout)=1)
same => n,Set(foo=${CURL(http:/urlWithParams)})
same => n,Return()

It works, but when both extensions are answered simultaneously, curl call is executed in both, and this is wrong. I tried to get ${DIALSTATUS} in my curl context to check if it is the real answering extension, but it’s empty.

Any idea?

Thanks and regards

Have you tried using multiple members in your queues.conf instead of dialing 2 members at the same time in your from-queue context?


exten => 101,1,Dial(SIP/${EXTEN},150,TtmeU(curl,${EXTEN},${CALLERID(number)}))
exten => 102,1,Dial(SIP/${EXTEN},150,TtmeU(curl,${EXTEN},${CALLERID(number)}))
exten => _10[12],2,Hangup()

Queues would have the same problem. The issue is that originating side of the local channel isn’t being answered until the curl has been issued. I’m not sure if this is just because of the general propagation delays for the answer event, or whether U is run before the the answer is propagated, but basically you need to run the curl on the Dial with the &.

You are right, calling from queues has the same issue.

Sorry, but I don’t know how to use & to execute curl in dial, could you show me an example?

Maybe I’m using a wrong approach, I only want to send call info to a CRM at pick up. Is there a better solution?

I tried to skip the second curl with a db flag, but It’s wrong because second extension has the call.

After first extension pick up the call, the second extension “steals” the call, then the problem is that the first one has sent the curl call but it hasn’t the call.

So the goal is to send your CRM something when the call connects correct?

The Wiki indicates you can do that in your Queue() command with the Gosub option


gosub - Will run a gosub on the called party’s channel (the queue member) once the parties are connected.

Have you tried that?

Thanks a lot, johnkiniston, it worked.

I was using dial from context because I didn’t know how to get the member who answers to send to CRM (s extension in subroutine) . Finally, I’ve found that CALLNUMBER(num) (or CHANNEL) inside the routine context gives the extension, I don’t know why it’s not the original caller number, and I suppose that there is another variable to get the extension who answered (EXTEN returns s), but it works.

I think that the problem launching the curl call from the dial function is that untill it finish the queue doesn’t that the call is answered, because changing curl call for NoOp I can’t reproduce the issue of answering two extensions simultaneously.

I am glad I was able to help you out.