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 the smsSuiteConfig.py file) 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.
As far as I have seen, people often confuse SMS technology with SIP instant messaging. They are completely different protocols! SMS requires some kind of an explicit central point (also called SMS Centre/SMS Centrum) which acts like a server which receive, store, process and resend messages (and, ideally, should keep them 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 as it doesn't explicitly use such a thing like SMS Centre (but Asterisk still has to do processing internally). However, this technology is definitely less powerful than classic SMS service.
And, the most important thing - SMS Centre actually can work even on the classic landline telephony (POTS) using FSK modulation (which is, in my opinion, such a great thing that it really works in Asterisk!) allowing You to use an old analogue phone with SMS support with it. 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 is responsible for gathering this information and relay it to other scripts. It 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 - delivering messages as faxes
- V - delivering messages as a voice synthesis
- C - being simple command service (automated SMS reciver and answerer)
- T - SIP messaging operation
- N - no messaging at all (disable messaging delivery 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; for AGI and AMI)
- Pillow (PIL)
- gTTS (simple Python voice synthesis helper utilizing Google Translate)
- MySQL Connector for Python (mysql.connector)
- paps
- ghostscript (gs)
- Imagemagick (convert)
- libtiff-tools (tiffset)
- FFmpeg (ffmpeg)
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.callfiles (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) unless You decide to place things another way (everything can be configured via smsSuiteConfig.py file).
The main functionality is provided by extensions.conf file and smsProcess.py script.
Extensions file define all needed extensions and some basic operations (I've uploaded part of mine describing how to use my tools) and the Python script processes all SMS-es received by SMS Centre (also these received before which weren't processed and remains in the morx directory).
All other scripts are just tools used by the main script to get information about channel and chosen service, prepare other type of message (fax, voice synthesis, etc.) or to post SIP message, etc.
extensions.conf- configuration file for Asterisk, which still does main part of the job (it's calledextensions.conf.partin this repository, because it's only a part here)smsProcess.py- main SMS processor/routergetChanInfo.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 shorter (from Mail2Fax project)agiGetChanInfo.py- AGI wrapper forgetChanInfo.pyagiPostSMS.py- AGI tool for posting SMS-es like they were received by SMS Centre (for routing SIP messages to SMS)amiSendSIPIM.py- AMI tool for sending SIP instant messages (for routing SMS-es to SIP messages)concatenatedSMSSender.py- helper for sending concatenated SMS-es (for messages longer than 160 characters)callFileGenerator.py- helper for creating call filestiffTools.py- helper for text-to-TIFF conversion, resizing and applying resolution information to the TIFF files (also from Mail2Fax project)voiceTools.py- helper for voice synthesis and converting audio files to 8000 Hz WAVEsmsTools.py- helper for sending SMS-es and gathering data from message filessuiteLogger.py- project-specific helper for easy warnings and errors loggingsmsSuiteConfig.py- configuration file for all toolssqlConfig.py- configuration file for SQL credentialsamiConfig.py- configuration file for AMI credentials
In fact, only smsProcess.py, agiGetChanInfo.py and agiPostSMS.py are explicitly seen as used (in extensions.conf).
Use of other tools is automated (seen in smsProcess.py 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, April 17, 2025 - November 26, 2025