[Freeswitch-users] Dialplan/PHP esl variable problem.

Alex Crow acrow at integrafin.co.uk
Fri Apr 6 23:21:44 MSD 2012

On 06/04/12 19:19, Anthony Minessale wrote:
> I think you might be twisted around its possible that doing what you
> are doing is much more complicated than just using the socket app.
> If you are just trying to play a file and get a digits etc you could
> do it all with existing dialplan apps.


Thanks very much for replying: what I wanted it it to do is things like 
ask a user if he'd like to set a pin for hotdesking (stored in a 
database, initially sqlite and later mysql or postgres), to check that 
pin when doing a login that logs out his existing extensions (if they 
exist), and various other features later  such as creating their own 
conferences with a pin of their choosing.

I thought the easiest way for the first task (and possibly others) would 
just be to set an extension in the dialplan to call a PHP page on a 
webserver via a curl action, passing some session variables, which would 
then take over the control of the call. I've already have written all 
the stuff for logging in/out and automatically rebooting/provisioning 
both Polycom and Snom phones but have been asked to add some security so 
someone can't just move someone else's registration to another device.

If you think that approach is wrong/doomed to failure and explain what 
the socket app is (is that the thing where you attach a call from the 
dialplan to a TCP socket? Then I've have to learn about setting up a 
listening app in PHP (or any other language), rather than via the 
webserver, wouldn't I, and then try and figure our how to filter our all 
the events from all the other calls, know which event I want, act on it, 

I just think that what I'm doing should be theoretically possible (if 
not the most elegant way) and just can't figure out why if I leave out 
the whole polling for events bit then the message is played, but as soon 
as I try to capture events *after* I've sent the execute call I never 
hear the message.

Just completely confused and am loathe to have to rewrite my hotdesking 
stuff which so far is really simple, I've attached the whole PHP app 
code here so you can see what I've done (it's only the "action=test" 
calling "saySomething" that I have been asking about.

Ideally I'd like to become at least adept if not expert in FS within a 
year as that would be the time we would think about replacing our 
existing phone system.



> On Fri, Apr 6, 2012 at 12:31 PM, Alex Crow<acrow at integrafin.co.uk>  wrote:
>> On 01/04/12 17:29, Alex Crow wrote:
>>> On 01/04/12 11:26, Peter Olsson wrote:
>>>> In your sample you're actually queuing "sleep(1000)" to the channel.
>>>> So first it will queue play_and_get_digits, inside that loop it will
>>>> find more commands in the queue, and exeute them, so in the end it
>>>> will only execute a bunch of "sleep(1000)".
>>>> You're better of using a sleep in your module directly (not tell FS
>>>> to sleep). Also you will need to poll the events in the loop
>>>> somehow., checkout the perl sample here:
>>>> http://wiki.freeswitch.org/wiki/Esl#Simple_Perl_Example
>>> Peter,
>>> I've changed to the below (adapted that Perl example) and I only hear
>>> the prompt for digits when the webserver times out after 60 seconds.
>>> Any time I make any call to ESL after the execute, I don't hear the
>>> prompt in a timely fashion. This is so complicated as I'm not really
>>> that good at software development, I'm more a systems/networks guy. I
>>> feel like a total thickie here, but the docs don't seem to explain in
>>> which order I should call things and expect to get replies, etc.
>>> $esl = new ESLconnection('localhost','8021','ClueCon');
>>> $event = $esl->events('plain', 'ALL');
>>> //$event = $esl->filter("Unique-ID",$uuid);
>>> sleep (1);
>>> $res = $esl->execute("play_and_get_digits","4 11 1 5000 #
>>> ivr/ivr-please_enter_the_phone_number.wav
>>> ivr/ivr-that_was_an_invalid_entry.wav target_num \d+", "$uuid");
>>> $job_uuid = $res->getHeader("Job-UUID");
>>> $status = $res->getHeader("Reply-Text");
>>> //$foo = $uuid . ' target_num';
>>> echo $status;
>>> $stay_connected = 1;
>>> while ( $stay_connected ) {
>>>      $e = $esl->recvEventTimed(0);
>>>      if ( $e ) {
>>>          $ev_name = $e->getHeader("Event-Name");
>>>          # Should we check for the $job_uuid to match the background job ?
>>>          //if ( $ev_name == 'BACKGROUND_JOB' ) {
>>>          //    if ( $e->getHeader("Job-UUID") == $uuid ) {
>>>          //        $call_result = $e->getBody();
>>>          //        echo "Result of call to $target was $call_result\n\n";
>>>          //    }
>>>          //} else
>>>          echo $ev_name;
>>>          if ( $ev_name == 'EXECUTE_COMPLETE' ) {
>>>              //my $digit = $e->getHeader("DTMF-Digit");
>>>             // print "Received DTMF digit: $digit\n";
>>>              //if ( $digit =~ m/\D/ ) {a
>>>               //   print "Exiting...\n";
>>>                  //if ( $e->getHeader("Job-UUID") == $job_uuid ) {
>>>                  $stay_connected = 0;
>>>                  //}
>>>              //}
>>>          } else {
>>>        # Some other event
>>>          }
>>>      } else {
>>>      # do other things while waiting for events
>>>          //sleep (1);
>>>      }
>>> }
>>> $event=$esl->sendRecv("api uuid_getvar $uuid target_num");
>>> $ret = $event->getBody();
>>> $esl->disconnect();
>>> Apologies for my newbishness and many thanks for your help so far.
>>> Hoping for an epiphany when I sudddenly understand what I am doing!
>>> Alex
>> Can anyone help with this? I updated to latest Git, thinking it may have
>> been a bug, and still have the same problem, when I try to wait for
>> events as in the above code, it stops the playback of the "enter the
>> phone number" from happening until after the web server times out.
>> Logically I can't see a reason for this, is it because you can't use an
>> inbound connection activated by calling from curl in the dialplan? If
>> this is indeed the case I could try rewriting this for outbound but I
>> feel that will be more complex for a relative beginner programmer.
>> If I have missed some vital or obvious concept feel free to chastise me :-).
>> Thanks
>> Alex
>> _________________________________________________________________________
>> 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 --------------
A non-text attachment was scrubbed...
Name: index.php
Type: application/x-php
Size: 13782 bytes
Desc: not available
Url : http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120406/04eaaaab/attachment-0001.bin 

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