The goal of this project is to provide a set of tools for processing and controlling the flow of short messages of different types in the Asterisk PBX. This suite can correctly route SMS-es and SIP instant messages and also resend them as a fax or voice messages to the non-messaging channels making it a ready-to-use solution for instant messaging of any kind.
This set of tools was created for SIP-configured Asterisk working on Linux system (especially Debian). It should work with PJSIP configurations, but I haven't tested it (it's yet to be done in my configuration). These tools might need some kind of fine tuning to work with PJSIP configurations properly.
Default configuration values (provided in configuration scripts and sms-process.sh
) assume that Asterisk and its directories are located in their default locations (/etc/asterisk
, /var/spool/asterisk
, etc.) and that there is a dedicated directory for all scripts at /etc/asterisk/scripts
.
This solution was created for Asterisk 16.28. However it should work with the newer versions. I haven't tested if these tools can work properly on systems other than Linux.
People often confuse SMS technology with SIP instant messaging. They are different protocols! SMS requires some kind of a central point (also called SMS Centre/SMS Centrum) which acts like a server which receive, store, process and resend Your messages (and, ideally, should keep Your messages for some time if the receiving end is offline). SIP messaging is much more automated and then looks more like a point-to-point service. It doesn't explicitly use such a thing like a SMS Centre. But it also doesn't mean Asterisk server have nothing to do here. However, this technology is less powerful than classic SMS service.
And, the most important thing - SMS Centre actually can work even on the classic landline technology (POTS) using FSK modulation (which is, in my opinion, such a great thing that it really works in Asterisk!) allowing You to use old analogue telephone with SMS support. In contrast, SIP messages can't as they are protocol based. I know no VoIP ATA that could turn this into the FSK SMS or something similar. There are probably IP phones supporting SIP messaging, but I don't know of any. The only ones I know and have used are software SIP clients like MicroSIP or Zoiper (both really good).
As this solution was prepared to be able to resend messages as faxes or voice calls, it needs to know what kind of service the recipient has activated. For this to work, it needs to have a simple table in a database with information about chosen service, phone number and Asterisk extension. There are at least three columns needed:
- Account -> varchar(100) - phone number
- Message -> varchar(1) - character indicating chosen service
- Extension -> varchar(100) - Asterisk extension (e.g. SIP/1000)
getChanInfo.py
was prepared to utilize MySQL database (using MySQL connector). If You need to use other database system, You have to change it in this script.
I've defined six indicators for services:
- S - normal SMS operation (SMS Centre)
- F - send message as a fax
- V - send message as a voice (make a voice call with text synthesis)
- C - simple command service (automated SMS reciver and answerer)
- T - SIP messaging operation
- N - no messaging at all (disable messaging feature for the chosen number)
These tools need some other packages and libraries to work. Here is the list (hope I remember everything):
- Asterisk (of course)
- smsq (should be part of the Asterisk package)
- pyst2 (Python Asterisk helper)
- Pillow (PIL)
- gTTS (simple Python voice synthesis helper utilizing Google Translate, as far as I know)
- paps
- ghostscript (gs)
- Imagemagick (convert)
- libtiff-tools (tiffset)
Default configurations provided here assume that Asterisk and other tools are in the specific locations. Here is the list:
/etc/asterisk
- main configuration directory for Asterisk/etc/asterisk/scripts
- additional directory for all scripts from this suite/var/spool/asterisk
- spool directory for Asterisk/var/spool/asterisk/sms
- SMS part of Asterisk's spool directory/var/spool/asterisk/sms/morx
- directory for received SMS-es/var/spool/asterisk/outgoing
- directory for.call
files (originating calls)/var/spool/T.38
- additional directory for faxes (don't have to be T.38 - I've used such name, because T.38 was first way of faxing in Asterisk I used; now I'm using audio stream but the name stayed the same ;))/var/spool/T.38/outgoing
- additional directory for TIFFs to be sent/var/spool/Voice
- additional directory for voice files/var/spool/Voice/outgoing
- additional directory for voice files to be played on call
Additional above means that those directories didn't exist previously in the installation.
They were created by me to make performing additional functions easier.
They are now used and necessary in this software (scripts
in the configurations, T.38
and Voice
in spool).
The main functionality is provided by extensions.conf
file and sms-process.sh
script.
Extensions file defines all needed extensions and some basic operations (I've uploaded part of mine describing how to use my tools) and the Bash script processes all SMS-es previously received by SMS Centre.
All other Python scripts are used to get information about channel and chosen service, to prepare other type of message (fax, voice synthesis, etc.) or to post SIP message, etc.
There is also one auxiliary script called cutter.py
which is used to automatically cut prepared fax page to help waste less paper on the receiving fax machine.
extensions.conf
- main part of the job, which still is in the Asterisk's extensions configurationsms-process.sh
- main SMS processor/router (also have some configuration variables inside, probably to be changed before use!)getChanInfo.py
- helper for gathering number information (chosen service, channel extension, etc.)smsToFax.py
- fax page and call creatorsmsToVoice.py
- voice synthesis and call creatorsmsCommand.py
- SMS commands processor (just an example to be extended to be something better)cutter.py
- cutting helper for making fax pages shorteragiGetChanInfo.py
- AGI wrapper forgetChanInfo.py
agiPostSMS.py
- AGI tool for posting SMS-es like they were received by SMS CentreamiSendSIPIM.py
- AMI tool for sending SIP instant messagessmsSuiteConfig.py
- simple configuration script for most of the toolssqlConfig.py
- simple configuration for SQL credentialsamiConfig.py
- simple configuration for AMI credentialsconcatenatedSMSSender.py
- helper for sending concatenated SMS-es (for messages longer than 160 characters)
In fact, only sms-process.sh
, agiGetChanInfo.py
and agiPostSMS.py
are explicitly seen as used (in extensions.conf
).
Use of other tools is automated (seen in sms-process.sh
or other scripts).
I've made much effort to provide here working code and solutions with hope they'll be useful and free from any bugs. However I can't guarantee anything. The software and solutions here are provided "AS IS" and I take no responsibility for anything. You're using them on Your own risk!
Free for personal use. You probably shouldn't use these solutions commercially (as they are not so good tested to be intended to). However, if You still like to anyway, please ask me before.
Bartłomiej "Magnetic-Fox" Węgrzyn, 20-24th September 2025