概述
Freeswitch是一款非常好用的開源VOIP軟交換平臺(tái)滔灶。
最近在對(duì)fs做一些功能測(cè)試肛宋,測(cè)試的過程中產(chǎn)生的一個(gè)需求咐容,如何從fs發(fā)起呼叫并把后續(xù)的呼叫流程轉(zhuǎn)到某一個(gè)dialplan上授药,這樣在測(cè)試時(shí)會(huì)非常方便好用幅疼,可以隨時(shí)修改dialplan定制業(yè)務(wù)流程。
通過對(duì)fs官方文檔搜索后堂飞,排除了“transfer”灌旧、“execute_extension”、“bind_meta_app”绰筛,偶然發(fā)現(xiàn)“originate”接口可以直接實(shí)現(xiàn)這樣的功能需求枢泰。
環(huán)境
centos:CentOS? release 7.0 (Final)或以上版本
freeswitch:v1.8.7
GCC:4.8.5
originate
originate是一個(gè)API接口,接口格式如下铝噩。
originate <call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]
接口實(shí)例衡蚂。
originate{origination_caller_id_number=9005551212}sofia/default/whatever@wherever&bridge({origination_caller_id_number=8001234567}sofia/profile/someother@destination.com)
從接口格式來看,originate接口可以使用“&”接一個(gè)APP接口骏庸,在呼叫接通之后繼續(xù)處理流程毛甲,但是有時(shí)候一個(gè)APP是不夠用的,這樣我們就需要在“originate”之后把呼叫流程轉(zhuǎn)到dialplan中繼續(xù)處理具被。
轉(zhuǎn)dialplan的接口實(shí)例玻募。
originate{origination_caller_id_number=9005551212}sofia/default/whatever@wherever19005551212 XML default CALLER_ID_NAME CALLER_ID_NUMBER
這個(gè)實(shí)例中,使用originate接口發(fā)起呼叫一姿,然后轉(zhuǎn)到XML類型的撥號(hào)計(jì)劃“default”中七咧。
配置
修改配置文件“/usr/local/freeswitch/conf/dialplan/test.xml”改执。
<include>
? ? ? ? <context name="ext_test">
? ? ? ? ? ? ? ? <extension name="test" continue="false">
? ? ? ? ? ? ? ? ? ? ? ? <condition field="destination_number" expression="^(\d+)$">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <action application="sched_hangup" data="+10"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <action application="send_dtmf" data="1234"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <action application="sleep" data="5000"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <action application="endless_playback" data="/usr/local/freeswitch/sounds/101-baidu-mp3.mp3"/>
? ? ? ? ? ? ? ? ? ? ? ? </condition>
? ? ? ? ? ? ? ? </extension>
? ? ? ? </context>
</include>
測(cè)試
在freeswitch命令行中使用originate發(fā)起呼叫,再轉(zhuǎn)到撥號(hào)計(jì)劃ext_test發(fā)送DTMF坑雅。
freeswitch@localhost.localdomain>originate{originator_codec=PCMA,origination_caller_id_number=0755110}sofia/external/sip:1001@10.55.55.138:50801001 XML ext_test
fs呼叫138服務(wù)器上的1001,呼叫接通之后衬横,發(fā)送DTMF并播放提示語(yǔ)音裹粤,日志如下。
freeswitch@localhost.localdomain>originate{originator_codec=PCMA,origination_caller_id_number=0755110}sofia/external/sip:1001@10.55.55.138:50801001 XML ext_test
...
2022-06-13 11:37:15.601015 [DEBUG]sofia.c:7084 Channel sofia/external/1001@10.55.55.138:5080 entering state [ready][200]
...
2022-06-13 11:37:15.610983 [INFO]mod_dialplan_xml.c:637 Processing?<0755110>->1001 in context ext_test
Dialplan:sofia/external/1001@10.55.55.138:5080 parsing [ext_test->test]continue=false
Dialplan:sofia/external/1001@10.55.55.138:5080 Regex (PASS) [test]destination_number(1001) =~ /^(\d+)$/ break=on-false
Dialplan:sofia/external/1001@10.55.55.138:5080 Action sched_hangup(+10)
Dialplan:sofia/external/1001@10.55.55.138:5080 Action send_dtmf(1234)
Dialplan: sofia/external/1001@10.55.55.138:5080Action sleep(5000)
Dialplan:sofia/external/1001@10.55.55.138:5080 Actionendless_playback(/usr/local/freeswitch/sounds/101-baidu-mp3.mp3)
...
EXECUTEsofia/external/1001@10.55.55.138:5080 sched_hangup(+10)
EXECUTE sofia/external/1001@10.55.55.138:5080send_dtmf(1234)
2022-06-13 11:37:15.610983 [DEBUG]switch_core_io.c:1918 sofia/external/1001@10.55.55.138:5080 send dtmf digit=1ms=250 samples=2000
...
EXECUTEsofia/external/1001@10.55.55.138:5080 sleep(5000)
...
EXECUTE sofia/external/1001@10.55.55.138:5080endless_playback(/usr/local/freeswitch/sounds/101-baidu-mp3.mp3)
...
2022-06-13 11:37:25.121013 [DEBUG]switch_ivr_play_say.c:1942 done playing file/usr/local/freeswitch/sounds/101-baidu-mp3.mp3
...
2022-06-13 11:37:25.121013 [DEBUG]mod_sofia.c:440 Channel sofia/external/1001@10.55.55.138:5080 hanging up,cause: ALLOTTED_TIMEOUT
總結(jié)
使用originate接口蜂林,可以直接實(shí)現(xiàn)呼叫轉(zhuǎn)dialplan的業(yè)務(wù)流程遥诉。
仔細(xì)想一想,通過bridge轉(zhuǎn)接到某一個(gè)dailplan應(yīng)該也有實(shí)現(xiàn)的可行性噪叙。具體情況未詳細(xì)深入了解矮锈。
空空如常
求真得真