Gammu SMSD can be configured by RunOnReceive directive (see SMSD Configuration File for details) to run defined program after receiving message.
This parameter is executed through shell, so you might need to escape some special characters and you can include any number of parameters. Additionally parameters with identifiers of received messages are appended to the command line. The identifiers depend on used service backend, typically it is ID of inserted row for database backends or file name for file based backends.
Gammu SMSD waits for the script to terminate. If you make some time consuming there, it will make SMSD not receive new messages. However to limit breakage from this situation, the waiting time is limited to two minutes. After this time SMSD will continue in normal operation and might execute your script again.
program is executed with environment which contains lot of information about the message. You can use it together with NULL service (see Null Backend) to implement completely own processing of messages.
Number of physical messages received.
Number of decoded message parts.
The variables further described as SMS_1_... are generated for each physical message, where 1 is replaced by current number of message.
Class of message.
Sender number.
Message text. Text is not available for 8-bit binary messages.
The variables further described as DECODED_1_... are generated for each message part, where 1 is replaced by current number of part. Set are only those variables whose content is present in the message.
Decoded long message text.
Sender of MMS indication message.
title of MMS indication message.
Address (URL) of MMS from MMS indication message.
Size of MMS as specified in MMS indication message.
To activate this feature you need to set RunOnReceive in the SMSD Configuration File.
[smsd]
RunOnReceive = /path/to/script.sh
Following script (if used as RunOnReceive handler) passes message data to other program. This works only with the Files backend.
#!/bin/sh
INBOX=/path/to/smsd/inbox
PROGRAM=/bin/cat
for ID in "$@" ; do
$PROGRAM < $INBOX/$ID
done
Following script (if used as RunOnReceive handler) passes message text and sender to external program.
#!/bin/sh
PROGRAM=/bin/echo
for i in `seq $SMS_MESSAGES` ; do
eval "$PROGRAM \"\${SMS_${i}_NUMBER}\" \"\${SMS_${i}_TEXT}\""
done
Following script (if used as RunOnReceive handler) will write information about each received MMS indication to the log file. Just replace echo command with your own program to do custom processing.
#!/bin/sh
if [ $DECODED_PARTS -eq 0 ] ; then
# No decoded parts, nothing to process
exit
fi
if [ "$DECODED_1_MMS_ADDRESS" ] ; then
echo "$DECODED_1_MMS_ADDRESS" "$DECODED_1_MMS_SENDER" "$DECODED_1_MMS_TITLE" >> /tmp/smsd-mms.log
fi
Following script (if used as RunOnReceive handler) written in Python will concatenate all text from received message:
#!/usr/bin/python
import os
import sys
numparts = int(os.environ['DECODED_PARTS'])
# Are there any decoded parts?
if numparts == 0:
print('No decoded parts!')
sys.exit(1)
# Get all text parts
text = ''
for i in range(1, numparts + 1):
varname = 'DECODED_%d_TEXT' % i
if varname in os.environ:
text = text + os.environ[varname]
# Do something with the text
print('Number %s have sent text: %s' % (os.environ['SMS_1_NUMBER'], text))