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

Alex Crow acrow at integrafin.co.uk
Fri Apr 6 21:31:13 MSD 2012


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




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