Asterisk & PHP AGI

Get help with installing, upgrading and running Asterisk.

Moderators: muppetmaster, Moderator, Support

Asterisk & PHP AGI

Postby anya » Thu Apr 26, 2012 1:18 pm

Hello everyone,

I'm newbie with asterisk and if you have time, please advice me. I want to run php script, for example I want to analyse some conditions and every time for every condition I set variable, for examle $call. Then I want to send variable $call into dialplan, and for every value of $call to do something, if $call is 1, Dial,..or if is not, hangup...

Cheers
Anya
anya
Newsterisk
 
Posts: 35
Joined: Fri Apr 13, 2012 2:45 am

Re: Asterisk & PHP AGI

Postby dcabot » Thu Apr 26, 2012 2:49 pm

First I'd install this:

http://phpagi.sourceforge.net/

Look for the demos for examples.
dcabot
Newsterisk
 
Posts: 15
Joined: Fri Apr 06, 2007 8:26 pm

Re: Asterisk & PHP AGI

Postby anya » Thu Apr 26, 2012 3:16 pm

Yes, I know how to install everything, and I have it. My problem is syntax and logic how to past variable to Asterisk and to work something with it....
anya
Newsterisk
 
Posts: 35
Joined: Fri Apr 13, 2012 2:45 am

Re: Asterisk & PHP AGI

Postby david55 » Thu Apr 26, 2012 5:31 pm

http://www.asteriskdocs.org/

There are example scripts in the contrib/scripts directory, in the source distribution.
david55
Moves Like Spencer
 
Posts: 7710
Joined: Fri Sep 26, 2008 5:03 am

Re: Asterisk & PHP AGI

Postby navaismo » Thu Apr 26, 2012 5:57 pm

Use: Set_Variable("yourvariable","yourvalue"), then in your dialplan use it calling the name "yourvariable", and thats all.

Code: Select all
$mcount=3;
$agi->Set_Variable("count","${mcount}");


then in the dialplan:

Code: Select all
....
same => n, NoOP( "the result of my count is ${count}")
.....
navaismo
Astmaster
 
Posts: 767
Joined: Mon Dec 07, 2009 1:30 pm
Location: Mexico City, Mexico

Re: Asterisk & PHP AGI

Postby anya » Thu Apr 26, 2012 11:36 pm

Thank you all ! I will test it today, I hope without problems:) Or I will contact you again...thx once more
anya
Newsterisk
 
Posts: 35
Joined: Fri Apr 13, 2012 2:45 am

Re: Asterisk & PHP AGI

Postby anya » Fri Apr 27, 2012 1:03 am

Unfortunately, I have problem.
In php script I set variable

$my = 1;
$agi -> set_variable("myvar","${my}");

Then in dialplan I wrote :

exten => XXX,1,Wait(1)
exten => XXX,2,AGI(script.php)
exten => XXX,n,NoOp("the result is ${myvar}")
exten => XXX,n,GotoIf($["${myvar}" = "1"]?yes:no)
exten => XXX,n(yes),Dial(SIP/XXX)
exten => XXX,n(no),Dial(SIP/XXX)
exten => XXX,n,Hangup()

But I got nothing in variable :(

Executing [...] NoOp("SIP/XXX-....", ""the result is "") in new stack
anya
Newsterisk
 
Posts: 35
Joined: Fri Apr 13, 2012 2:45 am

Re: Asterisk & PHP AGI

Postby david55 » Fri Apr 27, 2012 1:12 am

What is the result of enabling AGI debugging in the Asterisk CLI?
david55
Moves Like Spencer
 
Posts: 7710
Joined: Fri Sep 26, 2008 5:03 am


Return to Asterisk Support

Who is online

Users browsing this forum: No registered users and 25 guests