Eventhandler call on received messagesThe FoxBox messaging system is designed to allow you to customize all the internal scripts. As discussed in the "How to integrate foxbox to your server environment" foxbox message processing is based on events. Below is reported an example of eventhandler, the locate the incoming script (red section):
#!/bin/sh #SCRIPT: Event handler SMS #AUTHOR: Davide Cantaluppi
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
#DATE: 28.02.06 #REV: 1 #PLATFORM: Not platform dependent #PURPOSE: Handle event linked to smsd daemon # #Usefull Variables are # # $1 # $2 # $3 # #Values associated to these variables are # # $1 is the type of the event wich can be SENT, RECEIVED, FAILED or REPORT. # $2 is the filename of the sms. # $3 is the message id. Only used for SENT messages with status report. # #BEGIN SCRIPT # # TURN ON LED OG29 ON RECEIVED MESSAGE #if [ "$1" = "RECEIVED" ]; then # #/etc/sms/scripts/led29 #fi # # TURN ON OG 29 ON SENT MESSAGE #if [ "$1" = "SENT" ]; then #/etc/sms/scripts/led29 #fi #
#NEVER DISABLE THE FOLLOWING SCRIPT FOR MESSAGE RECEIVING if [ "$1" = "RECEIVED" ]; then /etc/sms/scripts/parser.php fi
# # #NEVER DISABLE THE FOLLOWING SCRIPT FOR MESSAGE OUTGOING if [ "$1" = "SENT" ]; then # /etc/sms/scripts/out.php fi # #Save messages in XML format #if [ "$1" = "RECEIVED" ]; then #/etc/sms/scripts/sms2xml $1 $2 $3 #fi #SEND EMAIL USING MAILSEND SCRIPT ON SMS RECEIVED # #if [ "$1" = "RECEIVED" ]; then # Use this to test # /etc/mailsend/mailsend -d kdev.it -smtp www.kdev.it -t
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
-f
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
+c +b -sub "New SMS received" -m "$2" # #/etc/mailsend/smstomail "$2" "$1" #fi #this is the database mysql backend #if [ "$1" = "RECEIVED" ]; then #/etc/sms/scripts/mysmsd "$1" "$2" "$3" #fi #This is the custom script written by user for RX action # #Enable this to activate custom events # #if [ "$1" = "RECEIVED" ]; then #/mnt/flash/root/source/custom/custom_rx "$2" #fi #source='/mnt/flash/root/conf/smtp.conf' # #Event on sent message #if [ "$1" = "SENT" ]; then # Use this to test # /etc/mailsend/mailsend -d kdev.it -smtp www.kdev.it -t
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
-f
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
+c +b -sub "New SMS sent" -m "$2" # #/etc/mailsend/smstomail "$2" "$1" #fi #This is the custom script written by user for TX action #if [ "$1" = "SENT" ]; then #/mnt/flash/root/source/custom/custom_tx "$2" #fi # #Event on failed message #if [ "$1" = "FAILED" ]; then #this send the failed message to a mail address #/etc/mailsend/smsfailmail "$2" "$1" #fi ADD THE POST FUNCTION TO THE PARSER The script /etc/sms/scripts/parser.php is executed each time a message is received by the appliance. To automatically post to a webservice SMS incoming data simply you have to add a little PHP function to the parser specifying the URL of your webservice.
#!/bin/php function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } CALLING THE POST FUNCTION AND PASSING DATA Now all you have to do is to create the call to the function passing the parameter you need for example: The sender, the text received and the date/time of reception:
$urlp= 'http://your.url.xxx/webservice.xxx'; $parametri='PHONE='.urlencode($nmit).'&smsTEXT='.urlencode($testo).'&smsDATE='.urlencode($ricevuto); $response = do_post_request($urlp, $parametri);
Put the code into parser before the line // defualt queue population (should be line 135 in the default parser)
A WEBSERVICE EXAMPLE ON YOUR SERVEROn your webserver probably you'll have to create a PHP page like this:
<? $sender=$_REQUEST[' PHONE']; $text=$_REQUEST['smsTEXT']; $deldate=$_REQUEST['smsDATE']; $db = mysql_connect("localhost", "dbuser", "password"); if ($db == FALSE) die ("Error cannot connect to MYSQL"); mysql_select_db("SMS", $db); $query = mysql_query("insert into incoming values ('','$sender','$text', '$deldate'")"); ?>
You can apply the post to each event, for example to outgoing messages or failed. You can also use it with every webservice, PHP, ASP, JSP etc...
|