Asterisk PBX SMS sending

Download: ngsms (perl script)

Asterisk is an open source IP PBX platform. With Ozeki NG SMS Gateway you can add SMS functionality to Asterisk PBX. Once you have Ozeki NG SMS Gateway installed, you can send voice mail notifications, fax notifications, missed call alerts and SMS text messages on various events. This SMS Gateway provides a much better option for SMS messaging then the built in SMS functionality of Asterisk. Ozeki NG SMS Gateway can use GSM Modem(s) attached to your server and IP SMS connections (SMPP, UCP, CIMD2, etc) to send the SMS messages.

How does it work?

To get the system working, you have to attach a GSM phone or GSM Modem to your PC with a phone-to-PC datacable (Figure 1.). This GSM phone will send the SMS messages. After the phone is attached, you need to install the Ozeki NG SMS Gateway software and configure the GSM Modem in it. Ozeki NG - SMS Gateway will be responsible for encoding the messages and for handling your phone. The next step is to install the ngSMS extension to Asterisk PBX. The ngSMS module can be downloaded on this webpage. It makes it possible for you to use the ngsms command in your asterisk configuration files.

asterisk integration with sms gateway
Figure 1 - Asterisk integration with SMS Gateway

The ngsms module and Ozeki NG - SMS Gateway can be located on two different computers. Often Ozeki NG and the GSM modem is installed on Windows XP and Asterisk PBX with ngsms is running on a Linux box. When the Asterisk PBX would like to send an SMS message, the ngsms module will perform an HTTP request to Windows XP machine running Ozeki NG - SMS Gateway and Ozeki NG will send the message through the attached GSM Modem.

How to use

In this example Asterisk runs on Ubuntu Linux and Ozeki NG SMS Gateway runs on Windows XP.

On Figure 3 you can see the IP address of the computer on which Ozeki NG SMS Gateway runs. The IP address is 192.168.91.211

ip adress of the computer which ozeki ng sms gateway runs on
Figure 3 - IP address of the computer where Ozeki NG SMS Gateway runs

Start Terminal on Ubuntu Linux (Figure 4).

start a terminal on ubuntu
Figure 4 - Start Terminal on Ubuntu

If Terminal is launched install Asterisk with the following command:

sudo apt-get install asterisk

install asterisk on ubuntu
Figure 5 - Install Asterisk

Create a directory with the name ozekisms with the following command:

mkdir ozekisms

create an ozekisms directory
Figure 6 - Create ozekisms directory

Enter ozekisms directory

with the following command:

cd ozekisms

enter the ozekisms directory
Figure 7 - Enter ozekisms directory

Download ngsms.tgz:

wget http://www.ozekisms.com/attachments/1/ngSMS.tgz

download ngsms.tgz
Figure 8 - Download ngsms.tgz

Extract the downloaded ngsms.tgz file:

tar -xzvf ngSMS.tgz

extract the downloaded file
Figure 9 - Extract the file

Enter ngsms directory:

cd ngSMS

enter the ngsms directory
Figure 10 - Enter ngsms directory

In ngsms directory extract the file:

tar -xzvf libwww-perl-5.805.tar.gz

extract the libwww-perl file
Figure 11 - Extract libwww-perl file

Enter libwww-perl directory:

cd libwww-perl-5.805

enter libwww-perl file which you just extracted
Figure 12 - Enter libwww-perl file

Type perl Makefile.PL (Figure 13):

perl Makefile.PL

perl makefile.pl
Figure 13 - Perl Makefile.PL

Type make (Figure 14):

make

make
Figure 14 - Make

Type make test (Figure 15):

make test

make test
Figure 15 - Make test

Type sudo make install (Figure 16). This command will compile and install libwww-perl file:

sudo make install

compile and install the libwww-perl
Figure 16 - Compile and install libwww-perl

Move up one directory:

cd ..

move up one directory
Figure 17 - Move up one directory

Extract asterisk-perl complement:

tar -xzvf asterisk-perl-0.10.tar.gz

extract the complement
Figure 18 - Extract the complement

Enter the extracted directory:

cd asterisk-perl-0.10

enter the extracted directory
Figure 19 - Enter the extracted directory

Type perl Makefile.PL (Figure 20):

perl Makefile.PL

perl makefile
Figure 20 - Perl Makefile.PL

Type make (Figure 21):

make

make command
Figure 21 - Make

Type make test (Figure 22):

make test

make test
Figure 22 - Make test

Compile and install Perl module for Asterisk (Figure 23):

sudo make install

compile and extract the file
Figure 23 - Compile and extract file

Move up one directory (Figure 24):

cd ..

move up one directory
Figure 24 - Move up one directory

Create agi-bin directory in /usr/share/asterisk directory (Figure 25):

sudo mkdir /usr/share/asterisk/agi-bin

create agi-bin directory
Figure 25 - Create agi-bin directory

Copy ngsms Perl script into the created agi-bin directory under the name of ngsms (Figure 26):

sudo cp ./ngsms /usr/share/asterisk/agi-bin/ngsms

copy the ngsms script
Figure 26 - Copy ngsms script

Open ngsms Perl script to edit (Figure 27):

sudo nano /usr/share/asterisk/agi-bin/ngsms

edit the ngsms perl script
Figure 27 - Edit ngsms Perl script

Specify the IP adress of the computer on which Ozeki NG SMS Gateway runs at $smsgateway line. In our example the IP address is: 192.168.91.211 (Figure 28).

define the ip address of the computer where ozeki ng sms gateway in installed
Figure 28 - Define the IP address of the computer where Ozeki NG SMS Gateway is installed

In our example there is a test_config directory on the desktop that contains an extensions.conf and users.conf file (Figure 29).

test config directory
Figure 29 - Test_config directory

In users.conf file there are two clients: oz850 and oz851 (Figure 30).

two clients are added
Figure 30 - Two clients are added

In our example there is a very basic rule defined: if client oz851 is called, ngsms module will be issued and instead of telephone calling, an SMS text message will be sent out (Figure 31):

exten => 850,1,Dial(SIP/oz850)
exten => 851,1,AGI(ngsms,+4412300000,This is a test message,+4412300012,,1)

the ng sms module
Figure 31 - Ngsms module

AGI(ngsms,+4412300000,This is a test message,+4412300012,,1)

In this format the parameters should be read as follows:

ngsms tells AGI to launch the ngsms script
+4412300000 is the recipient phone number
This is a test message is the message text. You can use variables in it.
+4412300012 is the sender phone number. This can be a number or an alphanumeric string.
  is the message type. This can be any of the messagetypes below. Since it is blank the message type will be text.
1 is the extra parameter. For example in a voicemail indication this should contain the number of messages in the mailbox.

Message types:

 For text messages you do not have to specify a messagetype
VOICEMAILON Sets a voicemail indication on the cellphone. The extra parameter contains the number of messages in the mailbox.
VOICEMAILOFF Clears a voicemail indication on the cellphone. The extra parameter should be set to 0.
FAXON Sets a fax indication on the cellphone. The extra parameter contains the number of messages in the mailbox.
FAXOFF Clears a fax indication on the cellphone. The extra parameter should be set to 0.
EMAILON Sets an email indication on the cellphone. The extra parameter contains the number of messages in the mailbox.
EMAILOFF Clears an email indication on the cellphone. The extra parameter should be set to 0.
VIDEOON Sets a video message indication on the cellphone. The extra parameter contains the number of messages in the mailbox.
VIDEOOFF Clears a video message indication on the cellphone. The extra parameter should be set to 0.
WEBLINK Sends a webpage URL to the phone. This webpage can be opened in the phone browser with a simple click. The extra parameter should contain the URL starting with http://
WEBBOOKMARK Sends a webpage bookmark to the phone. This webpage bookmark will be stored in the phone browser. The extra parameter should contain the URL starting with http://

Now extensions.conf file needs to be copied from test_config directory to /etc/asterisk directory (Figure 32):

sudo cp /home/ozeki/Desktop/test_config/extensions.conf /etc/asterisk/extensions.conf

copy extension.conf file
Figure 32 - Copy extensions.conf file

Now users.conf file also needs to be copied from test_config directory to /etc/asterisk directory (Figure 33):

sudo cp /home/ozeki/Desktop/test_config/users.conf /etc/asterisk/users.conf

copy users.conf file
Figure 33 - Copy users.conf file

Finally, Asterisk service needs to be restart (Figure 34):

sudo service asterisk restart

restart asterisk
Figure 34 - Restart Asterisk

I simulated a test call: I called oz851 client and ngsms module sends out the SMS message. You can see the sent message in Ozeki NG SMS Gateway on Figure 35.

Figure 35 - Sent message

Further utilization examples

exten=>115,55,AGI(ngsms|+4412300000|You have a voicemail from ${CALLERID}. Message was recorded at ${DATETIME}|+4412300012)

exten=>115,55,AGI(ngsms|+4412300000|You have ${VMCOUNT(100)} messages|+4412300012|VOICEMAILON|${VMCOUNT(100)})

exten=>115,55,AGI(ngsms|+4412300000|Clearing voicemail indication on phone|+4412300012|VOICEMAILOFF|0)

exten=>115,55,AGI(ngsms|+4412300000|Visit www.ozekisms.com!|+4412300012|WEBLINK|http://www.ozekisms.com)

exten=>115,55,AGI(ngsms|+4412300000|Bookmark www.ozekisms.com in your phone browser|+4412300012|WEBBOOKMARK|http://www.ozekisms.com)

How to set Voicemail indication on the cellphone

exten => 115,1,VoiceMail(${EXTEN})
exten => 115,55,AGI(ngsms|+4412300000|You have ${VMCOUNT(100)} messages|+4412300012|VOICEMAILON|${VMCOUNT(100)})
exten => 115,56,AGI(ngsms|+4412300000|You have a voicemail from ${CALLERID}. Message was recorded at ${DATETIME}|+4412300012)
exten => 115,57,Hangup

How to clear Voicemail indication

exten => 120,1,VoiceMailMain(${EXTEN})
exten => 120,55,AGI(ngsms|+4412300000|Clearing voicemail indication on phone|+4412300012|VOICEMAILOFF|0)
exten => 120,57,Hangup

Highlights

Integrates well with Asterisk AGI architecture!
Provides an in-house solution. There is no need to subscribe for a service!
Works with all wireless networks in the world!
High capacity. Up to 500 SMS/second (on IPSMS connections)
Support for local and international recipient number formats
Dynamic sender number or (alphanumeric string)
International (Unicode) characters can be used in text messages
Support for long (multipart) messages
Message Waiting Indication Support, to enable Voice mail waiting or Fax waiting indication on cellphones.

Download Asterisk SMS extension

ngSMS is a small module that you install on your Asterisk PBX. It is a Perl script that uses the AGI interface. This module makes it possible to use the ngSMS command in your configuration files to send text messages.

Download:

ngsms (perl script)

Prerequisites:
LWP::UserAgent
Asterisk::AGI

More information