Hi,<br><br>It is easy to achieve using powerful Lua scripting and Core ODBC (<a href="http://wiki.freeswitch.org/wiki/Using_ODBC_in_the_core">http://wiki.freeswitch.org/wiki/Using_ODBC_in_the_core</a>)<br><br>If you did not have any experience with Lua, just copy paste script below, and fix syntax errors if any :) <br>
(Or you can achieve similar using perl, javascript, etc...)<br><br>Steps:<br><br>1. Add the following block inside your default dialplan (for example you want to handle international calls, prefix &quot;00&quot; or &quot;+&quot;)<br>
-----------------------------------------------------------------------------<br>&lt;extension name=&quot;international_with_some_routing&quot;&gt;<br>      &lt;condition field=&quot;destination_number&quot; expression=&quot;^(00|\+)(\d+)&quot;&gt;        <br>
          &lt;action application=&quot;lua&quot; data=&quot;call.lua $2&quot;/&gt;<br>      &lt;/condition&gt;      <br>&lt;/extension&gt;<br>-----------------------------------------------------------------------------<br>
<br><br>2. Create &quot;call.lua&quot; with the following lines and put it into &quot;scripts&quot; folder under freeswitch main folder:<br>-----------------------------------------------------------------------------<br>
--get db handler<br>local dbh = assert(freeswitch.Dbh(&quot;my_routing_db&quot;,&quot;my_user&quot;,&quot;my_pass&quot;));<br><br>subscriber_number = session:getVariable(&quot;accountcode&quot;); --or session:getVariable(&quot;caller_id_number&quot;); if you wish<br>
called_number = argv[1];<br><br>--let&#39;s check about money<br>balance = 0;<br>dbh:query(&quot;select balance from subscriber where subscriber_number=&#39;&quot;..subscriber_number..&quot;&#39;&quot;,<br>function(row)     <br>
    balance = tonumber(row.balance);<br>end);<br><br>if (balance &lt;= 0) then<br>    freeswitch.consoleLog(&quot;WARNING&quot;, &quot;Call denied for &quot;..subscriber_number..&quot; to &quot;..called_number..&quot; Balance: &quot;..balance..&quot;\n&quot;);<br>
    return;<br>end    <br><br>--select price plan and gateway (you can implement more complex logic here, to select the plan with lowest cost, etc)<br>--assuming you use mysql<br>dbh:query(&quot;select price_buy, price_sell, provider from dialplan where instr(&#39;&quot;..called_number..&quot;&#39;,prefix)=1 order by prefix desc limit 1&quot;,<br>
function(row) <br>    price_buy=tonumber(row.price_buy);<br>    price_sell=tonumber(row.price_sell);<br>    called_gateway=row.provider;<br>end);<br><br>--add some checks if needed<br>call_duration_min = balance / price_sell;<br>
call_duration_sec = call_duration_min * 60;<br><br>--release db handler<br>dbh:release();<br><br>--prepare outgoing session<br>called_parameters = &quot;{ignore_early_media=true,originate_timeout=90,price_sell=&quot;..price_sell..&quot;,price_buy=&quot;..price_buy..&quot;,subscriber_number=&quot;..subscriber_number..&quot;,hangup_after_bridge=true}&quot;;<br>
called_string = called_parameters..&quot;sofia/gateway/&quot;..called_gateway..&quot;/&quot;..called_number;<br>    <br>session:setVariable(&quot;ringback&quot;, &quot;%(2000,4000,440,480)&quot;);<br>called_session = freeswitch.Session(called_string, session);<br>
<br>--sometimes it is needed :)    <br>session:sleep(200);<br><br>if (called_session:ready()) then    <br>    -- this will disconnect the call after allowed seconds<br>    session:execute(&quot;sched_hangup&quot;,&quot;+&quot;..call_duration_sec);    <br>
    --finally, bridge<br>    freeswitch.bridge(session, called_session);        <br>end<br><br>--that&#39;s it<br>-----------------------------------------------------------------------------<br><br>Make sure that you have valid registered gateway as returned by &quot;called_gateway&quot; in your conf/sip_profiles.<br>
<br>Any questions, I will be glad to assist.<br><br>Regards,<br>Vitalie<br><br><br><br><br><div class="gmail_quote">2011/7/7 Nazim Aghabayov <span dir="ltr">&lt;<a href="mailto:nazim.aghabayov@gmail.com">nazim.aghabayov@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello Mateusz,<br>
<br>
I&#39;m finding  ESL powerful yet complicated and using mod_xml_curl for<br>
dynamic routing.<br>
mod_xml_curl with  with bindings = &quot;dialplan&quot; handles routing just fine.<br>
<a href="http://wiki.freeswitch.org/wiki/Mod_xml_curl" target="_blank">http://wiki.freeswitch.org/wiki/Mod_xml_curl</a><br>
<br>
Another approach is to a the Lua scripts for setting the variables<br>
&quot;inside&quot; the dialplan.<br>
FreeSWITH is a flexible system, so there are a lot of ways to achieve<br>
the same result.<br>
<br>
Best Regards,<br>
<font color="#888888">Nazim<br>
</font><div><div></div><div class="h5"><br>
<br>
On 07/01/2011 05:55 PM, Mateusz Bartczak wrote:<br>
&gt; OK but how can I respond for received events?<br>
&gt;<br>
&gt; I subscribe to receive events using following event socket command:<br>
&gt;<br>
&gt; event plain CHANNEL_CREATE<br>
&gt;<br>
&gt; then I got all events of that type and that&#39;s great but the question is how<br>
&gt; can I handle those events, what&#39;s the syntax and where to put it?<br>
&gt;<br>
&gt; I will simply explain what I&#39;m trying to achieve:<br>
&gt;<br>
&gt; 1. User dialed number<br>
&gt; 2. CHANNEL_CREATE event is created<br>
&gt; 3. I got this event using socket<br>
&gt; 4. What to do now? How to respond for that event? For example I would like<br>
&gt; to respond with dialstring to use, user called number 123, I would like to<br>
&gt; return something like sofia/gateway123/00123<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; 2011/6/30 Steven Ayre&lt;<a href="mailto:steveayre@gmail.com">steveayre@gmail.com</a>&gt;<br>
&gt;<br>
&gt;&gt; Yes it&#39;s possible and I suggest you look at esl<br>
&gt;&gt;<br>
&gt;&gt; Steve on iPhone<br>
&gt;&gt;<br>
&gt;&gt; On 30 Jun 2011, at 09:54, Mateusz Bartczak&lt;<a href="mailto:netcentrica@gmail.com">netcentrica@gmail.com</a>&gt;  wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; Hi all<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I&#39;m new to FS and I would like to know is it possible to implement<br>
&gt;&gt; following scenario:<br>
&gt;&gt;&gt; 1. User dials number<br>
&gt;&gt;&gt; 2. Routing script detects outgoing call event. Every call needs to be<br>
&gt;&gt; handled by routing script.<br>
&gt;&gt;&gt; 3. Routing script takes in input: user name, domain, dialed number. Than<br>
&gt;&gt; it query database to find best SIP trunk to route the call, it also checks<br>
&gt;&gt; destination price per minute and calculates maximum call time for prepaid<br>
&gt;&gt; user.<br>
&gt;&gt;&gt; 4. Routing script output is: SIP trunk to use, SIP call parameters (ie.<br>
&gt;&gt; callerid), maximum call duration<br>
&gt;&gt;&gt; 5. FS read output from routing script and make call using returned<br>
&gt;&gt; parameters<br>
&gt;&gt;&gt; Preferred routing implementation technology: background running unix<br>
&gt;&gt; deamon written in Java or PHP. Connection with FS via socket.<br>
&gt;&gt;&gt; Event routing script will be multi-threaded, must be able to deal with a<br>
&gt;&gt; lot of calls in parallel and processing of one call should not block<br>
&gt;&gt; processing of other calls (I have this problem with Yate voip server, and<br>
&gt;&gt; that&#39;s really big problem)<br>
&gt;&gt;&gt; Is it possible to do this using FS?<br>
&gt;&gt;&gt; Any advices where to search for additional info? I know that there is<br>
&gt;&gt; event handler but can it return &quot;dialstring&quot; for outgoing call events?<br>
&gt;&gt;&gt; Some code examples?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I will really appreciate your help<br>
&gt;&gt;&gt;<br>
<br>
<br>
_______________________________________________<br>
Join us at ClueCon 2011, Aug 9-11, Chicago<br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a> 877-7-4ACLUE<br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></div></blockquote></div><br>