Easy Guardian provides alarms by texting system administrators
If you would like to monitor you server 24h/24h this is the right tool for you! It brings together NMAP and Net-SNMP in a small silent Linux embedded box.  Visit: http://www.easyguardian.com
FoxBox arrow Software Manual arrow Extra: Custom actions
English
Custom action on SMS PDF Print E-mail

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 FoxBox.

There are two ways to access events inside the interface:

  1. Custom Application
  2. Event Handler

Case 1: The Custom Applications Forms

To access this area click on the "Custom Application" button in the web interface menu. In this window you will have two forms, the first is related to RECEIVED-items event and the second is related to SENT-items event.

Now it's 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 our SMS FoxBox typing into the text a CODE, and we want to answer to the winner with an SMS notification.

Analysis of the problem:

To create this application we need to control the text of each incoming message, in case that's the message with the winning code we need to extract the phone number of the winner and send an SMS with the notification to the From number extracted.

This is a shell script that performs all this actions:

#!/bin/sh
#
#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
SEARCH="123456"
#
#Text message that we want to send
TEXT="You WIN!"
#
#
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
fi

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 inside: 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 proceeded 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 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? It's 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 FoxBox performs 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 things.

To activate or deactivate functionalities you need only to comment or uncomment 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 (http://www.kdev.it), a Davide Cantaluppi company on Acme Systems FOX GM Hardware

 
< Prev   Next >

buy foxbox
buy on FoxBox eShop



For further info contact us by mail This e-mail address is being protected from spam bots, you need JavaScript enabled to view it providing us the FoxBox model you need and your company details.

KDEV di Davide Cantaluppi, P.IVA 02984320131

http://www.kdev.it