Hi all, I have a dialplan that calls a PHP script through CURL: <extension name="test" continue="false"> <condition field="destination_number" expression="^669$"> <action application="answer"/> <action application="sleep" data="1000"/> <!--<action application="play_and_get_digits" data="4 11 1 5000 # ivr/ivr-please_enter_the_phone_number.wav ivr/ivr-that_was_an_invalid_entry.wav target_num"/>--> <action application="curl" data="http://localhost/provision/index.php?action=test&uuid=${uuid}&exten=${caller_id_number}" /> <action application="sleep" data="1000"/> <action application="log" data="INFO ${curl_response_data}"/> <action application="hangup" data="NORMAL_CLEARING"/> </condition> </extension> (notice the play_and_get_digits is commented out) and in PHP I connect via ESL via this function and code: function saySomething($uuid) { $sock = new ESLconnection('localhost','8021','ClueCon'); sleep (2); $res = $sock->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"); //$foo = $uuid . ' target_num'; sleep (2); $res=$sock->sendRecv("api uuid_getvar $uuid target_num"); $ret = $res->getBody(); $sock->disconnect(); //echo $ret; return ($ret); } if ($action == 'test') { $res = saySomething($_REQUEST['uuid']); echo $res; } However if I run the play_and_get_digits from the PHP the subsequent uuid_getvar returns _undef_. If I comment out the play_and_get_digits in PHP and uncomment it in the dialplan, the uuid_getvar *does* return the digits pressed. Is there something I'm doing wrong here? Thanks Alex -- This message is intended only for the addressee and may contain confidential information. Unless you are that person, you may not disclose its contents or use it in any way and are requested to delete the message along with any attachments and notify us immediately. "Transact" is operated by Integrated Financial Arrangements plc Domain House, 5-7 Singer Street, London EC2A 4BQ Tel: (020) 7608 4900 Fax: (020) 7608 5300 (Registered office: as above; Registered in England and Wales under number: 3727592) Authorised and regulated by the Financial Services Authority (entered on the FSA Register; number: 190856)
ESL execute is async, so you will need to wait for the correct event to be returned, that tells you it's finished. EXECUTE_COMPLETE I think the event is called.. /Peter 29 mar 2012 kl. 16:57 skrev "Alex Crow" <acrow@integrafin.co.uk>:
Hi all,
I have a dialplan that calls a PHP script through CURL:
<extension name="test" continue="false"> <condition field="destination_number" expression="^669$"> <action application="answer"/> <action application="sleep" data="1000"/> <!--<action application="play_and_get_digits" data="4 11 1 5000 # ivr/ivr-please_enter_the_phone_number.wav ivr/ivr-that_was_an_invalid_entry.wav target_num"/>--> <action application="curl" data="http://localhost/provision/index.php?action=test&uuid=${uuid}&exten=${caller_id_number}" /> <action application="sleep" data="1000"/> <action application="log" data="INFO ${curl_response_data}"/> <action application="hangup" data="NORMAL_CLEARING"/> </condition> </extension>
(notice the play_and_get_digits is commented out)
and in PHP I connect via ESL via this function and code:
function saySomething($uuid) {
$sock = new ESLconnection('localhost','8021','ClueCon');
sleep (2);
$res = $sock->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");
//$foo = $uuid . ' target_num';
sleep (2);
$res=$sock->sendRecv("api uuid_getvar $uuid target_num");
$ret = $res->getBody();
$sock->disconnect();
//echo $ret;
return ($ret);
}
if ($action == 'test') { $res = saySomething($_REQUEST['uuid']); echo $res; }
However if I run the play_and_get_digits from the PHP the subsequent uuid_getvar returns _undef_.
If I comment out the play_and_get_digits in PHP and uncomment it in the dialplan, the uuid_getvar *does* return the digits pressed.
Is there something I'm doing wrong here?
Thanks
Alex
-- This message is intended only for the addressee and may contain confidential information. Unless you are that person, you may not disclose its contents or use it in any way and are requested to delete the message along with any attachments and notify us immediately.
"Transact" is operated by Integrated Financial Arrangements plc Domain House, 5-7 Singer Street, London EC2A 4BQ Tel: (020) 7608 4900 Fax: (020) 7608 5300 (Registered office: as above; Registered in England and Wales under number: 3727592) Authorised and regulated by the Financial Services Authority (entered on the FSA Register; number: 190856)
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
!DSPAM:4f7475d932769462314482!
On 29/03/12 16:08, Peter Olsson wrote:
ESL execute is async, so you will need to wait for the correct event to be returned, that tells you it's finished. EXECUTE_COMPLETE I think the event is called..
/Peter
29 mar 2012 kl. 16:57 skrev "Alex Crow"<acrow@integrafin.co.uk>:
Many thanks Peter. If you or anyone else can answer as well - I am also using PHP for directory via xml_curl. I see on the Wiki example for auth requests: [sip_contact_user] => 1004 [sip_contact_host] => 192.168.1.100 I am thinking this might be usable to figure out when a phone registers if it is an "outside" phone (ie checking if it is either on a public IP or presenting a private IP outside of company LAN ranges, and as such should have <variable name="sip-force-contact" value="NDLB-tls-connectile-dysfunction"/> as part of the returned XML to make sure audio gets through for all external clients. Does that sound reasonable? Alex -- This message is intended only for the addressee and may contain confidential information. Unless you are that person, you may not disclose its contents or use it in any way and are requested to delete the message along with any attachments and notify us immediately. "Transact" is operated by Integrated Financial Arrangements plc Domain House, 5-7 Singer Street, London EC2A 4BQ Tel: (020) 7608 4900 Fax: (020) 7608 5300 (Registered office: as above; Registered in England and Wales under number: 3727592) Authorised and regulated by the Financial Services Authority (entered on the FSA Register; number: 190856)
On 29/03/12 16:08, Peter Olsson wrote:
ESL execute is async, so you will need to wait for the correct event to be returned, that tells you it's finished. EXECUTE_COMPLETE I think the event is called..
/Peter
29 mar 2012 kl. 16:57 skrev "Alex Crow"<acrow@integrafin.co.uk>:
Peter, Actually if execute is async the Wiki is wrong: "execute execute($app[, $arg][, $uuid]) Execute a dialplan application, and wait for a response from the server. On socket connections not anchored to a channel (most of the time inbound), all three arguments are required -- $uuid specifies the channel to execute the application on. Returns an ESLevent object containing the response from the server. The getHeader("Reply-Text") method of this ESLevent object returns the server's response. The server's response will contain "+OK [Success Message]" on success or "-ERR [Error Message]" on failure. See the examples below for information on how to get a uuid to use when calling execute(). executeAsync executeAsync($app[, $arg][, $uuid]) Same as execute, but doesn't wait for a response from the server. This works by causing the underlying call to execute() to append "async: true" header in the message sent to the channel. " As you can see there is a specific executeAsync call documented. Are they both actually async? That aside, does this code look OK? $esl = new ESLconnection('localhost','8021','ClueCon'); $event = $esl->events('plain', 'ALL'); $event = $esl->filter("Unique-ID",$uuid); sleep (2); $event = $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"); //$foo = $uuid . ' target_num'; while ($event->getType() != 'CHANNEL_EXECUTE_COMPLETE' ) { $esl->execute("&sleep",100); } $event=$esl->sendRecv("api uuid_getvar $uuid target_num"); Cheers Alex
I believe that it's only sync in outbound mode. Maybe it would be easier to do what you want in outbound mode instead? /Peter ________________________________ Från: freeswitch-users-bounces@lists.freeswitch.org [freeswitch-users-bounces@lists.freeswitch.org] för Alex Crow [acrow@integrafin.co.uk] Skickat: den 1 april 2012 10:40 Till: freeswitch-users@lists.freeswitch.org Ämne: Re: [Freeswitch-users] Dialplan/PHP esl variable problem. On 29/03/12 16:08, Peter Olsson wrote: ESL execute is async, so you will need to wait for the correct event to be returned, that tells you it's finished. EXECUTE_COMPLETE I think the event is called.. /Peter 29 mar 2012 kl. 16:57 skrev "Alex Crow" <acrow@integrafin.co.uk><mailto:acrow@integrafin.co.uk>: Peter, Actually if execute is async the Wiki is wrong: "execute execute($app[, $arg][, $uuid]) Execute a dialplan application, and wait for a response from the server. On socket connections not anchored to a channel (most of the time inbound), all three arguments are required -- $uuid specifies the channel to execute the application on. Returns an ESLevent object containing the response from the server. The getHeader("Reply-Text") method of this ESLevent object returns the server's response. The server's response will contain "+OK [Success Message]" on success or "-ERR [Error Message]" on failure. See the examples below for information on how to get a uuid to use when calling execute(). executeAsync executeAsync($app[, $arg][, $uuid]) Same as execute, but doesn't wait for a response from the server. This works by causing the underlying call to execute() to append "async: true" header in the message sent to the channel. " As you can see there is a specific executeAsync call documented. Are they both actually async? That aside, does this code look OK? $esl = new ESLconnection('localhost','8021','ClueCon'); $event = $esl->events('plain', 'ALL'); $event = $esl->filter("Unique-ID",$uuid); sleep (2); $event = $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"); //$foo = $uuid . ' target_num'; while ($event->getType() != 'CHANNEL_EXECUTE_COMPLETE' ) { $esl->execute("&sleep",100); } $event=$esl->sendRecv("api uuid_getvar $uuid target_num"); Cheers Alex !DSPAM:4f7813f832766290219940!
On 01/04/12 10:33, Peter Olsson wrote:
I believe that it's only sync in outbound mode. Maybe it would be easier to do what you want in outbound mode instead?
/Peter
________________________________ Thanks Peter,
I was thinking about that but since I'm not having much luck listening for events in inbound mode, I think I'd be running before I could walk (ie I'd have to listen for incoming calls rather than just using the dialplan to do that, and I don't want to risk breaking all the other calls on the system). This isn't working for instance (after the execute): while ($event->getType() != 'CHANNEL_EXECUTE_COMPLETE' ) { $esl->execute("&sleep",1000); } It actually seems to stop the call working completely, ie the caller doesn't hear the "enter the phone number". Not sure why, since that's executed before! Cheers Alex
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 ________________________________________ Från: freeswitch-users-bounces@lists.freeswitch.org [freeswitch-users-bounces@lists.freeswitch.org] för Alex Crow [acrow@integrafin.co.uk] Skickat: den 1 april 2012 11:50 Till: FreeSWITCH Users Help Ämne: Re: [Freeswitch-users] Dialplan/PHP esl variable problem. On 01/04/12 10:33, Peter Olsson wrote:
I believe that it's only sync in outbound mode. Maybe it would be easier to do what you want in outbound mode instead?
/Peter
________________________________ Thanks Peter,
I was thinking about that but since I'm not having much luck listening for events in inbound mode, I think I'd be running before I could walk (ie I'd have to listen for incoming calls rather than just using the dialplan to do that, and I don't want to risk breaking all the other calls on the system). This isn't working for instance (after the execute): while ($event->getType() != 'CHANNEL_EXECUTE_COMPLETE' ) { $esl->execute("&sleep",1000); } It actually seems to stop the call working completely, ie the caller doesn't hear the "enter the phone number". Not sure why, since that's executed before! Cheers Alex _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org !DSPAM:4f7824ba32766551348335!
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
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
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. On Fri, Apr 6, 2012 at 12:31 PM, Alex Crow <acrow@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@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ Twitter: http://twitter.com/FreeSWITCH_wire AIM: anthm MSN:anthony_minessale@hotmail.com GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org googletalk:conf+888@conference.freeswitch.org pstn:+19193869900
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.
Anthony, 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, etc) 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. Cheers Alex
On Fri, Apr 6, 2012 at 12:31 PM, Alex Crow<acrow@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@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
Alex, I noticed that you are using the same thing as Michael Lutz from the other thread we just discussed. Could you try recvEventTimed(1) instead of recvEventTimed(0)? I'm curious to see if it changes the behavior of your application at all. -MC On Fri, Apr 6, 2012 at 12:21 PM, Alex Crow <acrow@integrafin.co.uk> wrote:
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.
Anthony,
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, etc)
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.
Cheers
Alex
On Fri, Apr 6, 2012 at 12:31 PM, Alex Crow<acrow@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<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
On 06/04/12 20:34, Michael Collins wrote:
Alex,
I noticed that you are using the same thing as Michael Lutz from the other thread we just discussed. Could you try recvEventTimed(1) instead of recvEventTimed(0)? I'm curious to see if it changes the behavior of your application at all.
-MC
Michael, I've tried 0, 1, 20, 200 and nothing makes a difference. Cheers Alex
Just to confirm... the symptom is that you start a play_and_get_digits action and when you do the recvEventTime() function it stops the playback of the pagd? -MC On Fri, Apr 6, 2012 at 12:51 PM, Alex Crow <acrow@integrafin.co.uk> wrote:
On 06/04/12 20:34, Michael Collins wrote:
Alex,
I noticed that you are using the same thing as Michael Lutz from the other thread we just discussed. Could you try recvEventTimed(1) instead of recvEventTimed(0)? I'm curious to see if it changes the behavior of your application at all.
-MC
Michael,
I've tried 0, 1, 20, 200 and nothing makes a difference.
On 06/04/12 20:55, Michael Collins wrote:
Just to confirm... the symptom is that you start a play_and_get_digits action and when you do the recvEventTime() function it stops the playback of the pagd?
-MC
Yes, In fact you never even hear the beginning of the pagd. You only hear it when the curl request from the dialplan call finally times out in the webserver (in my case nginx, 60 seconds, and FS logs the HTTP timeout the moment you hear the pagd prompt.) Alex
Maybe the dialplan is waiting for curl to return... Can you see that at the logs? Em 06/04/2012 18:21, "Alex Crow" <acrow@integrafin.co.uk> escreveu:
On 06/04/12 20:55, Michael Collins wrote:
Just to confirm... the symptom is that you start a play_and_get_digits action and when you do the recvEventTime() function it stops the playback of the pagd?
-MC
Yes,
In fact you never even hear the beginning of the pagd. You only hear it when the curl request from the dialplan call finally times out in the webserver (in my case nginx, 60 seconds, and FS logs the HTTP timeout the moment you hear the pagd prompt.)
Alex
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
On 07/04/12 10:33, Wesley Akio wrote:
Maybe the dialplan is waiting for curl to return... Can you see that at the logs?
Thanks Wesley, But the curl should return as soon as the event is detected, and surely the queued request for PAGD should proceed regardless of my polling for events after it. I've even tried listening for all events and logging them but I see nothing in the logs and still have to wait for the web server to timeout. The really odd thing is that if I don't do anything else in my PHP after the PAGD ESL call then I hear the message playing, as soon as I try to do anything else (including polling for events) I don't. I am just curious as to a) if I am trying to do something unsupported or b) I have found a bug. Cheers Alex
The script that does the polling is the one called by curl? Remember curl will return only when that script finishes. Em 07/04/2012 17:38, "Alex Crow" <acrow@integrafin.co.uk> escreveu:
On 07/04/12 10:33, Wesley Akio wrote:
Maybe the dialplan is waiting for curl to return... Can you see that at the logs?
Thanks Wesley,
But the curl should return as soon as the event is detected, and surely the queued request for PAGD should proceed regardless of my polling for events after it. I've even tried listening for all events and logging them but I see nothing in the logs and still have to wait for the web server to timeout. The really odd thing is that if I don't do anything else in my PHP after the PAGD ESL call then I hear the message playing, as soon as I try to do anything else (including polling for events) I don't.
I am just curious as to a) if I am trying to do something unsupported or b) I have found a bug.
Cheers
Alex
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
On 09/04/12 01:08, Wesley Akio wrote:
The script that does the polling is the one called by curl? Remember curl will return only when that script finishes.
Wesley, Yes. The script sends an ESL execute for the pagd and tries to poll for a response. Are you saying that I won't hear the PAGD until the script returns, so waiting for a response actually prevents it from playing until the script times out? Cheers Alex
I'll try it today to be certain but yes, I'm assuming your dialplan execution blocks on curl since only one application will be run on the call at a time... One thing you can try is to schedule curl to run on the background and park the call right after, that way you will be certain curl is not the issue since it will be running on another thread... I would try outbound sockets though. They seem more fit to your scenario... Em 09/04/2012 05:22, "Alex Crow" <acrow@integrafin.co.uk> escreveu:
On 09/04/12 01:08, Wesley Akio wrote:
The script that does the polling is the one called by curl? Remember curl will return only when that script finishes.
Wesley,
Yes. The script sends an ESL execute for the pagd and tries to poll for a response. Are you saying that I won't hear the PAGD until the script returns, so waiting for a response actually prevents it from playing until the script times out?
Cheers
Alex
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
On Sat, Apr 7, 2012 at 1:38 PM, Alex Crow <acrow@integrafin.co.uk> wrote:
On 07/04/12 10:33, Wesley Akio wrote:
Maybe the dialplan is waiting for curl to return... Can you see that at the logs?
Thanks Wesley,
But the curl should return as soon as the event is detected, and surely the queued request for PAGD should proceed regardless of my polling for events after it. I've even tried listening for all events and logging them but I see nothing in the logs and still have to wait for the web server to timeout. The really odd thing is that if I don't do anything else in my PHP after the PAGD ESL call then I hear the message playing, as soon as I try to do anything else (including polling for events) I don't.
I am just curious as to a) if I am trying to do something unsupported or b) I have found a bug.
I suspect there are better tools at your disposal for doing what you are trying to do. If I were in your shoes (someone who obviously has Web dev and PHP experience) then I would cut my losses with method and head straight for HTTAPI. My guess is that the initial learning curve will be a bit steep but that once you get over the hump you will be building awesome applications without all the weird issues. -MC
I suspect there are better tools at your disposal for doing what you are trying to do. If I were in your shoes (someone who obviously has Web dev and PHP experience) then I would cut my losses with method and head straight for HTTAPI. My guess is that the initial learning curve will be a bit steep but that once you get over the hump you will be building awesome applications without all the weird issues.
-MC
Thanks Michael, I will have a look at it. It does say on the wiki it needs a cgi, but presumable a PHP page will work just as well? Cheers Alex
participants (5)
-
Alex Crow
-
Anthony Minessale
-
Michael Collins
-
Peter Olsson
-
Wesley Akio