搭建一个小型的asterisk电话系统 (四、增加voicemail功能)

  • Post author:
  • Post category:其他




一,建表



1.1 voicemail

Voicemail表定义了voicemail的用户列表,采用动态加载的功能,这样方便更新。voicemail的表结构如下:

CREATE TABLE `voicemail` (
  `uniqueid` int(11) NOT NULL AUTO_INCREMENT,
  `customer_id` int(11) NOT NULL DEFAULT '0',
  `context` varchar(50) DEFAULT 'default',
  `mailbox` varchar(11) NOT NULL DEFAULT '0',
  `password` varchar(10) DEFAULT '1234',
  `fullname` varchar(50) NOT NULL DEFAULT '',
  `email` varchar(50) NOT NULL DEFAULT '',
  `pager` varchar(50) NOT NULL DEFAULT '',
  `stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `attach` varchar(3) DEFAULT 'no',
  `saycid` varchar(3) DEFAULT 'no',
  `hidefromdir` varchar(3) NOT NULL DEFAULT 'no',
  PRIMARY KEY (`uniqueid`),
  UNIQUE KEY `vm_idx` (`context`,`mailbox`),
  KEY `mailbox_context` (`mailbox`,`context`)
) ENGINE=MyISAM AUTO_INCREMENT=2872 DEFAULT CHARSET=utf8;

加入几个用户,在实际的操作中,可以采用动态页面进行,比如PHP,JSP等。

INSERT INTO `voicemail` VALUES 
(2868,0,'default','2220','1234','2220','','','','no','no','no'),
(2869,0,'default','2221','1234','2221','','','','no','no','no'),
(2870,0,'default','2222','1234','2222','','','','no','no','no'),
(2871,0,'default','2223','1234','2223','','','','no','no','no');



1.2  voicemessages

voicemessages表维护每一个voicemail用户的voice消息,可以根据用户的电话拨号情况被动态地增加(留言)和删除(听留言后按7删除)。voice的信息被存储在recording字段中,也被存储在/var/spool/asterisk/voicemail目录中相应的用户文件夹下。voicemessages的表结构如下:

CREATE TABLE `voicemessages` (
  `uniqueid` int(11) NOT NULL AUTO_INCREMENT,
  `dir` varchar(80) DEFAULT NULL,
  `msgnum` int(11) DEFAULT NULL,
  `recording` blob,
  `context` varchar(80) DEFAULT NULL,
  `macrocontext` varchar(80) DEFAULT NULL,
  `callerid` varchar(40) DEFAULT NULL,
  `origtime` varchar(40) DEFAULT NULL,
  `duration` varchar(20) DEFAULT NULL,
  `mailboxuser` varchar(80) DEFAULT NULL,
  `mailboxcontext` varchar(80) DEFAULT NULL,
  `label` varchar(30) DEFAULT NULL,
  `flag` varchar(10) DEFAULT NULL,
  `read` tinyint(11) DEFAULT '0',
  PRIMARY KEY (`uniqueid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;



二、配置



2.1 配置extconfig.conf

在文件extconfig.conf中加入voicemail的动态加载功能

vim extconfig.conf

sippeers => odbc,asterisk,sip
sipusers => odbc,asterisk,sip
voicemail => odbc,asterisk,voicemail



2.2  配置voicemail.conf

; Voicemail Configuration
[general]
format=wav49|gsm|wav
serveremail=asterisk
attach=yes
skipms=3000
maxsilence=10
silencethreshold=128
maxlogins=3
; in res_odbc.conf.
odbcstorage=asterisk
; The default table for ODBC voicemail storage is voicemessages.
odbctable=voicemessages
emaildateformat=%A, %B %d, %Y at %r
pagerdateformat=%A, %B %d, %Y at %r
sendvoicemail=yes ; Allow the user to compose and send a voicemail while inside

[zonemessages]
eastern=America/New_York|'vm-received' Q 'digits/at' IMp
central=America/Chicago|'vm-received' Q 'digits/at' IMp
central24=America/Chicago|'vm-received' q 'digits/at' H N 'hours'
military=Zulu|'vm-received' q 'digits/at' H N 'hours' 'phonetic/z_p'
european=Europe/Copenhagen|'vm-received' a d b 'digits/at' HM

[default]



odbcstorage和odbctable分别定义了数据库以及数据库的对应表,意思是voicemail的message被写入此表中。

通过 module reload app_voicemail.so 命令使更改生效。

通过 voicemail show users for default 命令可以查看voicemail表中定义的用户。

sm*CLI> voicemail show users for default

=============================================================
=== Configured Voicemail Users ==============================
=============================================================
===
=== Mailbox ...
===
=== ==> uniqueid: 2868
=== ==> customer_id: 0
=== ==> context: default
=== ==> mailbox: 2220
=== ==> password: 1234
=== ==> fullname: 2220
=== ==> stamp: 2012-08-18 17:43:13
=== ==> attach: no
=== ==> saycid: no
=== ==> hidefromdir: no
===
=== ---------------------------------------------------------
===
=== Mailbox ...

请确保用户对spool目录具有写权限,不然系统会报“Permission denied”错误,留言功能将不能工作。如果没有写权限,请使用如下命令获得用户所有权,如果的用户名不是asteriskpbx,请替换自己的用户和组


sudo chown -R asteriskpbx.asteriskpbx /var/spool/asterisk/voicemail



2.3 修改拨号方案extensions.conf

本文将对系列文章(一)中的拨号方案进行了较大的修改,主要是当被叫方无人接听、占线或者线路不可用的时候,转入语音留言功能。具体拨号方案如下,

vim extensions.conf

[globals]
TRUNK=DAHDI/2-1

[default]

exten => _222x,1,Macro(stdexten,${EXTEN},SIP/${EXTEN})
	same => n,Congestion(5)

exten => _v222x,1,Verbose(2,to ${EXTEN})
	same => n,Verbose(2,from ${CALLERID(number)})
	same => n,Macro(stdvmmenu,${EXTEN:1})


exten => _ZXXXXX.,1,Verbose(2,to ZXXXXX  ${EXTEN})
	same => n,Verbose(2,from ${CALLERID(number)})
	same => n,Dial(${TRUNK}/${EXTEN},,f)
	same => n,Hangup

exten => _s-.,1,Congestion
exten => a,1,Macro(stdvmmenu,${ARG1})   ;If they press *, send the user into VoicemailMain
exten => a,2,Hangup


[macro-stdexten]
exten => s,1,Verbose(2,to stdexten ${ARG1})
	same => n,Verbose(2,from ${CALLERID(number)})
	same => n,Dial(${ARG2},20,tf)
	same => n,Verbose(2, dial status s-${DIALSTATUS})
	same => n,Goto(s-${DIALSTATUS},1)

exten => s-NOANSWER,1,Macro(stdvm,${ARG1},u)
	same => n,Hangup

exten => s-BUSY,1,Macro(stdvm,${ARG1},b)
	same => n,Hangup


exten => s-CHANUNAVAIL,1,Macro(stdvm,${ARG1},u)
	same => n,Hangup




[macro-stdvm]
; ARG1 = vmbox ARG2 = u/b

exten => s,1,Answer
	same => n,Wait(2)
	same => n,Verbose(2,${ARG1}@default,${ARG2})
	same => n,Voicemail(${ARG1}@default,${ARG2})
	exten => n,Hangup

exten => a,1,Macro(stdvmmenu,${ARG1})
exten => a,2,Hangup

[macro-stdvmmenu]
; ARG1 = vmbox

exten => s,1,Answer
exten => s,2,Wait(2)
exten => s,3,VoicemailMain(${ARG1}@default)
exten => s,4,Hangup


[from-pstn]
exten => s,1,Verbose(2,INCOMING CALL ${EXTEN})
	same => n,Answer()
	; same => n,Dial(SIP/2222)
 	same => n,Macro(stdexten,2222,SIP/2222) ;forward incoming call to 2222, it will be changed later.
	;same => n,Playback(tt-weasels)
	same => n,Hangup

通过 dialplan reload 命令使拨号方案生效。



三、测试

配置结束之后,就可以对voicemail的功能进行测试。测试步骤如下

内线拨打:

1,2221呼叫2222

2,不用接听2222并等待呼叫音20秒超时

3,2221听到留言提示后留言并挂机

4,在2222 IP电话机拨Message键,如果是软件话,也可以直接拨叫“v2222”,

5,提示输入密码后,键入“1234”

6,听取留言

外线拨打并被自动注入2222分机:

1,用手机或者别的固定电话呼叫你的PSTN好,例如:0216436XXXX。呼叫被自动转到2222

2-6步骤和内线拨打相同,不再累述。



版权声明:本文为whyonly原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。