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"

Add Custom Fields in Asterisk’s MySQL CDRs


Introduction

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

Methodology

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.

[aliases]
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.

[default-context]
exten => _X.,1,set(CDR(ip_address)=${SHELL(/sbin/ifconfig | /usr/bin/awk '/inet addr/{print substr($2,6)}' | /bin/grep -v '127.0.0.1' | /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 cdr_mysql.so"
$ /usr/sbin/asterisk -rx "dialplan reload" 

Conclusion:

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

ONES Phone Number API


Introduction

  • 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

Services


Getting Phonenumber’s Information


Phone Number



4532160398

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



+4532160398

Without E164 Format



4532160398

National Format



32 16 03 98

International Format



+45 32 16 03 98

Verifying Phonenumber



{"valid-flag": 1}