[asterisk-users] Connecting two calls with Originate

Elliot Otchet elliot.otchet at callingcircles.com
Mon Aug 9 18:54:37 CDT 2010

-----Original Message-----
From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Steve Edwards
Sent: Monday, August 09, 2010 7:13 PM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Connecting two calls with Originate

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:
> <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
>   == Manager 'Man' logged off from
> <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()

If you are doing what Steve has described, and you require php, you should really check out PHPAGI (http://phpagi.sourceforge.net/).  It's a great framework for using both AGI and the AMI in PHP.  If you need just the AGI component and are going to be doing this on a large scale, google cagi (http://sourceforge.net/projects/cagi/).  It is structured similarly to PHPAGI.

Elliot Otchet
Calling Circles LLC

This message is intended only for the use of the individual (s) or entity to which it is addressed and may contain information that is privileged, confidential, and/or proprietary to Calling Circles LLC and its affiliates. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, forwarding or copying of this communication is prohibited without the express permission of the sender. If you have received this communication in error, please notify the sender immediately and delete the original message.

More information about the asterisk-users mailing list