Passing Variables Through Dialplan

Hello everyone.

I have a script that originates a call from a json, then passes it to my dialplan. Everything to here is okay but there the issue rises when I try to pass my variable in the script that sends call to dialplan to the dialplan itself. I have a $callernum variable in originate.php and from another callplan.php I send call to dialplan via $agi->exec(‘Dial’, “Local/$phone@$context/n”) .

Call send via $agi->exec seems to unset variables and I’m not able to get my $callernum as I send the call originated from me back to queue. Seeing this I tried to omit $agi->exec and rather set variables in callplan.php and then include it in dialplan directly via AGI like below.

exten => 10001,1,AGI(berkay/callplan.php)
exten => 10001,n,AGI(berkay/through.php)
exten => 10001,n,Set(CALLERID(name)=${callernum})
exten => 10001,n,Set(CDR(accountcode)=${cus_id})
exten => 10001,n,Goto(from-queue,1000,1)

Alas, no chance. I seek ways to pass my variable in callplan.php to the dialplan so I can set CALLERID. Any help would be appreciated.

You are mixing variables within your scripting language with variables in the dialplan. They aren’t synced, you have to explicitly use the AGI mechanism to set a dialplan variable to set it.

$agi->set_variable(“callernum”, $callerid) is the way I set the $callernum variable. I didn’t think there would be a problem but is there seem to be any with my implementation?

Nope, that seems to be fine. What does NoOp on the dialplan variable show? Have you confirmed that your AGI is indeed doing that, and that it succeeds?

My tests were of two days ago so no fresh log unfortunately. I will post as soon as produce any.

But NoOp didn’t show anything. Even though I was able to get the value with $agi->verbose($value) right after I set the variable, neither noop nor any other operation in dialplan gave a hint that variable has passed through. I was wondering that if it is the case that Asterisk creates/redirects to another channel when a call originated by random script to dialplan, again via random script. It was discussed here that set_variable is not to be used since Asterisk unsets the variable on the way from originate. Last resort would be to insert to database and then call elsewhere to use that variable but I would like do without db.

Sorry for the mess since I’m pretty much a newbie around, and thanks for help.

That verbose would have used the variable within your AGI, not a dialplan variable. I’d suggest giving a full example that demonstrates the problem.