MySQL custom ringtones

本文介绍了一个使用MySQL数据库来个性化Snom和其他支持ALERT_INFO字段电话铃声的小脚本。通过匹配来电显示和被叫分机号,该脚本能够根据不同呼叫类型选择相应的铃声音频文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Custom ringtones

using ALERT_INFO
This is a little script that will you let personalize
ringwave on a Snom phone and every phone that supports ALERT_INFO
field ( i.e. Cisco phones ).
You must place this script before the DIAL or QUEUE statement and
it will choose the best ringwave for the type of call specified.
It bases is search on a mysql table that contains a prefix for the callerid,
a prefix for the called extension and the filename of the ringtone.
when a call comes in this script matches the callerid and the called extension
with the database. Keep in mind that it gives precedence basing on the maximum
length of the best matching pattern but caller pattern has a 10x multiplier so
it is 10 time more important the caller than the called extension.

Let us see some examples:

the table contains

cid_fromcid_toringwave
external.wav
8
internal.wav
0805myexternal.wav
8805myinternal.wav




supposed that the local dialplan states that 8XX are local
number everyone will have "external.wav" as ringtone for external
calls and "internal.wav" BUT the 805 extension will have "myexternal.wav"
for external calls and "myinternal.wav" for internal calls.
you can be more and more precise adding more prefix for calls local to
you city, your country and so on.
the ringwaves must reside on a web server so that phones can download
them as they need them.

here is the script:

 exten => s-sound,1,MYSQL(Connect connid myhostname login password databasename)
 exten => s-sound,2,MySQL(Query resultid ${connid} SELECT/ ringwave/,CASE WHEN ISNULL(cid_from)/ then/ 0/ ELSE/ LENGTH(cid_from)*10/ END+CASE/ WHEN/ ISNULL(cid_to)/ then/ 0/ ELSE/ LENGTH(cid_to)/ END/ from/ ringer/ where/ (cid_from/ is/ NULL/ OR/ LEFT(/"${CALLERIDNUM}/"/,LENGTH(cid_from))=cid_from)/ AND/ (cid_to/ is/ NULL/ OR/ LEFT(/"${ARG1}/"/,LENGTH(cid_to))=cid_to)/ order/ by/ 2/ desc)
 exten => s-sound,3,Noop(result1 ${resultid})
 exten => s-sound,4,GotoIf($[empty${resultid} = empty]?30:5)
 exten => s-sound,5,MYSQL(Fetch foundrow ${resultid} selectedringwave)
 exten => s-sound,6,Noop(foundrow ${foundrow})
 exten => s-sound,7,GotoIf($["${foundrow}" = "1"]?100:30)

 exten => s-sound,30,SetVar(ALERT_INFO=${DEFAULT_SOUND))
 exten => s-sound,31,Goto(s-sound,110)

 exten => s-sound,100,SetVar(ALERT_INFO=http://webserver/${selectedtingwave))
 exten => s-sound,101,Goto(s-sound,110)

 exten => s-sound,110,MYSQL(Clear ${resultid} )
 exten => s-sound,111,MYSQL(Disconnect ${connid})
 exten => s-sound,112,Goto  ( goto DIAL statement )

Here is the MySQL table needed:

 CREATE TABLE ringer (
    cid_from char(20)  default NULL,
    cid_to char(20)  default NULL,
    ringwave char(20) default NULL
 ) ;

have a nice ring.
Eugenio

See also

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值