<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I got my first Erlang callback from Freeswitch working. The dialplan
segment collects the PIN:<br>
<br>
<extension name=\"OperatorLogin\"><br>
<condition field=\"destination_number\" expression=\"^6200$\"><br>
<action application=\"answer\" /><br>
<action application=\"set\"
data=\"hangup_after_bridge=false\" /><br>
<action application=\"play_and_get_digits\" data=\"4 4 1
5000 # /opt/freeswitch/sounds/en/us/callie/conference/8000/conf-pin.wav
/opt/freeswitch/sounds/en/us/callie/conference/8000/conf-bad-pin.wav
operator_pin \\d+\" /><br>
<action application=\"log\" data=\"INFO operator_pin is
${operator_pin}\" /><br>
<action application=\"erlang\" data=\"pbx_op_logged_in
pursuit@testsrv\" /><br>
</condition><br>
</extension><br>
<br>
The Erlang callback validates the PIN, and automatically hangs up the
call if a bad PIN was entered.<br>
<br>
There isn't anything special about the callback -- it's based on the
skeleton code from the Freeswitch documentation.<br>
<br>
Andrew Thompson wrote:
<blockquote cite="mid:20100223224902.GB1751@hijacked.us" type="cite">
<pre wrap="">Comments inline.
On Tue, Feb 23, 2010 at 03:00:46PM -0600, Mark Sobkow wrote:
</pre>
<blockquote type="cite">
<pre wrap="">It's become clear that I need to use Erlang event processing to do what
I need to do with Freeswitch, but I can't even get the most basic of
tasks working yet. (i.e. Answer the call and collect the PIN code from
the operator.)
The dialplan version of what I'm trying to do is:
<extension name=\"OpCallsIn\">
<condition field=\"destination_number\" expression=\"^6100$\">
<action application=\"answer\" />
<action application=\"play_and_get_digits\" data=\"4 4 1 5000 #
/opt/freeswitch/sounds/en/us/callie/conference/8000/conf-pin.wav
/opt/freeswitch/sounds/en/us/callie/conference/8000/conf-bad-pin.wav
operator_pin \\d+\" />
<action application=\"log\" data=\"INFO operator_pin is
${operator_pin}\" />
<action application=\"log\" data=\"INFO Queueing operator to
fifo\" />
<action application=\"fifo\" data=\"6100@${domain_name} in\" />
</condition>
</extension>
Attached is the Erlang that's attempting to do the same thing. The
Erlang is invoked by the following dialplan fragment:
<extension name=\"ErlangCallback\">
<condition field=\"destination_number\" expression=\"^6200$\">
<action application=\"erlang\" data=\"pbx_callback
pursuit@testsrv\" />
</condition>
</extension>
Any suggestions?
</pre>
</blockquote>
<pre wrap=""><!---->
Why not request the pin in the dialplan and then yield call control to
erlang? That's what I do most of the time.
</pre>
<blockquote type="cite">
<pre wrap="">%% Author: mark
%% Created: Feb 23, 2010
%% Description: TODO: Add description to pbx_callback
-module(pbx_callback).
%%
%% Include files
%%
%%
%% Exported Functions
%%
-export([start/0, run/0, launch/1]).
start() ->
        Pid = spawn( ?MODULE, run, [] ),
        register( ?MODULE, Pid ),
        { ok, Pid }.
run() ->
        receive
                { call, Data } ->
                        { event, [UUID | Rest]} = Data,
                        syslog:debug( "pbx_callback:run() New call received, UUID=~p, Rest=~p~n", [UUID, Rest] ),
                        AnswerResults = pbx:api( eval, "uuid:" ++ UUID ++ " answer" ),
                        syslog:debug( "pbx_callback:run() AnswerResults=~p~n", [AnswerResults] ),
                        GetPinResults = pbx:api( eval, "uuid:" ++ UUID ++ " play_and_get_digits 4 4 1 5000 # /opt/freeswitch/sounds/en/us/callie/conference/8000/conf-pin.wav /opt/freeswitch/sounds/en/us/callie/conference/8000/conf-bad-pin.wav operator_pin \\d+" ),
                        syslog:debug( "pbx_callback:run() GetPinResults=~p~n", [GetPinResults] ),
                        GetPinVarResults = pbx:api( uuid_getvar, UUID ++ " operator_pin" ),
                        syslog:debug( "pbx_callback:run() GetPinVarResults=~p~n", [GetPinVarResults] ),
                        run();
                {call_event, Data} ->
                        { event, [UUID | Rest]} = Data,
                        Name = proplists:get_value( "Event-Name", Rest ),
                        syslog:debug( "pbx_callback:run() call_event UUID=~p, Name=~p, Rest=~p~n", [UUID, Name, Rest] ),
                        run();
                {get_pid, UUID, Ref, Pid} ->
                        NewPid = spawn( ?MODULE, run, [] ),
                        syslog:debug( "pbx_callback:run() Request to spawn new handler process, returning PID ~p~n", [NewPid] ),
                        Pid ! { Ref, NewPid },
                        run()
        end.
launch( Ref ) ->
        NewPid = spawn( ?MODULE, run, [] ),
        syslog:debug( "pbx_callback:launch() Returning new PID ~p~n", [NewPid] ),
        {Ref, NewPid}.
</pre>
</blockquote>
<pre wrap=""><!---->
I don't know what your 'pbx' module is doing so I can't really help you
there. Are you doing a sendmsg for play_and_get_digits or what? You
should be using a uuid_getvar to get the result of the
play_and_get_digits in any case. How far does this code get before
failing?
Andrew
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Mark Sobkow
Senior Developer
MarkeTel Multi-Line Dialing Systems LTD.
428 Victoria Ave
Regina, SK S4N-0P6
Toll-Free: 800-289-8616-X533
Local: 306-359-6893-X533
Fax: 306-359-6879
Email: <a class="moz-txt-link-abbreviated" href="mailto:m.sobkow@marketelsystems.com">m.sobkow@marketelsystems.com</a>
Web: <a class="moz-txt-link-freetext" href="http://www.marketelsystems.com">http://www.marketelsystems.com</a> </pre>
</body>
</html>