Blogs on System Administration, Scripting, System Monitoring, Cloud Computing & Virtualizaton, VoIP Systems, SMS Systems and Web Applications Development.

How to enable realtime voice messages in Asterisk?


Introduction

This is blog is to introduce realtime voice messages in your existing Asterisk setup.
Image result for asterisk

The main benefits of using realtime voice messages is as following:
  • Easy management of voice messages and voicemail greetings from centralized location i.e. database.
  • If there are multiple nodes of Asterisk serving as failing over or load balancing, then same voice messages and greetings will be available from every Asterisk node.
  • No syncing of voice messages and greetings will required for multiple Asterisk nodes.
  • Easy to remove old messages with just a single DB query.

Step # 1:

First of all enable odbc storage of voicemails from asterisk menuselect command.

# make menuselect 

Voicemail Build Options -> ODBC_Storage


# make && make install  

An asterisk service restart will be required after this change.

Step # 2:

Create following table in your MySQL database:

 CREATE TABLE `voicemessages` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`msgnum` int(11) NOT NULL DEFAULT '0',
`dir` varchar(80) DEFAULT '',
`context` varchar(80) DEFAULT '',
`macrocontext` varchar(80) DEFAULT '',
`callerid` varchar(40) DEFAULT '',
`origtime` varchar(40) DEFAULT '',
`duration` varchar(20) DEFAULT '',
`mailboxuser` varchar(80) DEFAULT '',
`mailboxcontext` varchar(80) DEFAULT '',
`recording` longblob,
`flag` varchar(128) DEFAULT '',
`msg_id` varchar(40) DEFAULT '',
PRIMARY KEY (`id`),
KEY `uniqueid` (`uniqueid`),
KEY `msg_id` (`msg_id`),
KEY `origtime` (`origtime`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Step # 3:

Secondly, add following DSN settings in odbc configurations (if not already added).

# /etc/odbc.ini 

[asteriskrvms]
Description = MySQL Asterisk Database
Driver = /usr/lib64/libmyodbc5.so
Server = <hostname>
User = <username>
Password = <username>
Database = asterisk
Port = 3306
Socket = /var/lib/mysql/mysql.sock

Step # 4:

Then, add relevant settings of DSN in ODBC resource configurations of asterisk.

# /etc/asterisk/res_odbc.conf

[voicemails]
enabled => yes
dsn => asteriskrvms
pre-connect => yes



$ asterisk -rx "module reload res_odbc.so"

Step # 5:

Then, add relevant settings of database table configurations in voicemail.conf of asterisk.

# /etc/asterisk/voicemail.conf

...

odbcstorage=voicemails
odbctable=voicemessage
...


$ asterisk -rx "voicemail reload"

Step # 6:

Following configurations will be required to redirect asterisk to enable logging voice messages in database.

# /etc/asterisk/extconfig.conf

[settings]

voicemessages =>odbc,
voicemails,voicemessages

$ asterisk -rx "core reload"