PHPAGI AMI originate EXAMPLE -Desprate call for help

Hi Guys,

I have been trying to get phpagi to do originate and I fail over and over. I have been able to use Action: Command and send command originate which is the CLI originate and that works. But the AMI Originate doesn’t work. Can anyone please guide me to an example of Originate somewhere? I am trying to have my php file (from the browser) to take variables $x, $y, and $z through a form and then process the call as follows:

[testphp]
exten => _X.,1,Answer()
exten => _X.,n,Dial(SIP/testTrunk/$y)
exten => _X.,n,Hangup()

Please guide me what the Originate part should look like in the php file and what file should go where as for as phpagi files go. I need some detailed documentation on how to use phpagi which unfortunately is missing on phpagi site.
I really appreciate any help on this.

Anyone? It amazes me how less the phpagi AMI code is shared with the community :frowning:

I’m sorry I don’t have any sample about, try post your php script, try a call and post the Asterisk CLI output (set the verbose to a high level and activate agi debug), I’ll try help you debug it.

Cheers.

Marco Bruni
www.marcobruni.net

Hi let me get this right, you are creating a form on a webpage that users enter 3 variables,

and then on submit you want it to make the call is that correct ?

This is an article I cowrote some years back voipuser.org/forum_topic_9971.html have a read as it does cover using php to orignate calls.

I have since updated the code and nows its realy an IP where you just send key variables to it and it originates a call based on them.

Ian
www.cyber-cottage.co.uk

Sorry,
I didn’t read well enough, I thought about an php AGI script not a web page.

Ian is right as ever :smile:

Cheers.

Marco Bruni
www.marcobruni.net

I wish some one would tell my Children that :laughing:

Thanks for the input guys.

I was actually looking for the easy way out and used floAPI and phpagi-asmanager which does the dirty work behind the scene but I failed with them and spent way too much time on it looking for an easy way.

I will look at Ian’s and try to learn that method. Seems like that is exactly what I want. I will post back if I need any help.

Happy holidays!

So, I am facing problems and coming back now :smile:

First, allow me to clear the air for myself. From what I understand Ian doesn’t use any third party AMI handler and he simply relies on php for a opening socket to AMI and passing commands?! I followed his php example and I can’t even establish a connection. Asterisk CLI doesn’t show manager “test” logged from 127.0.0.1 when I submit the form. Below is my complete code and the context.

/etc/asterisk/extensions_custom.conf

[testphp] exten => _X.,1,Answer() exten => _X.,n,Dial(SIP/testTrunk/${EXTEN}) exten => _X.,n,Hangup()

/var/www/html/clickncall/index.php

[code]

ClicknCall

<?php $sys_ip = "127.0.0.1"; $User_str = "testphp"; $Secret_str = "testphp"; if ($_POST['x']) { $oSocket = fsockopen($sys_ip, 5038, $errnum, $errdesc) or die("Connection to host failed"); fputs($oSocket, "Action: login\r\n"); fputs($oSocket, "Username: $User_str\r\n"); fputs($oSocket, "Secret: $Secret_str\r\n\r\n"); fputs($oSocket, "Events: off\r\n\r\n"); fputs($oSocket, "Action: originate\r\n"); fputs($oSocket, "Channel: SIP/testTrunk/$phoneNumb\r\n"); fputs($oSocket, "Exten: $dialNumb\r\n"); fputs($oSocket, "Context: testphp\r\n"); fputs($oSocket, "Priority: 1\r\n\r\n"); fputs($oSocket, "Timeout: 10000\r\n"); fputs($oSocket, "CallerId: $spoofNumb\r\n"); fputs($oSocket, "Async: true\r\n"); fputs($oSocket, "Action: Logoff\r\n\r\n"); fclose($oSocket); print $_POST['x']; } else { print ""; print "
"; print "PHONE Number: "; print "
"; print "PARTY Number: "; print "
"; print "FORGE Number: "; print "
"; print ""; print ""; } ?>
[/code]

Any input on this will be much appreciated.

Hi

Im sure its a typo but you talk about the user test but you script mentions testphp

you need to add some echo lines in teh php to check the varibles.

This code does work and isin use on a daily basis by customers and crm applications.

PM me if you need more help.

Ian

Thanks for the input. I found out that with Asterisk 1.6 I have to add originate to write list in manager.conf :smile: . So, I add that. However now, if I do this:

$oSocket = fsockopen($sys_ip, 5038, $errnum, $errdesc) or die(“Connection to host failed”);
if ($_POST[‘x’]) {

I see an attempt to connect, but I don’t see it if I do this:

if ($_POST[‘x’]) {
$oSocket = fsockopen($sys_ip, 5038, $errnum, $errdesc) or die(“Connection to host failed”);

By the way what is errnum and errdesc? and the or die ("Connection… part? are these set variables and optinos for $sockopen?

I am wondering if anyone can test this on their machine. Would be much appreciated. keeps me itching my head 100 times a day :angry:

Can you telnet to the manager port and loging and manually make a call ?

Ian

Yes, I did telnet and it works fine after I added originate to write access in manager.conf.

It’s probably just the way I did this form in the php file. I may have to turn on debug and logging for php.

Here is what I have from my Asterisk CLI:

[quote]Action: Originate
Synopsis: Originate Call
Privilege: originate,all
Description: Generates an outgoing call to a Extension/Context/Priority or
Application/Data
Variables: (Names marked with * are required)
*Channel: Channel name to call
Exten: Extension to use (requires ‘Context’ and ‘Priority’)
Context: Context to use (requires ‘Exten’ and ‘Priority’)
Priority: Priority to use (requires ‘Exten’ and ‘Context’)
Application: Application to use
Data: Data to use (requires ‘Application’)
Timeout: How long to wait for call to be answered (in ms)
CallerID: Caller ID to be set on the outgoing channel
Variable: Channel variable to set, multiple Variable: headers are allowed
Account: Account code
Async: Set to ‘true’ for fast origination
[/quote]

However, when I set CallerID through Telnet it simply doesn’t pass through. Also, using Channel: SIP/testTrunk/14164445555 and then my context: testphp, exte: 14164446666 doesn’t wait for one channel to dial first. I know that it’s not a local extension but but channel should be dialed first, picked up and then go to context. Why does it ring both at the same time? This is SIP and rich of info in terms of answered or not.

Thanks for the input.