• 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@wherever 19005551212 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:5080 1001 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:5080 1001 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:5080 Action sleep(5000)

    Dialplan: sofia/external/1001@10.55.55.138:5080 Action endless_playback(/usr/local/freeswitch/sounds/101-baidu-mp3.mp3)

    ...

    EXECUTE sofia/external/1001@10.55.55.138:5080 sched_hangup(+10)

    EXECUTE sofia/external/1001@10.55.55.138:5080 send_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=1 ms=250 samples=2000

    ...

    EXECUTE sofia/external/1001@10.55.55.138:5080 sleep(5000)

    ...

    EXECUTE sofia/external/1001@10.55.55.138:5080 endless_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应该也有实现的可行性。具体情况未详细深入了解。

    空空如常

    求真得真

  • 相关阅读:
    概述Linux内核驱动之GPIO子系统API接口
    LayaBox---TypeScript---基础数据类型
    在c#中使用NPOI结合Magicodes.IE.excel将xlsx文件内存中转换为xls文件
    【推理引擎】从源码看ONNXRuntime的执行流程
    从根源剖析qsort函数及冒泡算法详解(qsort函数简介+排序算法举例+排序各类型数据举例及详细解析+冒泡排序算法实现qsort函数)
    河大-计算机院-编译原理--学习+实验+期末复习资料
    nginx配置中$http_host、$host、$host:$proxy_port和$host:$server_port区别
    透明质酸包裹马钱子碱白蛋白纳米粒|替尼泊苷人血清白蛋白纳米粒|肝素卵清白蛋白纳米粒(制备方法)
    Linux(5):Linux 磁盘与文件管理系统
    Redis的GEO结构
  • 原文地址:https://blog.csdn.net/qiuzhendezhen/article/details/125446175