Discussion:
[Freeswitch-users] Lua outbound executing another lua script
Alpha Niner
2012-07-19 13:18:10 UTC
Permalink
Hi,

Firstly apologies for the newbie question. I've tried searching the various documentation and trying a few different things but to no avail, so I've come here to ask for help. I think my problem relates to sessions, but I'm not totally sure.

What I'm trying to do is:

1. A lua script is run by someone calling into FS (the initiator)
2. They select an option, which originates and makes an outbound call to another phone number
3. The 3rd party (hopefully) answers their phone and receives a prompt that they're going to be connected (the receiver)
4. Both parties join a conference and talk to each other (a conference as there may be other parties in future)

To do this I'm creating a session and using execute_on_answer to run the second script and provide the prompt to the receiving party. However the receiving party never hears a prompt, comes into the conference, immediately drops out and hangs up.

Here are the scripts, they're pretty simple;

The initiator:

session:answer()
session:streamFile("WaitForOutdial.wav")
new_session = freeswitch.Session("[execute_on_answer=lua /usr/local/freeswitch/scripts/receivewithwhisper.lua]sofia/external/12345 at mydest");
session:execute("conference", "CONFTEST at defau?lt+flags{endconf, moderator}")
session:hangup();

The above works fine and the outbound call is placed. The script below is then executed but the receiving phone rings but nothing is heard, the conference is joined/exited and it terminates again;


The receiver (receivewithwhisper.lua):

session:answer()
session:streamFile("ConnectingToCaller.wav")
session:execute("conference", "CONFTEST at default+flags{endconf, moderator}")
session:hangup();

The receiving scripts runs when the receiver answers their phone, and executes (quickly) and terminates. I was expecting it to drop into the conference and I'd be able to talk to the other person. It does join the conference, but then exits right away and falls through to the hangup section.

As I say, I'm not exactly sure if this is the best way (maybe there's another - suggestions are welcome) and not exactly sure what the problem is although I suspect it's something to do with the sessions?

Any help, advice, corrections or examples would be appreciated. It's all done in lua and I've tried to avoid session.originate as I understand this is deprecated.

Thanks

Adam


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120719/51a90377/attachment.html
Michael Collins
2012-07-19 18:50:07 UTC
Permalink
First off, welcome to FreeSWITCH!

I would recommend that you do as much as possible in the dialplan and as
little as possible in Lua. Lua makes things like if/then/else blocks
trivially easy. The XML dialplan makes connecting calls trivially easy. The
sweet spot is to find a nice balance. From what I see in your samples
below, you don't even need the receivewithwhisper.lua on the b-leg. You
could create a very simple dialplan extension that has each of the dp apps
that you are executing in that Lua script. Then your execute_on_answer will
be a transfer to that extension instead of calling Lua.

Maybe something like this...

Modify initiator script:
new_session =
freeswitch.Session("[execute_on_answer=transfer:whisper_answer]sofia/external/12345 at mydest");


Then add an extension:

<extension name="whisper answer">
<condition field="destination_number" expression="^whisper_answer$">
<action application="answer"/>
<action application="playback" data="ConnectingToCaller.wav"/>
<action application="conference" data="CONFTEST at default+flags{endconf,
moderator}"/>
<action application="hangup"/>
</condition>
</extension>

Tinker with that and see what you can get accomplished.

-MC
Post by Alpha Niner
Hi,
Firstly apologies for the newbie question. I've tried searching the
various documentation and trying a few different things but to no avail, so
I've come here to ask for help. I think my problem relates to sessions,
but I'm not totally sure.
1. A lua script is run by someone calling into FS (the initiator)
2. They select an option, which originates and makes an outbound call to
another phone number
3. The 3rd party (hopefully) answers their phone and receives a prompt
that they're going to be connected (the receiver)
4. Both parties join a conference and talk to each other (a conference as
there may be other parties in future)
To do this I'm creating a session and using execute_on_answer to run the
second script and provide the prompt to the receiving party. However the
receiving party never hears a prompt, comes into the conference,
immediately drops out and hangs up.
Here are the scripts, they're pretty simple;
session:answer()
session:streamFile("WaitForOutdial.wav")
new_session = freeswitch.Session("[execute_on_answer=lua
/usr/local/freeswitch/scripts/receivewithwhisper.lua]sofia/external/12345 at mydest");
session:execute("conference", "CONFTEST at default+flags{endconf, moderator}")
session:hangup();
The above works fine and the outbound call is placed. The script below is
then executed but the receiving phone rings but nothing is heard, the
conference is joined/exited and it terminates again;
session:answer()
session:streamFile("ConnectingToCaller.wav")
session:execute("conference", "CONFTEST at default+flags{endconf, moderator}")
session:hangup();
The receiving scripts runs when the receiver answers their phone, and
executes (quickly) and terminates. I was expecting it to drop into the
conference and I'd be able to talk to the other person. It does join the
conference, but then exits right away and falls through to the hangup
section.
As I say, I'm not exactly sure if this is the best way (maybe there's
another - suggestions are welcome) and not exactly sure what the problem is
although I suspect it's something to do with the sessions?
Any help, advice, corrections or examples would be appreciated. It's all
done in lua and I've tried to avoid session.originate as I understand this
is deprecated.
Thanks
Adam
_________________________________________________________________________
consulting at 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
Join Us At ClueCon - Aug 7-9, 2012
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
--
Michael S Collins
Twitter: @mercutioviz
http://www.FreeSWITCH.org
http://www.ClueCon.com
http://www.OSTAG.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120719/503c7d3a/attachment.html
Loading...