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 "00" or "+")<br>
-----------------------------------------------------------------------------<br><extension name="international_with_some_routing"><br> <condition field="destination_number" expression="^(00|\+)(\d+)"> <br>
<action application="lua" data="call.lua $2"/><br> </condition> <br></extension><br>-----------------------------------------------------------------------------<br>
<br><br>2. Create "call.lua" with the following lines and put it into "scripts" folder under freeswitch main folder:<br>-----------------------------------------------------------------------------<br>
--get db handler<br>local dbh = assert(freeswitch.Dbh("my_routing_db","my_user","my_pass"));<br><br>subscriber_number = session:getVariable("accountcode"); --or session:getVariable("caller_id_number"); if you wish<br>
called_number = argv[1];<br><br>--let's check about money<br>balance = 0;<br>dbh:query("select balance from subscriber where subscriber_number='"..subscriber_number.."'",<br>function(row) <br>
balance = tonumber(row.balance);<br>end);<br><br>if (balance <= 0) then<br> freeswitch.consoleLog("WARNING", "Call denied for "..subscriber_number.." to "..called_number.." Balance: "..balance.."\n");<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("select price_buy, price_sell, provider from dialplan where instr('"..called_number.."',prefix)=1 order by prefix desc limit 1",<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 = "{ignore_early_media=true,originate_timeout=90,price_sell="..price_sell..",price_buy="..price_buy..",subscriber_number="..subscriber_number..",hangup_after_bridge=true}";<br>
called_string = called_parameters.."sofia/gateway/"..called_gateway.."/"..called_number;<br> <br>session:setVariable("ringback", "%(2000,4000,440,480)");<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("sched_hangup","+"..call_duration_sec); <br>
--finally, bridge<br> freeswitch.bridge(session, called_session); <br>end<br><br>--that's it<br>-----------------------------------------------------------------------------<br><br>Make sure that you have valid registered gateway as returned by "called_gateway" 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"><<a href="mailto:nazim.aghabayov@gmail.com">nazim.aghabayov@gmail.com</a>></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'm finding ESL powerful yet complicated and using mod_xml_curl for<br>
dynamic routing.<br>
mod_xml_curl with with bindings = "dialplan" 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>
"inside" 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>
> OK but how can I respond for received events?<br>
><br>
> I subscribe to receive events using following event socket command:<br>
><br>
> event plain CHANNEL_CREATE<br>
><br>
> then I got all events of that type and that's great but the question is how<br>
> can I handle those events, what's the syntax and where to put it?<br>
><br>
> I will simply explain what I'm trying to achieve:<br>
><br>
> 1. User dialed number<br>
> 2. CHANNEL_CREATE event is created<br>
> 3. I got this event using socket<br>
> 4. What to do now? How to respond for that event? For example I would like<br>
> to respond with dialstring to use, user called number 123, I would like to<br>
> return something like sofia/gateway123/00123<br>
><br>
><br>
><br>
> 2011/6/30 Steven Ayre<<a href="mailto:steveayre@gmail.com">steveayre@gmail.com</a>><br>
><br>
>> Yes it's possible and I suggest you look at esl<br>
>><br>
>> Steve on iPhone<br>
>><br>
>> On 30 Jun 2011, at 09:54, Mateusz Bartczak<<a href="mailto:netcentrica@gmail.com">netcentrica@gmail.com</a>> wrote:<br>
>><br>
>>> Hi all<br>
>>><br>
>>> I'm new to FS and I would like to know is it possible to implement<br>
>> following scenario:<br>
>>> 1. User dials number<br>
>>> 2. Routing script detects outgoing call event. Every call needs to be<br>
>> handled by routing script.<br>
>>> 3. Routing script takes in input: user name, domain, dialed number. Than<br>
>> it query database to find best SIP trunk to route the call, it also checks<br>
>> destination price per minute and calculates maximum call time for prepaid<br>
>> user.<br>
>>> 4. Routing script output is: SIP trunk to use, SIP call parameters (ie.<br>
>> callerid), maximum call duration<br>
>>> 5. FS read output from routing script and make call using returned<br>
>> parameters<br>
>>> Preferred routing implementation technology: background running unix<br>
>> deamon written in Java or PHP. Connection with FS via socket.<br>
>>> Event routing script will be multi-threaded, must be able to deal with a<br>
>> lot of calls in parallel and processing of one call should not block<br>
>> processing of other calls (I have this problem with Yate voip server, and<br>
>> that's really big problem)<br>
>>> Is it possible to do this using FS?<br>
>>> Any advices where to search for additional info? I know that there is<br>
>> event handler but can it return "dialstring" for outgoing call events?<br>
>>> Some code examples?<br>
>>><br>
>>> I will really appreciate your help<br>
>>><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>