How to pass variables to dialplan?


is it possible to pass variables / arguments and use them in dialplan? I am calling an extension with originate call using asterisk-php-api (‎) like this


  • Originate Call

try {
$ast->originateCall (‘1000’, ‘SIP/provider/+123456789’ , ‘outgoing’, ‘+122222092’, 1, 30000, array(“FOO”=>“value1”, “BAR”=>“value2”));
} catch (PEAR_Exception $e) {
echo $e;

I would expect to have those variables available in my dialplan:

exten => 1000,1,Background(/data/sounds/beep)
same => n,Background(/data/sounds/${FOO})
same => n,Background(/data/sounds/${BAR})
same => n,Hangup()

They are not.

Am I missing something? Can this be done?

Using call files you usually use the SET keyword and then the variables are availables in the dialplan. Check if the way you are generating the call support it, if not you may change the way you send the call.

Do you mean phpagi? Support for that is provided at

AGI::set_variable() in phpagi.php
Sets a variable to the specified value. The variables so created can later be used by later using ${} in the dialplan.

[quote]example :

<? $time=1368597301; $agi->set_variable("calltime",$time); ?>

Dial plan

1 Like

He’s doing an originate, and the handling of variables for that is likely to be complicated. I assume that this third party PHP library calls the originate application. That application doesn’t pass the incoming channel to the Asterisk core when creating the new channel, so I don’t think any variables can propagate, even if you made them inheritable.

1 Like

Thank you, I managed to install phpagi. So now I am, able to run php scripts inside my dialplan and pass variables from dialplan to scripts. That’s fine.

But still, I need to first trigger a call (using origionate at the moment) from my web application and at that moment also pass information (variables) to dialplan so it can be passed to agiscripts. Obviously I am missing something here…

My use case: I need to make automated phone call when user makes action in php app, to external number and when picked up, a message containing information (numbers) would be read to user.

Thank you very much for suggestions

you can not use $agi->set_variable because you want to originate a new call and the variable will unset . I have the same experience for such an application . You should save the variable in database ( I used MYSQL ) you can not use uniqueid to save variable as well because it will change after you originate . I used callerid and a flag field in database to save my variables and can fetch them .

id | callerid | viwedFlad | variable |

1 | 44267518 | 0 | samplefile |

1 Like

Thank you