[asterisk-users] Connecting two calls with Originate

Steve Edwards asterisk.org at sedwards.com
Mon Aug 9 18:12:40 CDT 2010


On Mon, 9 Aug 2010, Kathryn Jones wrote:

> I have been working on this for a while today, and still no luck. This is my script:
> 
> #!/usr/bin/php
> <?php
> $errno=0;
> $errstr=0;
> $fp = fsockopen ("localhost",5038,$errno,$errstr,20);
> if (!$fp) {
>         echo "$errstr ($errno)<br>\n";
> } else {
> 
>          fputs($fp, "Action: Login\r\n");
>          fputs($fp, "Username: xxxx\r\n");
>          fputs($fp, "Secret: xxxx\r\n");
>          fputs($fp, "Events: off\r\n");
>         sleep(1);
>          fputs($fp, "Action: Originate\r\n");
>          fputs($fp, "Channel: SIP/trunk/1DIDNumber\r\n");
>          fputs($fp, "Context: CallContext\r\n\r\n");
>          fputs($fp, "Exten: NumberToCall\r\n");
>          fputs($fp, "Priority: 1\r\n");
>          fputs($fp, "Timeout: 30000\r\n");
>         sleep(2);
>         fclose($fp);
> }
> ?>
> 
> It seems simple enough, And I have no compilation errors. This is my output:
> 
>  -- Launched AGI Script /var/lib/asterisk/agi-bin/MyScript.php
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_request: MyScript.php
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_channel: SIP/xx.xx.xxx.xx-00000111
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_language: en
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_type: SIP
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_uniqueid: 1281390000.000
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_version: 1.6.2.6
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_callerid: 1PhoneThatCalled The DID
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_calleridname: unknown
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_callingpres: 0
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_callingani2: 0
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_callington: 0
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_callingtns: 0
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_dnid: IncomingExt
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_rdnis: unknown
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_context: default
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_extension: incomingExt
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_priority: 3
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_enhanced: 0.0
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_accountcode:
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> agi_threadid: -1237000000
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >>
>   == Manager 'Man' logged on from 127.0.0.1
>   == Manager 'Man' logged off from 127.0.0.1
> <SIP/xx.xx.xxx.xx-00000111>AGI Rx <<
> <SIP/xx.xx.xxx.xx-00000111>AGI Tx >> 510 Invalid or unknown command
> [Aug  9 17:44:10] ERROR[25594]: utils.c:1128 ast_carefulwrite: write() returned error: Broken pipe
> [Aug  9 17:44:10] ERROR[25594]: utils.c:1128 ast_carefulwrite: write() returned error: Broken pipe
>     -- <SIP/xx.xx.xxx.xx-00000111>AGI Script MyScript.php completed, returning 0
> 
> Could someone please point me in the right direction?

This is not an AGI, this is an AMI :)

AGI is a protocol where Asterisk creates a process and sends it the "AGI 
environment" (all the "AGI Tx >> agi_xxx" cruft above") and then waits for 
your process to issue requests and read responses. This "request, 
response" is repeated as your process completes it's tasks and exits.

Are you expecting your script to execute within the "context" of a channel 
within Asterisk or as a process external to Asterisk?

I read your original request:

> I want to connect an open call with an extension. I call in with a DID, 
> them redirect to the extension using AGI. Can I use agi's originate to 
> make the second call without dropping the first DID call? How would I go 
> about this?

as "I call in, I execute an AGI that looks up an extension based on some 
criteria, I want to dial that extension."

If this is close, the AGI should set a channel variable with the value of 
the extension and exit. Your dialplan would look something like:

 	exten = my-did,1,		verbose(${EXTEN}@${CONTEXT})
 	exten = my-did,n,		agi(lookup-extension)
 	exten = my-did,n,		dial{${LOOKED-UP-EXTENSION})
 	exten = my-did,n,		hangup()

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000


More information about the asterisk-users mailing list