PHPAGI AMI originate EXAMPLE -Desprate call for help

Get help with installing, upgrading and running Asterisk.

Moderators: muppetmaster, Moderator, Support

PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby torontob » Tue Dec 15, 2009 11:41 pm

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:

Code: Select all
Dial $x with Originate > Channel > SIP/testTrunk/$x and send call to Context: [testphp] and Exten: $y where the context [testphp] like the following (using CallerID: $z) :


[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.
torontob
Newsterisk
 
Posts: 13
Joined: Sun Dec 06, 2009 7:06 pm

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby torontob » Wed Dec 16, 2009 6:01 pm

Anyone? It amazes me how less the phpagi AMI code is shared with the community :(
torontob
Newsterisk
 
Posts: 13
Joined: Sun Dec 06, 2009 7:06 pm

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby mbruni » Thu Dec 17, 2009 2:56 am

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
mbruni
Astmaster
 
Posts: 957
Joined: Thu Dec 21, 2006 10:56 pm
Location: Arezzo, Italy

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby ianplain » Thu Dec 17, 2009 6:58 am

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 http://www.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
ianplain
Moves Like Spencer
 
Posts: 3076
Joined: Thu Dec 14, 2006 7:01 am
Location: Bath, UK

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby mbruni » Thu Dec 17, 2009 7:22 am

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

Ian is right as ever :)

Cheers.

Marco Bruni
www.marcobruni.net
mbruni
Astmaster
 
Posts: 957
Joined: Thu Dec 21, 2006 10:56 pm
Location: Arezzo, Italy

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby ianplain » Thu Dec 17, 2009 7:44 am

Ian is right as ever :)


I wish some one would tell my Children that :lol:
ianplain
Moves Like Spencer
 
Posts: 3076
Joined: Thu Dec 14, 2006 7:01 am
Location: Bath, UK

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby torontob » Thu Dec 17, 2009 12:31 pm

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!
torontob
Newsterisk
 
Posts: 13
Joined: Sun Dec 06, 2009 7:06 pm

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby torontob » Thu Dec 17, 2009 6:47 pm

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

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
Code: Select all
[testphp]
exten => _X.,1,Answer()
exten => _X.,n,Dial(SIP/testTrunk/${EXTEN})
exten => _X.,n,Hangup()



/var/www/html/clickncall/index.php
Code: Select all
<html>
<head>
<title>ClicknCall</title>
</head>
<body><br><br>
<div align="center">

<?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 "<form method=\"post\"action=\"$_SERVER[PHP_SELF]\">";
  print "<br>";
  print "PHONE Number: <input type=\"text\"name=\"phoneNumb\">";
  print "<br>";
  print "PARTY Number: <input type=\"text\"name=\"dialNumb\">";
  print "<br>";
  print "FORGE Number: <input type=\"text\"name=\"spoofNumb\">";
  print "<br>";
  print "<input type=\"Submit\" value=\"                         Dial                             \">";
  print "</form>";

} ?>

</div>
</body>
</html>


Any input on this will be much appreciated.
torontob
Newsterisk
 
Posts: 13
Joined: Sun Dec 06, 2009 7:06 pm

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby ianplain » Fri Dec 18, 2009 4:34 am

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
ianplain
Moves Like Spencer
 
Posts: 3076
Joined: Thu Dec 14, 2006 7:01 am
Location: Bath, UK

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby torontob » Fri Dec 18, 2009 10:20 am

Thanks for the input. I found out that with Asterisk 1.6 I have to add originate to write list in manager.conf :) . 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 :x
torontob
Newsterisk
 
Posts: 13
Joined: Sun Dec 06, 2009 7:06 pm

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby ianplain » Fri Dec 18, 2009 11:26 am

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

Ian
ianplain
Moves Like Spencer
 
Posts: 3076
Joined: Thu Dec 14, 2006 7:01 am
Location: Bath, UK

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby torontob » Fri Dec 18, 2009 11:50 am

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.
torontob
Newsterisk
 
Posts: 13
Joined: Sun Dec 06, 2009 7:06 pm

Re: PHPAGI AMI originate EXAMPLE -Desprate call for help

Postby torontob » Fri Dec 18, 2009 9:00 pm

Here is what I have from my Asterisk CLI:

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


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.
torontob
Newsterisk
 
Posts: 13
Joined: Sun Dec 06, 2009 7:06 pm


Return to Asterisk Support

Who is online

Users browsing this forum: romeneses and 47 guests