freeswitch拨打分机号-LMLPHP

概述

电话语音服务中,有一种稍微复杂的场景,就是总机分机的落地场景,客户拨打总机号码之后,需要再拨打分机号转接到指定的话机。

分机号的拨打一般在总机接通之后,会有语音提示,总机收号之后转接分机。

分机号转接的实现方式其实和IVR的实现方式是一致的,都是通过DTMF码收号。

本篇文档不讲总机分机怎么落地,而是讲怎么通过fs自动拨打分机。

环境

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

freeswitch:v1.8.7

GCC:4.8.5

APP接口

Freeswitch有app接口“send_dtmf”,可以很方便的发送DTMF码,源代码在mod_dptools模块。

使用方法很简单,格式如下。

send_dtmf <dtmf digits>[@<tone_duration>]

实例,拨号计划

<action application="send_dtmf" data="0123456789ABCD*#@100"/>

实例,C++代码。

char *extnum = "123456";

if (SWITCH_STATUS_SUCCESS != switch_core_session_execute_application(session, "send_dtmf", extnum))

{

    switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,

        "send_dtmf failed, extnum = %s\n", extnum);

}

拨号计划配置

修改fs配置文件/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="987654321"/>

                                <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,日志如下。

2022-06-10 15:57:57.810985 [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(987654321)

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 send_dtmf(987654321)

2022-06-10 15:57:57.810985 [DEBUG] switch_core_io.c:1918 sofia/external/1001@10.55.55.138:5080 send dtmf

digit=9 ms=250 samples=2000

2022-06-10 15:57:57.810985 [DEBUG] switch_core_io.c:1918 sofia/external/1001@10.55.55.138:5080 send dtmf

digit=8 ms=250 samples=2000

...

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

2022-06-10 15:57:57.810985 [DEBUG] switch_ivr_play_say.c:1498 Codec Activated L16@8000hz 1 channels 20ms

2022-06-10 15:57:57.820986 [DEBUG] switch_rtp.c:5237 Send start packet for [9] ts=160 dur=160/160/2000 seq=65154 lw=160

2022-06-10 15:57:57.820986 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=320/320/2000 seq=65155 lw=320

2022-06-10 15:57:57.841015 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=480/480/2000 seq=65156 lw=480

2022-06-10 15:57:57.841015 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=640/640/2000 seq=65157 lw=640

2022-06-10 15:57:57.861013 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=800/800/2000 seq=65158 lw=800

2022-06-10 15:57:57.861013 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=960/960/2000 seq=65159 lw=960

2022-06-10 15:57:57.881025 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=1120/1120/2000 seq=65160 lw=1120

2022-06-10 15:57:57.881025 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=1280/1280/2000 seq=65161 lw=1280

2022-06-10 15:57:57.901015 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=1440/1440/2000 seq=65162 lw=1440

2022-06-10 15:57:57.901015 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=1600/1600/2000 seq=65163 lw=1600

2022-06-10 15:57:57.921012 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=1760/1760/2000 seq=65164 lw=1760

2022-06-10 15:57:57.921012 [DEBUG] switch_rtp.c:5136 Send middle packet for [9] ts=160 dur=1920/1920/2000 seq=65165 lw=1920

2022-06-10 15:57:57.941013 [DEBUG] switch_rtp.c:5136 Send end packet for [9] ts=160 dur=2080/2080/2000 seq=65166 lw=1920

2022-06-10 15:57:57.941013 [DEBUG] switch_rtp.c:5136 Send end packet for [9] ts=160 dur=2080/2080/2000 seq=65167 lw=1920

2022-06-10 15:57:57.941013 [DEBUG] switch_rtp.c:5136 Send end packet for [9] ts=160 dur=2080/2080/2000 seq=65168 lw=1920

2022-06-10 15:57:57.941013 [DEBUG] switch_rtp.c:5084 Queue digit delay of 40ms

2022-06-10 15:57:57.980986 [DEBUG] switch_rtp.c:5237 Send start packet for [8] ts=1440 dur=160/160/2000 seq=65171 lw=1440

2022-06-10 15:57:57.980986 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=320/320/2000 seq=65172 lw=1600

2022-06-10 15:57:57.991013 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=480/480/2000 seq=65173 lw=1760

2022-06-10 15:57:57.991013 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=640/640/2000 seq=65174 lw=1920

2022-06-10 15:57:58.021023 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=800/800/2000 seq=65175 lw=2080

2022-06-10 15:57:58.021023 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=960/960/2000 seq=65176 lw=2240

2022-06-10 15:57:58.041014 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=1120/1120/2000 seq=65177 lw=2400

2022-06-10 15:57:58.041014 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=1280/1280/2000 seq=65178 lw=2560

2022-06-10 15:57:58.061012 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=1440/1440/2000 seq=65179 lw=2720

2022-06-10 15:57:58.061012 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=1600/1600/2000 seq=65180 lw=2880

2022-06-10 15:57:58.081014 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=1760/1760/2000 seq=65181 lw=3040

2022-06-10 15:57:58.081014 [DEBUG] switch_rtp.c:5136 Send middle packet for [8] ts=1440 dur=1920/1920/2000 seq=65182 lw=3200

2022-06-10 15:57:58.101024 [DEBUG] switch_rtp.c:5136 Send end packet for [8] ts=1440 dur=2080/2080/2000 seq=65183 lw=3200

2022-06-10 15:57:58.101024 [DEBUG] switch_rtp.c:5136 Send end packet for [8] ts=1440 dur=2080/2080/2000 seq=65184 lw=3200

2022-06-10 15:57:58.101024 [DEBUG] switch_rtp.c:5136 Send end packet for [8] ts=1440 dur=2080/2080/2000 seq=65185 lw=3200

2022-06-10 15:57:58.101024 [DEBUG] switch_rtp.c:5084 Queue digit delay of 40ms

...

总结

在呼叫接通之后,使用send_dtmf发送DTMF码,但是实际使用过程中,发现俩个问题。

第一个问题,发送DTMF码会和放音语音叠加。

第二个问题,发送DTMF码app执行之后,并不会马上发送,而是要等待有媒体流发送的同时开始发送。

本来想把源代码的流程一起讲完,但是跟踪了源代码之后,发现代码调用的逻辑比较复杂,在不同模块之间跳转较多,后面单独开一章讲代码流程。

空空如常

求真得真

06-29 17:53