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?


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 '',
KEY `uniqueid` (`uniqueid`),
KEY `msg_id` (`msg_id`),
KEY `origtime` (`origtime`)

Step # 3:

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

# /etc/odbc.ini 

Description = MySQL Asterisk Database
Driver = /usr/lib64/
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

enabled => yes
dsn => asteriskrvms
pre-connect => yes

$ asterisk -rx "module reload"

Step # 5:

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

# /etc/asterisk/voicemail.conf



$ 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


voicemessages =>odbc,

$ asterisk -rx "core reload"

Add Custom Fields in Asterisk’s MySQL CDRs


This blog is to introduce some unique fields in Asterisk MySQL CDRs for identifying a call and asterisk instance.


Following are the steps required:

Step # 1

Introduce following columns in database table `cdr`:

  • ip_address
  • call_id
  • unique_identifier

ALTER TABLE `cdr` ADD `ip_address` VARCHAR(20) NULL;
ALTER TABLE `cdr` ADD `call_id` VARCHAR(200) NULL;
ALTER TABLE `cdr` ADD `unique_identifier` VARCHAR(100) NULL;

Step # 2

Add following section in asterisk file i.e. cdr_mysql.conf. It will enable the CDR() function to recognize custom fields included in asterisk MySQL CDRs.

ip_address = ip_address
call_id = call_id
unique_identifier = unique_identifier

Step # 3

Following is the dialplan (in file i.e. extensions.conf) to handle custom Asterisk MySQL CDRs.

exten => _X.,1,set(CDR(ip_address)=${SHELL(/sbin/ifconfig | /usr/bin/awk '/inet addr/{print substr($2,6)}' | /bin/grep -v '' | /usr/bin/head -n1):0:-1})
exten => _X.,n,set(CDR(call_id)=${SIPCALLID})
exten => _X.,n,set(CDR(unique_identifier)=${UNIQUEID})

Step # 4

You need to restart asterisk or following commands to apply such changes.

$ /usr/sbin/asterisk -rx "module reload"
$ /usr/sbin/asterisk -rx "dialplan reload" 


It is the simplest way to introduce some of custom fields with custom names in existing mysql cdrs of Asterisk.

ONES Phone Number API


  • These services are developed get updated details of phonenumbers.
  • The result is in JSON and valid-flag signifies whether phonenumber is valid or not i.e. 1 or 0 respectively.
  • Number can be provided in any format i.e. with spaces, characters etc.
  • Phonenumber’s Length must be within range of 4 to 20.
GitHub Repo: libphonenumber-api


Getting Phonenumber’s Information

Phone Number


Phonenumber’s Type

{"type": "FIXED_LINE_OR_MOBILE", "valid-flag": 1}

Phonenumber’s Country Code

{"countrycode": "45", "valid-flag": 1}

Phonenumber’s National Significant Number

{"nsn": "32160398", "valid-flag": 1}

Phonenumber’s Country’s ISO Code

ISO Code in 2 Alphabets

{"iso": "DK", "valid-flag": 1}

ISO Code in 3 Alphabets

{"iso": "DNK", "valid-flag": 1}

Phonenumber’s Regional Operator

{"operator": "Telenor", "valid-flag": 1}
Note: Operator’s Names are available in different languages with param i.e. operator-en, operator-fr, operator-it, operator-de.

Phonenumber’s Country

{"country": "Denmark", "valid-flag": 1}

Phonenumber’s Location

{"country": "Denmark", "valid-flag": 1}
Note: Location Names are available in different languages with param i.e. location-en, location-fr, location-it, location-de.

Phonenumber’s TimeZone

{"timezone": ["valid-flag": 1}

All details in JSON

 "phonenumber": "4532160398",
 "code": "45",
 "nsn": "32160398",
 "typeid": "FIXED_LINE_OR_MOBILE",
 "operator": "Telenor",
 "iso3": "DNK",
 "iso2": "DK",
 "country": "Denmark",
 "timezone": ["Europe/Copenhagen"]("Europe/Copenhagen"],),
 "is_validnumber": true,
 "is_validnumberforRegion": true,
 "is_possiblenumber": true

Phone Number FORMATs

E164 Format


Without E164 Format


National Format

32 16 03 98

International Format

+45 32 16 03 98

Verifying Phonenumber

{"valid-flag": 1}