How to perform custom actions on incoming or outgoing SMS messages

Thanks to the Event Handler interface you can link actions on each SMS received or transmitted

The main purpose of the Event Handler is allow you to create custom applications and fully customize the functionalities of your SMS Fox Box.

There are two ways to access events inside the interface:

  1. 1- Custom Application
  2. 2- Event Handler

Case 1: The Custom Applications Forms

To access this area click on the button on the left menu.

In this window you have two forms, the first is linked to on RECEIVED items event and the second is linked to on SENDED items event.

Now is time to proceed with a practical example, we would like to create a game, a little example of Lottery.

We would like that people send SMS messages to the number of SMS FoxBox typing in the text a CODE,

and we want to answer to the winner with a SMS notification.

Analysis of the problem:

To create this application we need to control the text of each incoming message,

in case of the message with the winning code we need to extract the phone number of the winner and send

a SMS with the notification to the From number extracted.

This is a shell script that perform all this actions:

#This is a sample script for custom RX action
#PURPOSE: The script search a code inside a incoming message and if the code is matched reply
#with the messahe "You WIN!"
#Search the code 1223456 inside the SMS message
#CODE that we want to search
#Text message that we want to send
CODE=`/bin/cat $1 | grep "$SEARCH"`
#if code is not empty reply with the message "You WIN!"
if [ "$CODE" == "$SEARCH" ]; then
#I need to extract the phone number to send the reply
NUMB=`/bin/cat $1 | /bin/grep "From:" | awk '{print $2}'`
#Now I generate the file for outgoing queue
FILE=`/bin/mktemp /mnt/flash/spool/outgoing/send_XXXXXX`
echo "To: $NUMB" >> $FILE
echo "" >> $FILE
echo "$TEXT" >> $FILE

To try this script, copy it and paste it inside the form "Custom application applied to received items".

Then send a message with this CODE: 123456 and you will WIN! :-)

As you can see in this example, we have created a little parser using `/bin/cat $1 | grep "$SEARCH"` this means

list the content of $1 (that is the full path to the received message) and match if it contains the pattern $SEARCH (the winner code).

Then we extract the phone number of the winner with:

`/bin/cat $1 | /bin/grep "From:" | awk '{print $2}'`
this means list the content of $1 search the pattern "From:" and take the number using awk {print $2} (column 2).

At the end we proceed generating the notification message. The code below will create a file with this content, the destination To: (previous extracted number) a blank line and the the text of the notification.

FILE=`/bin/mktemp /mnt/flash/spool/outgoing/send_XXXXXX`
echo "To: $NUMB" >> $FILE
echo "" >> $FILE
echo "$TEXT" >> $FILE
The variable $1 contains the full PATH to the message, and what is the format of the message in this file? Is simply this !
From: Kanta
To: 491721234567
Alphabet: ISO
Text of the message:
The messages format is fully explained in this article: SMS Fox Box File Format

Case 2: The Event Handler Form

To access this area click on the button on the left menu. In this window you have an already filled form:

From here, you have full control on all actions that SMS Fox Box perform for receiving or sending a message. You can assign different meanings to LEDS, disable incoming messages or disable outgoing messages and a lot of other process.

To activate or deactivate functionalities you need only to uncomment or comment the little blocks enclosed between (# sharp symbol)

In the figure I have highlighted the block that calls custom scripts on incoming messages, uncommenting it as shown below you will activate the custom form of the case 1:

As you can see, in this if clause the RECEIVED event is selected. The events you can select are: SENT, RECEIVED, FAILED or REPORT
You have to keep in mind, that you need to pass arguments to the script you want to lauch:

Arguments you can pass are:

  • $1 Is the event identification and should be SENT, RECEIVED, FAILED or REPORT
  • $2 Is the full path to the SMS file
  • $3 is the message id of the SENT message, it is only used if you sent a message successfully with status report enabled.

The SMS FoxBox Software is developed by KDEV (, a Davide Cantaluppi company on Acme Systems FOX GM Hardware