Freeswitch使用originate转dialplan


概述

Freeswitch是一款非常好用的开源VOIP软交换平台。

最近在对fs做一些功能测试,测试的过程中产生的一个需求,如何从fs发起呼叫并把后续的呼叫流程转到某一个dialplan上,这样在测试时会非常方便好用,可以随时修改dialplan定制业务流程。

通过对fs官方文档搜索后,排除了“transfer”、“execute_extension”、“bind_meta_app”,偶然发现“originate”接口可以直接实现这样的功能需求。


环境

centos:CentOS  release 7.0 (Final)或以上版本

freeswitch:v1.8.7

GCC:4.8.5


originate

originate是一个API接口,接口格式如下。

originate <call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]


接口实例。

originate{origination_caller_id_number=9005551212}sofia/default/whatever@wherever&bridge({origination_caller_id_number=8001234567}sofia/profile/someother@destination.com)


从接口格式来看,originate接口可以使用“&”接一个APP接口,在呼叫接通之后继续处理流程,但是有时候一个APP是不够用的,这样我们就需要在“originate”之后把呼叫流程转到dialplan中继续处理。


转dialplan的接口实例。

originate{origination_caller_id_number=9005551212}sofia/default/whatever@wherever19005551212 XML default CALLER_ID_NAME CALLER_ID_NUMBER

这个实例中,使用originate接口发起呼叫,然后转到XML类型的拨号计划“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>


测试

在freeswitch命令行中使用originate发起呼叫,再转到拨号计划ext_test发送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服务器上的1001,呼叫接通之后,发送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

...

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


总结

使用originate接口,可以直接实现呼叫转dialplan的业务流程。

仔细想一想,通过bridge转接到某一个dailplan应该也有实现的可行性。具体情况未详细深入了解。


空空如常

求真得真

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容