FreeSWITCH技巧:如何向通话的另一方号码发送dtmf?
来源:互联网 发布:女生发型 知乎 编辑:程序博客网 时间:2024/05/02 00:30
注:这里的文章都是本人的日常总结,请尊重下个人的劳动成果,转载的童鞋请注明出处,谢谢。如您转载的文章发生格式错乱等问题而影响阅读,可与本人联系,无偿提供本文的markdown源代码。联系邮箱:jizhask@gmail.com.
需求描述
在实际的应用中,经常有这样的需求,比如一个号码拨打外线,需要送dtmf出去(如拨打10086,根据提示按1按2等),在这种情况下,如果处理呢?
需求分析
其实该问题可以分解为下面两个子问题:
1、如何根据一方号码,获取与之通话的另一方号码? 比如66903 拨打 66904,那如何根据66903来获取到66904呢?
解决方法:
通过执行FreeSWITC的API命令,可以获取另一条信道的信息,如下:
show channels like 66903@ as xml
在该命令的返回值中抽取sent_callee_num,即为另一方的号码。
下面是具体的实现方法:
- --根据一方号码获取另一条腿的UUID
- function getOtherLegUUID(api,num)
- local uuid;
- local res=api:executeString("show channels like "..num.."@ as xml")
- ----判断获取的channel信息是否为空
- --fslog("debug","show channels res",res);
- --如果channel信息不为空
- if res and string.len(res) >0 then
- local _,_, sendCalleeNum = string.find(res,"<sent_callee_num>(.-)<%/sent_callee_num>");
- if sendCalleeNum then
- uuid = getUUIDByNum(api,sendCalleeNum);
- end
- end
- return uuid;
- end
2、如何向另一方号码发送dtmf?
解决方法:
该问题比较容易处理,只需要调用uuid_send_dtmf方法即可。前提条件是获取到那个信道的UUID。
具体代码
下面是完整的脚本代码,仅供参考:
- --/****************************************************/
- --脚本名称:send_dtmf_toleg.lua
- --脚本参数:
- -- argv[1] 当前通话的号码
- -- argv[2] 待发送的dtmf信息
- --脚本功能:
- -- 根据当前通话的号码,查出另一条腿的uuid,然后向该uuid发送dtmf
- --作者: 默言 2013-11-24
- --/****************************************************/
- --输出freeeswitch日志
- function fslog(loglevel,logtitle, logbody)
- loglevel = loglevel or "debug";
- logtitle = logtitle or "";
- logbody = logbody or "";
- freeswitch.consoleLog(loglevel, "\n" .. argv[0] .. " : " .. logtitle .. "{" .. logbody .. "}\n");
- end
- --获取号码对应的uuid
- --参数:num, 待查询号码
- --返回:号码对应的通道的uuid
- function getUUIDByNum(api, num)
- local uuid;
- local res=api:executeString("show channels like "..num.."@ as xml")
- if res then
- --使用正则表达式从字符串中截取uuid
- --'-'代表最短匹配
- _,_,uuid = string.find(res,"<uuid>(.-)<%/uuid>")
- end
- fslog("debug","getUUID:" .. num, uuid);
- return uuid;
- end
- --根据一方号码获取另一条腿的UUID
- function getOtherLegUUID(api,num)
- local uuid;
- local res=api:executeString("show channels like "..num.."@ as xml")
- ----判断获取的channel信息是否为空
- --fslog("debug","show channels res",res);
- --如果channel信息不为空
- if res and string.len(res) >0 then
- local _,_, sendCalleeNum = string.find(res,"<sent_callee_num>(.-)<%/sent_callee_num>");
- if sendCalleeNum then
- uuid = getUUIDByNum(api,sendCalleeNum);
- end
- end
- return uuid;
- end
- do
- local legNum=argv[1];
- --待发送的dtmf信息
- local dtmfs = argv[2];
- fslog("debug","start to send dtmf, legnum",legNum);
- fslog("debug","need send dtmfs", dtmfs);
- if legNum and tonumber(legNum) then
- api=freeswitch.API();
- uuid=getOtherLegUUID(api, legNum);
- if uuid then
- local cmd = "uuid_send_dtmf " .. uuid .. " " .. dtmfs;
- fslog("debug","send_dtmf cmd", cmd);
- api:executeString(cmd);
- else
- fslog("warning","cannot get another leg uuid","");
- end
- else
- fslog("warning","invalid parameters","");
- end
- end
0 0
- FreeSWITCH技巧:如何向通话的另一方号码发送dtmf?
- FreeSWITCH技巧:如何向通话的另一方号码发送dtmf?
- 如何向通话的另一方号码发送dtmf Export原理和使用
- Android通话中发送DTMF信号
- 如何向另一场景发送信息
- 发送dtmf键盘事件(模拟通话界面键盘事件)
- 发送dtmf键盘事件(模拟通话界面键盘事件)
- 发送dtmf键盘事件(模拟通话界面键盘事件)
- Android发送dtmf键盘事件(模拟通话界面键盘事件)
- freeswitch 两方通话过程中,按*3进入指定的会议
- S60中如何捕捉通话动作,获得当前通话的号码
- PJSIP 检测通话过程中对方手机发送过来的in-bnad DTMF(no rfc2833)按键信息
- freeswitch 对dtmf 支持
- freeswitch配置之dtmf
- 关于:Android 如何发送/接收DTMF问题
- iPhone向多个号码发送短信的代码
- android 拨号盘输入号码时来电,通话结束后回到拨号盘,如何保存之前输入的号码
- FreeSWITCH通话测试
- hadoop2的参数配置实例
- 对高德,马云为何非得全资收购?
- linux shell实现随机数多种方法(date,random,uuid)
- ios Map 开发笔记 四 导航画线
- UVa 10534 Wavio Sequence
- FreeSWITCH技巧:如何向通话的另一方号码发送dtmf?
- 单元测试本质:面向逻辑块
- 互联网公司该向东莞学什么?
- 锁和并发性----锁
- FreeSWITCH: JAVA模块的简单应用(mod_java)
- 使用Netbeans创建java Web项目
- CentOS 6.3 安装Apache
- Attachment
- Binary Tree Maximum Path Sum