Asterisk 15 + AGI = unable to catch CALLERID(num)

Hello people,

I have a telephone line with n operators. In case of incoming call all n operators have their phonesets ringing. When a certain operator picks up the phone, I need AGI to catch his/her internal number + calling party’s number and send both params to some external system over http with curl.

The problem is that I cannot do this:

exten => 6,n,Dial(SIP/2001&SIP/2002&SIP/2003,20)
exten => 6,n,AGI(/var/lib/asterisk/agi-bin/script.sh)

Because AGI() will be called after the operator’s hang up.

And I cannot do like this:

exten => 6,n,AGI(/var/lib/asterisk/agi-bin/script.sh)
exten => 6,n,Dial(SIP/2001&SIP/2002&SIP/2003,20)

Because we don’t know operator’s number yet.

One of the solution that I found is to call Dial() with U() sub-function like this:

[main-context]
...
exten => 6,n,Dial(SIP/2001&SIP/2002&SIP/2003,20,U(agi-context))

[agi-context]
exten => s,1,AGI(/var/lib/asterisk/agi-bin/script.sh)
exten => s,n,Return()

Using U() I am unable to catch CALLERID(num) within [agi-context]. Setting variables in the [main-context] also does not work. I know that setting a variable with SET() in one context should be visible/accessible in another, but in fact U() breaks this logic. The only way is to set the GLOBAL variable in [main-context] and catch it in [agi-context]. But I think this is absolutely incorrect in case of having several parallel calls.

Could you advise me another way to accomplish this task?

Thank you in advance.

U is run on a different channel. You should be able to set a variable, but you will need to prefix it with _ on the Set.

1 Like

Hello! I really appreciate your advice. Thanks, it helped.
Best regards!

1 Like

Welcome @IgorZem! If you are satisfied, then marking the post by @david551 as the solution might be helpful for the next user who has a similar question. You may also find further information on Variable Inheritance in the Asterisk documentation.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.