freeswitch号码变化方案


概述

freeswitch是一款简单易用的开源音视频软交换平台。

在生产环境中,由于各个线路的号码规则并不统一,经常需要针对中继线路做号码变换的方案。

本文主要介绍fs中有哪些可选的号码变换方案。

环境

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

freeswitch:v1.8.7

GCC:4.8.5

拨号计划

拨号计划中,condition的匹配项配置中,可以对号码进行正则匹配,并根据格式做简单的号码变换功能。

<include>

<context name="public">

<extension name="test0">

<condition field="destination_number" expression="^test(\d+)$">

<action application="bridge" data="user/$1"/>

</condition>

</extension>

<extension name="test1">

<condition field="destination_number" expression="^000(\d+)$">

<action application="bridge" data="sofia/external/sip:${1}@10.55.55.138:5090"/>

</condition>

</extension>

<extension name="test2">

<condition field="destination_number" expression="^(\d+);.*$">

<action application="bridge" data="{sip_invite_call_id=${sip_call_id}}user/$1"/>

</condition>

</extension>

<extension name="test3">

<condition field="destination_number" expression="^(\d+)$">

<action application="bridge" data="{sip_invite_call_id=${sip_call_id}}user/$1"/>

</condition>

</extension>

</context>

</include>

test0中,对被叫号码删除了号码开头的‘test’字符串。

test1中,对被叫号码删除了号码开头的‘000‘字符串。

test2中,对被叫号码删除了号码中‘;‘后的部分。

test3中,号码不变。

regex接口

mod_dptools: regex接口函数。用法如下。

regex value expression results*

app接口返回‘0555555555‘。

freeswitch@localhost.localdomain> regex 61555555555|^61([0-9]{9})$|0%1

0555555555

app接口返回true。

freeswitch@localhost.localdomain> regex 61555555555|^61([0-9]{9})$

true

拨号计划的实例。

<action application="set" data="effective_caller_id_number=${regex(${caller_id_number}|^61([0-9]{9})$|0%1)}"/>

mod_translate

mod_translate模块通过配置文件和接口形式,支持对号码格式的更新,灵活方便。

并且在拨号计划中,使用translate模块可以在进入拨号计划之前对号码进行变换,这种场景在CDR话单中会有用处。

mod_translate模块默认是不编译安装的,要自行编译安装启动。

配置文件translate.conf.xml。

<include>

  <configuration name="translate.conf" description="Number Translation Rules">

    <profiles>

      <profile name="US">

<rule regex="^\+(\d+)$" replace="$1"/>

<rule regex="^(1[2-9]\d{2}[2-9]\d{6})$" replace="$1"/>

<rule regex="^([2-9]\d{2}[2-9]\d{6})$" replace="1$1"/>

<rule regex="^([2-9]\d{6})$" replace="1${areacode}$1"/>

<rule regex="^011(\d+)$" replace="$1"/>

      </profile>

      <profile name="GB">

<rule regex="^\+(\d+)$" replace="$1"/>

<rule regex="^$" replace="$1"/>

      </profile>

      <profile name="HK">

<rule regex="\+(\d+)$" replace="$1"/>

<rule regex="^(852\d{8})$" replace="$1"/>

<rule regex="^(\d{8})$" replace="852$1"/>

      </profile>

    </profiles>

  </configuration>

</include>

API接口。

translate <number> [<profile>]

APP接口。

<action application="translate" data="${destination_number} US"/>

实例1。

freeswitch@localhost.localdomain> translate +86123456 GB

2022-09-01 14:24:49.257196 [INFO] mod_translate.c:329 +86123456 GB

86123456

2022-09-01 14:24:49.257196 [DEBUG] mod_translate.c:128 translating [+86123456] against [GB] profile

2022-09-01 14:24:49.257196 [DEBUG] mod_translate.c:137 +86123456 =~ /^\+(\d+)$/

2022-09-01 14:24:49.257196 [NOTICE] mod_translate.c:348 Translated: 86123456

实例2。

freeswitch@localhost.localdomain> translate +852123456 HK

2022-09-01 14:26:37.117176 [INFO] mod_translate.c:329 +852123456 HK

2022-09-01 14:26:37.117176 [DEBUG] mod_translate.c:128 translating [+852123456] against [HK] profile

2022-09-01 14:26:37.117176 [DEBUG] mod_translate.c:137 +852123456 =~ /\+(\d+)$/

2022-09-01 14:26:37.117176 [NOTICE] mod_translate.c:348 Translated: 852123456

852123456

freeswitch@localhost.localdomain> translate 12345678 HK

2022-09-01 14:29:29.517186 [INFO] mod_translate.c:329 12345678 HK

85212345678

2022-09-01 14:29:29.517186 [DEBUG] mod_translate.c:128 translating [12345678] against [HK] profile

2022-09-01 14:29:29.517186 [DEBUG] mod_translate.c:137 12345678 =~ /\+(\d+)$/

2022-09-01 14:29:29.517186 [DEBUG] mod_translate.c:137 12345678 =~ /^(852\d{8})$/

2022-09-01 14:29:29.517186 [DEBUG] mod_translate.c:137 12345678 =~ /^(\d{8})$/

2022-09-01 14:29:29.517186 [NOTICE] mod_translate.c:348 Translated: 85212345678

总结

freeswitch中对正则表达式的支持有多种形式。

正则表达式对于常见的号码变换场景基本可以完美支持。

mod_translate模块很强大,可以深挖一下逻辑。


空空如常

求真得真

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

推荐阅读更多精彩内容

  • 概述 电话语音服务中,有一种稍微复杂的场景,就是总机分机的落地场景,客户拨打总机号码之后,需要再拨打分机号转接到指...
    求真得真阅读 533评论 0 1
  • 概述 Freeswitch是一款非常好用的开源VOIP软交换平台。 最近在对fs做一些功能测试,测试的过程中产生的...
    求真得真阅读 665评论 0 0
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,546评论 0 13
  • 概述 freeswitch 在对VOIP语音通话中,可以通过playback命令播放IVR语音文件。 默认情况下,...
    求真得真阅读 681评论 0 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,199评论 19 139