[Freeswitch-users] Use of ESL and PHP for Call

Michael Collins msc at freeswitch.org
Sat Mar 3 02:49:10 MSK 2012


Shahzad,

I think you may have taken an unnecessarily complicated approach to this.
If I were you I would simply use the play_and_get_digits application which
does all the work for you. I would also handle that in the XML dialplan and
then use the api_hangup_hook to call your script to process the result.
(I.e. did the user press 1 or 2 or something else...)

I recommend you start with something simple like a basic originate command
that calls the user and then drops that call to a dialplan extension:

originate user/1500 meeting_request_1500

Then create that extension:

<extension name="meeting request">
  <condition field="destination_number" expression="^meeting_request_(
\d+)$">
    <action application="set" data="target_user=$1"/>
    <action application="set" data="text=cepstral|callie|Hi, we have a
meeting on Monday at 9, are you joining us, if yes then press, 1. and if
not press, 2."/>
    <action application="answer"/>
    <action application="sleep" data="1000"/>
    <action application="play_and_get_digits"
      data="1 1 3 5000 # speak:${text}
ivr/ivr-that_was_an_invalid_entry.wav answer \d"/>
    <action application="set" data="api_hangup_hook=system handler.php
${target_user} ${answer}"/>
    <action application="log" data="INFO User ${target_user} responded with
${answer}"/>
    <action application="playback" data="ivr/ivr-Thank_you.wav"/>
    <action application="hangup"/>
  </condition>
</extension>

Then you just need to write your handler.php script (or whatever you want
to call it) and have it parse the command line args - the first one is the
user and the second one is the digit pressed. PHP scripts will work for
hangup hooks but they aren't the best choice since there isn't a "mod_php"
like there is a mod_lua or mod_perl. Those modules let you do cool things
like "session_in_hangup_hook." However, what you're doing doesn't look like
it's very difficult so the example I've given should get you going. Please
note that I just did this off the top of my head w/o testing it so be sure
double-check everything if you run into any unusual or unexpected behavior.

Keep in mind that in this example you will need two different PHP scripts -
one that actually initiates the ESL connection and does the originate and
one that handles the call results. Instead of one semi-complicated script
you will have two very easy scripts.

Hope this helps...
-MC

On Fri, Mar 2, 2012 at 4:14 AM, Shahzad Bhatti <shahzad.bhatti at g-r-v.com>wrote:

>
> Hi,
>
> i park the call and then execute the speak command as but execute is not
> working any idea ?
>
>  $cmd  = "api originate {origination_uuid=$uuid}user/$user &park()";
>  $text = "Hi, we have a meeting on Monday at 9, are you joining us, if yes
> then press, 1. and if not press, 2.";
>
>  $e = $esl->sendRecv($cmd);
>  $esl->execute('speak',"(cepstral|callie|$text)",$uuid);
>
>
>
> my complete code is
>
> <?php
>
>  require_once('ESL.php');
>
>  $host_name      =       'localhost';
>  $port           =       '8021';
>  $password       =       'ClueCon';
>
>  $esl           =       new ESLconnection($host_name,$port,$password);
>
>  $e = $esl->sendRecv("api create_uuid");
>  $uuid = $e->getBody();
>  $user = '1500';
>
>  $cmd  = "bgapi originate {origination_uuid=$uuid}user/$user &park()";
>  $text = "Hi, we have a meeting on Monday at 9, are you joining us, if yes
> then press, 1. and if not press, 2.";
>
>  $e = $esl->sendRecv($cmd);
>  $esl->execute('speak',"(cepstral|callie|$text)",$uuid);
>
>
>  $e = $esl->sendRecv("events plain all");
>  $e = $esl->filter("Unique-ID",$uuid);
>
>  while ($esl->connected())
>  {
>    $e = $esl->recvEvent();
>    $result = $e->getType();
>        if($result=='CHANNEL_EXECUTE_COMPLETE')
>        {
>                        //      what i do here...!
>                $esl->execute("&sleep",10000);
>        }
>        $digit          = $e->getHeader("DTMF-Digit");
>        $state_no       = $e->getHeader("Channel-State-Number");
>        $curr_uuid      = $e->getHeader("Channel-Call-UUID");
>
>  /*
>        $ans_state      = $e->getHeader("Answer-State");
>        $state_no       = $e->getHeader("Channel-State-Number");
>        $core_id        = $e->getHeader("Core-UUID");
> */
>        if($curr_uuid==$uuid && $digit!=NULL)
>        {
>                print "input number is " . $digit . "\n";
>        }
>    $state = $e->getHeader("Channel-Call-State");
>    if ($state == 'HANGUP') {
>        print "\n\nHangup Cause Number: " . $state_no;
>        $esl->disconnect();
>    }
>  }
>
> ?>
>
>
> Regards
>
> Shahzad Bhatti
>
>
> ---------- Forwarded message ----------
> From: Peter Olsson <peter.olsson at visionutveckling.se>
> To: FreeSWITCH Users Help <freeswitch-users at lists.freeswitch.org>
> Cc:
> Date: Fri, 2 Mar 2012 05:31:35 +0000
> Subject: Re: [Freeswitch-users] Use of ESL and PHP for Call
> You should pass the originate command to &park() instead.
>
> Right now you originate the call and then execute the application speak.
> After this (when speak is finished) FS has no more instructions so it will
> hangup the call.
>
> If you execute &park() instead, the call will be "parked" and wait for
> furter instructions. Then you will also need to execute the speak from ESL
> instead - and afther that you continue to do whatever you want to do with
> the call.
>
> /Peter
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> 
> 
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120302/85af9003/attachment.html 


Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list