freeswitch lua 回拨

190 篇文章 1 订阅
127 篇文章 2 订阅


需求
回拨, 外呼
命令行
呼通主叫后, 转到拨号方案
originate user/1000 2000 XML default
呼通主叫后, 播放XML IVR
originate {origination_caller_id_number=137XXXX4955,origination_caller_id_name=137XXXX4955}sofia/external/180XXXX9957@10.0.1.2:5060 &ivr(demo_ivr)
呼通主叫后, 执行脚本, 不带参数
originate {origination_caller_id_number=137XXXX4955,origination_caller_id_name=137XXXX4955}sofia/external/180XXXX9957@10.0.1.202:9080 &lua(demo_ivr.lua)
呼通主叫后, 执行脚本, 带参数
originate {origination_caller_id_number=137XXXX4955,origination_caller_id_name=137XXXX4955}sofia/external/180XXXX9957@10.0.1.202:9080 '&lua(dy_ivr.lua tier)'
更进一步
默认originate是阻塞的, 使用 bgapi 实现非阻塞回拨.
例如
bgapi originate {origination_caller_id_number=13771114955,origination_caller_id_name=13771114955}sofia/external/18051799957@10.0.1.2:5060 &ivr(demo_ivr)
应用
可以使用shell&fs_cli, esl, xml_rpc 外部控制FreeSWITCH进行外呼或回拨, 以实现批量外呼. 使用lua实现,主要用于熟悉originate命令。
调用示例:
lua callback.lua 1377XXX4955 180XXXX9957 2345677 360 /tmp/test.wav
callback.lua
-- -- CALLBACK -- -- Author: foxgoing@gmail.com / http://8000hz.com -- -- 功能描述:先拨打主叫,主叫接通后向主叫播放指定声音文件,然后拨打被叫,同时设置最大通话时长。 -- 设置供其他应用使用的客户号。主被叫都为外线号码。 local caller_number = argv[1]; --主叫号码 local callee_number = argv[2]; --被叫号码 local customer_number = argv[3]; --主叫的平台账号 local maxtimes = argv[4]; --最大通话时长(秒) local sounds = argv[5]; --声音文件路径 api = freeswitch.API(); local callstring = "bgapi originate {ringback="..sounds..",ignore_early_media=true}sofia/gateway/szcmcc/"..caller_number.." '&lua(call.lua "..maxtimes.." "..callee_number.." "..customer_number..")'"; freeswitch.consoleLog("notice", callstring.."\n"); api:executeString(callstring); freeswitch.consoleLog("notice", "Leave callback Scripts\n"); 复制代码
****call.lua
-- -- CALL , a part of callback -- -- Author: foxgoing@gmail.com / http://8000hz.com local maxtimes = argv[1]; --最大通话时常秒 local callee_number = argv[2]; --被叫号码 local customer_number = argv[3]; --主叫的平台账号 session:execute("sched_hangup", "+"..maxtimes.." allotted_timeout"); session:execute("set", "customer_number="..customer_number); session:execute("bridge", "sofia/gateway/szcmcc/"..callee_number); freeswitch.consoleLog("notice", "Leave call.lua Scripts\n"); 复制代码
****小贴士:
originate命令执行时,如果收到了183或200就会立即执行 ‘&’ 后面的语句,换句话说就是只要来了媒体就执行后面。
但人们的需求不一嘛,有些人需要只有接通主叫后才能执行’&’后面的语句。那么如果你就可以设置:
{ignore_early_media=true} 复制代码
如果要实现主被叫同时呼叫,但你的运营商只返回180,但你还是想要主被叫同时呼叫。那么你可以这样设置:
{return_ring_ready=true} 复制代码
reeswitch lua 回拨 主叫被叫号码
功能实现
1:主叫呼叫接入号,挂断主叫回busy给主叫
2:回拨 接通主叫号码及被叫号码
dialplan代码:


<action application=”lua” data=”test.lua ${destination_number}”/>


test.lua代码:
freeswitch.consoleLog("notice","test.lua debug\n") local caller=session:getVariable("caller_id_number"); local callee=argv[1]; freeswitch.consoleLog("notice","get caller "..caller.."\n") freeswitch.consoleLog("notice","get callee "..callee.."\n") session:hangup("USER_BUSY"); api = freeswitch.API(); local callstring = "bgapi originate {ignore_early_media=true,origination_caller_id_number="..callee..",origination_caller_id_name="..callee.."}user/"..caller.." '&bridge(sofia/gateway/szcmcc/"..callee..")'"; freeswitch.consoleLog("notice", callstring.."\n"); api:executeString(callstring); freeswitch.consoleLog("notice", "Leave callback Scripts\n");


缺点
还不知道怎么实现等待几秒后再回拨。
呼叫接入号后会马上进行回拨操作。

Freeswitch is an open-source telephony platform that allows you to build various communication applications. It supports multiple scripting languages, including Lua. Lua is a lightweight and powerful scripting language that is often used for extending the functionality of Freeswitch. With Lua, you can write custom applications, create dial plans, handle call control logic, and interact with various telephony features provided by Freeswitch. Lua scripts in Freeswitch are typically used for tasks such as call routing, IVR (Interactive Voice Response) systems, call recording, and more. To use Lua with Freeswitch, you need to have the mod_lua module enabled in your Freeswitch installation. Once enabled, you can start writing Lua scripts to control call flows and handle telephony events. Here is a simple Lua script example for Freeswitch that answers an incoming call and plays a welcome message: ```lua -- answer.lua session:answer() session:streamFile("/path/to/welcome-message.wav") ``` In this example, the `session:answer()` function answers the incoming call, and the `session:streamFile()` function plays an audio file to the caller. You can save this script as `answer.lua` and load it in your Freeswitch dial plan configuration to execute it when an incoming call arrives. Note that this is just a basic example, and Lua with Freeswitch offers much more functionality and flexibility. Feel free to explore the official Freeswitch documentation and Lua scripting resources for more advanced use cases and examples.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值