[asterisk-users] How to pass variable back and forth from dialplan to php file?

Carlos Chavez cursor at telecomabmex.com
Mon Jun 14 17:07:16 CDT 2010


	Go to http://phpagi.sourceforge.net/ and check the documentation.
Basically you can run any command you can run on the CLI or
extensions.conf.  To get the status of a SIP peer I would recommend
using AMI.  PHPAGI also has a library to connect to the AMI and send
commands.

On Mon, 2010-06-14 at 17:38 -0400, bruce bruce wrote:
> Thanks for pointing to the debug. I found that the path to phpagi was
> not right and since I fixed that everything seems to work fine.
> 
> 
> Now, I want to know if I can use a phpagi command to check the status
> of SIP Peer if it is online and registered or not. I know I can use
> grep with asterisk rx "sip show peers" and use that as a shell script
> but I think there are better methods in Asterisk dialplan or in phpagi
> that it can be check.
> 
> 
> Thanks,
> Bruce
> 
> On Mon, Jun 14, 2010 at 5:27 PM, Carlos Chavez
> <cursor at telecomabmex.com> wrote:
>                If you do an "agi set debug on" from the CLI and run
>         your AGI you
>         should see something like this:
>         
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_request: auth.agi
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_channel: SIP/206-00000d9b
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_language: es
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_type: SIP
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_uniqueid: 1276192380.5115
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_version: 1.6.2.8
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_callerid: 206
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_calleridname: Carmen Saavedra
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_callingpres: 0
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_callingani2: 0
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_callington: 0
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_callingtns: 0
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_dnid: *22081019999282711
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_rdnis: unknown
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_context: oficina
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_extension: *22081019999282711
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_priority: 2
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_enhanced: 0.0
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_accountcode:
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_threadid: -1234945136
>         [Jun 10 12:53:00] VERBOSE[8515] res_agi.c:
>         <SIP/206-00000d9b>AGI Tx >>
>         agi_arg_1: ldnac
>         
>                As you can see agi_extension and agi_dnid should
>         contain the number
>         that the user dialed.  Those are all the variables that are
>         automatically sent to the AGI script from Asterisk.  I do not
>         know why
>         you are getting the channel instead of the extension, you
>         could try
>         giving the extension as a parameter to the AGI script if you
>         cannot get
>         that from the included request variable.
>         
>         
>         On Mon, 2010-06-14 at 14:57 -0400, bruce bruce wrote:
>         > Carlos, Thanks a lot for getting me started. That helps a
>         great deal.
>         >
>         >
>         > Currently, the $agi->request['agi_extension'];  returns the
>         SIP
>         > channel info with IP and I want that to be the incoming DID
>         number.
>         >
>         >
>         > My dialplan output is this for line one:
>         >
>         >
>         > exten => _x.,1,NoOp(${EXTEN})
>         >
>         >
>         > 415444555
>         >
>         >
>         > But with the agi_extension it comes back as:
>         > NoOp("SIP/64.111.222.111-00000ca7", "")
>         >
>         >
>         > Where can I find the list of command requests that can be
>         sent to
>         > Asterisk? Specially that for DID.
>         >
>         >
>         > Thanks
>         >
>         >
>         > On Mon, Jun 14, 2010 at 2:15 PM, Carlos Chavez
>         > <cursor at telecomabmex.com> wrote:
>         >         On Mon, 2010-06-14 at 13:41 -0400, bruce bruce
>         wrote:
>         >         > Hi Carlso,
>         >         >
>         >         >
>         >         > Thanks for the input. I have done this in php and
>         am not
>         >         familiar with
>         >         > phpagi.
>         >         > So, there is absolutely no way to temporarily
>         solve this
>         >         problem by
>         >         > getting the value back from php file?
>         >         >
>         >         >
>         >         > Wondering if it would require a lot of work to
>         change the
>         >         php file to
>         >         > phpagi?
>         >         > Thanks,
>         >         > Bruce
>         >         >
>         >
>         >                Here is an example:
>         >
>         >         exten => _x.,1,AGI(sample.agi)
>         >         exten => _x.,n,NoOp(${var})
>         >
>         >
>         >         sample.agi:
>         >
>         >         #!/usr/bin/php -q
>         >         <?php
>         >         set_time_limit(30);
>         >         require('phpagi/phpagi.php');
>         >         $agi = new AGI();
>         >         $exten = $agi->request['agi_extension']; //Dialed
>         extension
>         >         // the result is stored in $exten
>         >         // do something with your data
>         >         $agi->set_variable("var", $result);
>         >         $agi->verbose("The result was: $result", 3);
>         >         ?>
>         >
>         >                You can even send parameters to the AGI via
>         the command
>         >         line like:
>         >
>         >         exten => _x.,1,AGI(sample.agi,param1,param2) //Use
>         comma for
>         >         1.6 or |
>         >         for 1.4 or below
>         >
>         >                And access them via $argv[1], $argv[2] is
>         there is some
>         >         extra
>         >         information that you cannot get via the AGI
>         variables.
>         >
>         >         --
>         >
>         >         Telecomunicaciones Abiertas de México S.A. de C.V.
>         >         Carlos Chávez Prats
>         >         Director de Tecnología
>         >         +52-55-91169161 ext 2001
>         >
>         >
>         >         --
>         >
>         _____________________________________________________________________
>         >         -- Bandwidth and Colocation Provided by
>         >         http://www.api-digital.com --
>         >         New to Asterisk? Join us for a live introductory
>         webinar every
>         >         Thurs:
>         >                       http://www.asterisk.org/hello
>         >
>         >         asterisk-users mailing list
>         >         To UNSUBSCRIBE or update options visit:
>         >
>         http://lists.digium.com/mailman/listinfo/asterisk-users
>         >
>         >
>         
>         > --
>         >
>         _____________________________________________________________________
>         > -- Bandwidth and Colocation Provided by
>         http://www.api-digital.com --
>         > New to Asterisk? Join us for a live introductory webinar
>         every Thurs:
>         >                http://www.asterisk.org/hello
>         >
>         > asterisk-users mailing list
>         > To UNSUBSCRIBE or update options visit:
>         >    http://lists.digium.com/mailman/listinfo/asterisk-users
>         
>         
>         --
>         
>         Telecomunicaciones Abiertas de México S.A. de C.V.
>         Carlos Chávez Prats
>         Director de Tecnología
>         +52-55-91169161 ext 2001
>         
>         
>         --
>         _____________________________________________________________________
>         -- Bandwidth and Colocation Provided by
>         http://www.api-digital.com --
>         New to Asterisk? Join us for a live introductory webinar every
>         Thurs:
>                       http://www.asterisk.org/hello
>         
>         asterisk-users mailing list
>         To UNSUBSCRIBE or update options visit:
>           http://lists.digium.com/mailman/listinfo/asterisk-users
> 
> 
> -- 
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> New to Asterisk? Join us for a live introductory webinar every Thurs:
>                http://www.asterisk.org/hello
> 
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users

-- 
Telecomunicaciones Abiertas de México S.A. de C.V.
Carlos Chávez Prats
Director de Tecnología
+52-55-91169161 ext 2001
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20100614/de45099d/attachment.pgp 


More information about the asterisk-users mailing list