VoIP Mailing List Archives
Mailing list archives for the VoIP community |
|
View previous topic :: View next topic |
Author |
Message |
gregt at cgicommunicat... Guest
|
Posted: Tue Aug 04, 2009 2:21 pm Post subject: [Freeswitch-users] Outbound socket PHP question |
|
|
Hi, does anyone have an example of a simple PHP socket script that will listen and spawn of a process that handles the incoming call?
I understand the inbound socket and code such as this
http://wiki.freeswitch.org/wiki/PHP_Event_Socket
that will let me initiate operations. It's the constantly running php socket program that I can't get my head around, and how it will spawn another php script that will be able to do things like answer the session, get dtmf, etc.
--
Greg
On Aug 2, 2009, at 6:35 PM, Michael Collins wrote:
Quote: |
On Sun, Aug 2, 2009 at 12:38 PM, Nik Middleton <nik.middleton@noblesolutions.co.uk (nik.middleton@noblesolutions.co.uk)> wrote:
Quote: |
Hi Guys,
I’m using an outbound socket to control calls, and it works a charm. However, what I’d like to do is send a custom event regarding the call on hang-up. The way I see things happening at the moment, and I could be wrong, is that the socket is closed when a hang-up occurs, so am I taking a chance trying to send the event then? (try to sneak out the event before socket closure happens) The other option is of course to open an inbound socket and send the event, but I’d rather not do that if possible.
| Nik,
Perhaps the "linger" event socket command will do what you need? Check out this commit:
http://lists.freeswitch.org/pipermail/freeswitch-svn/2009-January/009391.html
Let me know if it works for you and I'll be sure to get it documented properly. If you get it working I'd love to see a code snippet so we can wikify this knowledge.
Thanks,
MC
_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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
|
|
|
Back to top |
|
|
william.suffill at gma... Guest
|
Posted: Tue Aug 04, 2009 6:12 pm Post subject: [Freeswitch-users] Outbound socket PHP question |
|
|
I wrote some notes on this but have yet to wiki it.
example of an outbound socket connection where the call is answered, a
variable is set then perhaps play one of the pre-installed files and
hangup.
ivrd
fs_ivrd comes with freeswitch. It being a small daemon just invokes
the script defined in a variable and passes data from it via STDIN/OUT
Since this is an outbound socket connections it needs to be defined in
the dialplan.
Ex:
<extension name="outbound-socket">
<condition field="destination_number" expression="^55(522)$">
<action application="set"
data="ivr_path=/usr/local/freeswitch/scripts/ivrd-demo.php"/>
<action application="socket" data="127.0.0.1:8084 async full"/>
</condition>
</extension>
The above dialplan sample would invoke ivr-demo.php when 55522 is
called as long as fs_ivrd is running. To start fs_ivrd:
/usr/local/freeswitch/bin/fs_ivrd -h 127.0.0.1 -p 8004
It takes 2 arguments -h for hostname and -p for port.
PHP Code
#!/usr/bin/php -q
<?php
// set a couple of things so we dont kill the system
ob_implicit_flush(true);
set_time_limit(30);
// Open stdin so we can read the AGI data in
$in = fopen("php://stdin", "r");
// Connect
echo "connect\n\n";
// Answer
echo "sendmsg\n";
echo "call-command: execute\n";
echo "execute-app-name: answer\n\n";
// Play a prompt
echo "sendmsg\n";
echo "call-command: execute\n";
echo "execute-app-name: playback\n";
echo "execute-app-arg:
/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-welcome_to_freeswitch.wav\n\n";
// Wait
sleep(5);
// Hangup
echo "sendmsg\n";
echo "call-command: hangup\n\n";
fclose($in);
?>
ivrd will call this script for each call. All itdoes is answer the
channel tell FreeSWITCH to play the “welcome to freeswitch” prompt.
Since the script is now controlling all call flow I needed to add a
wait or it would send the hangup immediately before the prompt was
played.
Some improvements possible but that's 1 way to do it. It would be
possible to do the socket directly in PHP but fs_ivrd is a nice option
too.
-- W
_______________________________________________
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 |
|
Back to top |
|
|
gregt at cgicommunicat... Guest
|
Posted: Wed Aug 05, 2009 8:10 am Post subject: [Freeswitch-users] Outbound socket PHP question |
|
|
Thanks so much, William. This gives me a great start.
--
Greg
On Aug 4, 2009, at 7:04 PM, William Suffill wrote:
Quote: | I wrote some notes on this but have yet to wiki it.
example of an outbound socket connection where the call is answered, a
variable is set then perhaps play one of the pre-installed files and
hangup.
ivrd
fs_ivrd comes with freeswitch. It being a small daemon just invokes
the script defined in a variable and passes data from it via STDIN/OUT
Since this is an outbound socket connections it needs to be defined in
the dialplan.
Ex:
<extension name="outbound-socket">
<condition field="destination_number" expression="^55(522)$">
<action application="set"
data="ivr_path=/usr/local/freeswitch/scripts/ivrd-demo.php"/>
<action application="socket" data="127.0.0.1:8084 async full"/>
</condition>
</extension>
The above dialplan sample would invoke ivr-demo.php when 55522 is
called as long as fs_ivrd is running. To start fs_ivrd:
/usr/local/freeswitch/bin/fs_ivrd -h 127.0.0.1 -p 8004
It takes 2 arguments -h for hostname and -p for port.
PHP Code
#!/usr/bin/php -q
<?php
// set a couple of things so we dont kill the system
ob_implicit_flush(true);
set_time_limit(30);
// Open stdin so we can read the AGI data in
$in = fopen("php://stdin", "r");
// Connect
echo "connect\n\n";
// Answer
echo "sendmsg\n";
echo "call-command: execute\n";
echo "execute-app-name: answer\n\n";
// Play a prompt
echo "sendmsg\n";
echo "call-command: execute\n";
echo "execute-app-name: playback\n";
echo "execute-app-arg:
/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-welcome_to_freeswitch.wav\n\n";
// Wait
sleep(5);
// Hangup
echo "sendmsg\n";
echo "call-command: hangup\n\n";
fclose($in);
?>
ivrd will call this script for each call. All itdoes is answer the
channel tell FreeSWITCH to play the “welcome to freeswitch” prompt.
Since the script is now controlling all call flow I needed to add a
wait or it would send the hangup immediately before the prompt was
played.
Some improvements possible but that's 1 way to do it. It would be
possible to do the socket directly in PHP but fs_ivrd is a nice option
too.
-- W
_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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
|
|
|
Back to top |
|
|
mike at jerris.com Guest
|
Posted: Sat Aug 08, 2009 12:53 am Post subject: [Freeswitch-users] Outbound socket PHP question |
|
|
there is some other info on http://wiki.freeswitch.org/wiki/Perl_esl
about this as well. could somone try to put together some decent docs
on fs_ivrd on the wiki as I keep getting asked this stuff privately as
well.
Mike
On Aug 4, 2009, at 7:04 PM, William Suffill wrote:
Quote: | I wrote some notes on this but have yet to wiki it.
example of an outbound socket connection where the call is answered, a
variable is set then perhaps play one of the pre-installed files and
hangup.
ivrd
fs_ivrd comes with freeswitch. It being a small daemon just invokes
the script defined in a variable and passes data from it via STDIN/OUT
Since this is an outbound socket connections it needs to be defined in
the dialplan.
Ex:
<extension name="outbound-socket">
<condition field="destination_number" expression="^55(522)$">
<action application="set"
data="ivr_path=/usr/local/freeswitch/scripts/ivrd-demo.php"/>
<action application="socket" data="127.0.0.1:8084 async full"/>
</condition>
</extension>
The above dialplan sample would invoke ivr-demo.php when 55522 is
called as long as fs_ivrd is running. To start fs_ivrd:
/usr/local/freeswitch/bin/fs_ivrd -h 127.0.0.1 -p 8004
It takes 2 arguments -h for hostname and -p for port.
PHP Code
#!/usr/bin/php -q
<?php
// set a couple of things so we dont kill the system
ob_implicit_flush(true);
set_time_limit(30);
// Open stdin so we can read the AGI data in
$in = fopen("php://stdin", "r");
// Connect
echo "connect\n\n";
// Answer
echo "sendmsg\n";
echo "call-command: execute\n";
echo "execute-app-name: answer\n\n";
// Play a prompt
echo "sendmsg\n";
echo "call-command: execute\n";
echo "execute-app-name: playback\n";
echo "execute-app-arg:
/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-
welcome_to_freeswitch.wav\n\n";
// Wait
sleep(5);
// Hangup
echo "sendmsg\n";
echo "call-command: hangup\n\n";
fclose($in);
?>
ivrd will call this script for each call. All itdoes is answer the
channel tell FreeSWITCH to play the “welcome to freeswitch” prompt.
Since the script is now controlling all call flow I needed to add a
wait or it would send the hangup immediately before the prompt was
played.
Some improvements possible but that's 1 way to do it. It would be
possible to do the socket directly in PHP but fs_ivrd is a nice option
too.
-- W
_______________________________________________
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
|
_______________________________________________
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 |
|
Back to top |
|
|
william.suffill at gma... Guest
|
|
Back to top |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|