Information service menu via SMS

This example shows you how you can use Ozeki NG SMS Gateway to create an SMS information menu. The SMS information menu is based on an automatic response system and works similarly as games and other service menus. It works very simply, the mobile users send messages including certain characters (numbers or letters) to a specified phone number and the system replies automatically. The mobile user can select a menu item by sending in another character. In this guide, you can read about the neccessary configuration to start your own SMS information menu.

Download: sms-information-menu.zip (2 KB)

Introduction

This solution is a simple, fast and automatized way to share information with customers. The character sent by the customer generates a constant reply which contains the needed information. All you have to do is to provide the characters or words the customer can select from and to configure your system.

How to configure your system

To launch SMS information menu via SMS text messages you need to build your own SMS system. To do so download and install Ozeki NG SMS Gateway to your computer. This software product will ensure SMS functionality and operate your SMS system. After the installation you can start to receive SMS messages from mobiles to your PC and send response messages from PC to mobiles.

The SMS Gateway forwards SMS messages to the mobile network in two possible ways. One of the possibilities is GSM modem connection, it means that one or more GSM modems are attached to the PC with a datacable and the gateway operates them. Or the SMS gateway connects directly to the SMS center of a mobile service provider over the Internet. It is called IP SMS connection.

Description of the solution

If a customer sends a message containing the chosen menu number to a predefined phone number, he will receive a welcome response message containing the description of the SMS information menu. In the response message two letters "i" and "e" are mentioned from which the customer can choose. Further information and options belong to each letter, from which the customer send back the one, he wants to get response message of. The guide below provides a detailed description of the system.

System architecture

After you built your SMS system it will work as follows: A customer sends an empty message to you. Ozeki NG SMS Gateway processes this message and its ASP user will check the phone number and its state in the database. The response to the message is determined by the state of the mobile phone. Figure 1 demonstrates this process.

sms information menu
Step 1 - Configure MySQL database

Step 1 - Configure MySQL database

First you need to download and extracted sms_information_menu.zip file to your computer.

Open MySQL Command Line Client, log in with your password and create a table using the below script for sms information. Select the contents of the below and copy it into the MySQL Command Line Client. (Figure 2)

Step 2 - Create table script for MySQL

CREATE TABLE `numbers` (
  `id` int(11) NOT NULL auto_increment,
  `phonenum` varchar(50) NOT NULL,
  `state` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
)  DEFAULT CHARSET=utf8;
 

mysql command line
Figure 2 - MySQL Command Line

Step 3 - Setup Ozeki NG

The downloaded "sms_information_menu.zip" file contains an ASPX file named "sms_information_menu.aspx". Open this file and search the line containing the connection string and customize it. Below you can see an example of customized connection string.

Connection string

Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;
Database=MyInformation;User=root;Password=qwe123;Option=4;

Below you can see the source code of the "sms_information_menu.aspx" file.

<%@ Page Language="C#"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.Odbc" %>

<%

//************************************************************
//copy the properties of the incoming SMS into local variables
//************************************************************

string sender = Request.QueryString["sender"];
string receiver = Request.QueryString["receiver"];
string messagedata = Request.QueryString["messagedata"];
string messageid = Request.QueryString["messageid"];
string messagetype = Request.QueryString["messagetype"];
string senttime = Request.QueryString["senttime"];
string receivedtime = Request.QueryString["receivedtime"];
string serviceprovider = Request.QueryString["operatornames"];

string respmsg = "";

//************************************************************
//Create the responses for the messages
//************************************************************    

    //response message for the empty messagedata
        string RespForEmpty = "Welcome to the SMS information menu. If you want to receive 
information about the import possibilities, send the character 'i', if you want to receive 
information about export possibilities, send character 'e'";
    
        //response messages for letter 'i'
        Dictionary RespForI =
                new Dictionary();
        RespForI.Add("i", "1.public import \0x0D\0x0A2.cargo \0x0D\0x0A3.manifest \0x0D\0x0A
4.temp import \0x0D\0x0A5.warehouse \0x0D\0x0A6.re-import");
    
        RespForI.Add("i1", "1.public import1 \0x0D\0x0A2.public import2 \0x0D\0x0A
3.public import3 \0x0D\0x0A4.public import4 \0x0D\0x0A5.public import5  \0x0D\0x0A
6.public import6 \0x0D\0x0A");
        RespForI.Add("i2", "2.cargo1 \0x0D\0x0A3.cargo2 \0x0D\0x0A4.cargo3 \0x0D\0x0A
4.cargo4 \0x0D\0x0A5.cargo5 \0x0D\0x0A6.cargo6 \0x0D\0x0A");
        RespForI.Add("i3", "1.manifest1 \0x0D\0x0A2.manifest2 \0x0D\0x0A
3.manifest3 \0x0D\0x0A4.manifest4 \0x0D\0x0A5.manifest5 \0x0D\0x0A6.manifest6 \0x0D\0x0A");
        RespForI.Add("i4", "1.temp import1 \0x0D\0x0A2.temp import2 \0x0D\0x0A
3.temp import3 \0x0D\0x0A4.temp import4 \0x0D\0x0A5.temp import5 
\0x0D\0x0A6.temp import6 \0x0D\0x0A");
        RespForI.Add("i5", "1.warehouse1 \0x0D\0x0A2.warehouse2 \0x0D\0x0A
3.warehouse3 \0x0D\0x0A
4.warehouse4 \0x0D\0x0A5.warehouse5 \0x0D\0x0A6.warehouse6 \0x0D\0x0A");
        RespForI.Add("i6", "1.re-import1 \0x0D\0x0A2.re-import2 \0x0D\0x0A3.re-import3 \0x0D\0x0A
4.re-import4 \0x0D\0x0A5.re-import5 \0x0D\0x0A6.re-import6 \0x0D\0x0A");

        //response messages for letter 'e'
        Dictionary RespForE =
                new Dictionary();
        RespForE.Add("e", "1.public export. \0x0D\0x0A2.cargo \0x0D\0x0A3.re-export \0x0D\0x0A4.temp re-export \0x0D\0x0A5.export manifest 
\0x0D\0x0A6.countries");
    
        RespForE.Add("e1", "1.public export1 \0x0D\0x0A2.public export2 \0x0D
\0x0A3.public export3 \0x0D\0x0A4.public export4 \0x0D
\0x0A5.public export5 \0x0D\0x0A6.public 
export6 \0x0D\0x0A");
        RespForE.Add("e2", "1.cargo1 \0x0D\0x0A2.cargo2 \0x0D\0x0A3.cargo3 \0x0D
\0x0A4.cargo4 \0x0D\0x0A5.cargo5 \0x0D\0x0A.6cargo6 \0x0D\0x0A");
        RespForE.Add("e3", "1.re-export1 \0x0D\0x0A2.re-export2 \0x0D\0x0A3.re-export3 
\0x0D\0x0A4.re-export4 \0x0D\0x0A5.re-export5 \0x0D\0x0A6.re-export6 \0x0D\0x0A");
        RespForE.Add("e4", "1.temp re-export1 \0x0D\0x0A2.temp re-export2 \0x0D
\0x0A3.temp re-export3 \0x0D\0x0A4.temp re-export4 \0x0D
\0x0A5.temp re-export5 \0x0D\0x0A6.temp 
re-export6 \0x0D\0x0A");
        RespForE.Add("e5", "1.export manifest1 \0x0D\0x0A2.export manifest2 \0x0D
\0x0A3.export manifest3 \0x0D\0x0A4.export manifest4 \0x0D\0x0A
5.export manifest5 \0x0D\0x0A6.export manifest6 \0x0D\0x0A");
        RespForE.Add("e6", "1.countries1 \0x0D\0x0A2.countries2 \0x0D\0x0A3.countries3 
\0x0D\0x0A4.countries4 \0x0D\0x0A5.countries5 \0x0D\0x0A6.countries6 \0x0D\0x0A");

        
//************************************************************
//Respond to the messages
//************************************************************    
        if (messagedata.Equals(""))
        {
            Response.Write("{SMS:TEXT:FORMATTED}{}{}{" + sender + "}
{" + RespForEmpty + "}");
            
        }
        else
        {
            string phonestate = messagedata.Trim().ToLowerInvariant();
            string getPhoneState = "select `state` from 
`numbers` where `phonenum` = '" + sender + "'";
            
            try
            {
                string connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;
Database=MyInformation;User=root;Password=qwe123;Option=4;";
                OdbcConnection oc = new OdbcConnection(connectionString);
                oc.Open();
                try
                {

                    try
                    {
                        string sqlresp = "";
                        OdbcCommand command = new OdbcCommand(getPhoneState, oc);
                        OdbcDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            sqlresp = reader.GetString(0);
                        }
                        reader.Close();

                        //if the phone number is not yet stored, 
inserting it into the database
                        if (sqlresp == "")
                        {
                            string insertSQL = 
"insert into `numbers` (`phonenum`, `state`) values  ('" + sender + "','" + phonestate + "');";
                            OdbcCommand storephonenum = new OdbcCommand(insertSQL, oc);
                            storephonenum.ExecuteNonQuery();
                        }
                            //if the phone number is stored 
in the datbase, modifying its phone state to  according the current messagedata
                            //and updating the corresponding record in the database
                        else 
                        {
                            if (!(phonestate.EndsWith("i")
 || phonestate.EndsWith("e")))
                            {
                                phonestate = sqlresp + phonestate;
                                string updateSQL = 
"update `numbers` set `state`= '"  + phonestate + "' where `phonenum` = '" + sender + "';";
                                OdbcCommand updatephonestate = new OdbcCommand(updateSQL, oc);
                                updatephonestate.ExecuteNonQuery();
                            }
                            else
                            {
                                string updateSQL = 
"update `numbers` set `state`= '"  + phonestate + "' where `phonenum` = '" + sender + "';";
                                OdbcCommand updatephonestate = new OdbcCommand(updateSQL, oc);
                                updatephonestate.ExecuteNonQuery();
                            }
                            
                        }
                        
                        oc.Close();
                    }
                    catch (Exception z)
                    {
                        string errCode = z.Message;
                        Response.Write(errCode);
                    }

                }
                catch (Exception z)
                {
                    string errCode = z.Message;
                    Response.Write(errCode);
                }
            }
            catch (Exception z)
            {
                string errCode = z.Message;
                Response.Write(errCode);
            }
            
            //setting up the response messages for the recipient
            if (phonestate.StartsWith("i"))
            {
                respmsg = RespForI[phonestate];
            }

            if (phonestate.StartsWith("e"))
            {
                respmsg = RespForE[phonestate];
            }
            string respsms = "{SMS:TEXT:FORMATTED}{}{}{" + sender + "}
{" + respmsg + "}";
            Response.Write(respsms);
        }
        
%>

You can customize the responses by modifying the following variables:

  • RespForEmpty: this variable contains the response message for an empty message. In this example it is a description for the menu.
  • RespForI: this variable contains the response message for a message containing the letter "i".
  • RespForE: this variable contains the response message for a message containing the letter "e".

The "RespForI" and "RespForE" variables determines response messages for the chosen sub-menus (for example: "e4"). You can customize these response messages as well or you can add further sub-menus (for example: "e41").

After you customized the ASPX file, start Ozeki NG SMS Gateway and login with your username and password and create an ASP user. To do so click on "Add users and applications" and select "ASP" user in the list and click on "Install". Give the access path of sms_information_menu.aspx file in the ASP user's configuration form as in Figure 3.

asp script file
Figure 3 - ASP script file

After configuration, your system is ready to use the SMS Information Menu.

Step 4 - Testing the system

First time I simulate an incoming message which message data is empty. You can see the response message to the empty message in Figure 4, as described in the "RespForEmpty" variable.

response to empty sms
Figure 4 - Response to empty SMS

In Figure 5 you can see the response message for letter "i", as described in the "RespForI" variable's "i" keyword:

response to i
Figure 5 - Response to "i"

If I send the number "3" I will get the response for number "3" at the "i" menu, as described in the "RespForI" variable's "i3" keyword:

response to i3
Figure 6 - Response to "i3"

In Figure 7 you can see the response message for letter "e", as described in the "RespForE" variable's "e" keyword:

response to e
Figure 7 - Response to "e"

If I send the number "4" I will get the response for number "4" at the "e" menu, as described in the "RespForE" variable's "e4" keyword:

response to e4
Figure 8 -Response to "e4"

More information

  • Autoreply voucher example
  • Email to SMS feature
  • Email to SMS alert
  • E-mail to SMS, SMTP Server configuration
  • Reminder example
  • SMS PIN code query
  • Bulk SMS Client
  • Sending e-mail alert SMS messages
  • Bulk SMS to a given phone number range
  • 2 way SMS to Email gateway
  • SMS Service Provider Connectivity
  • Users and SMS Applications