SMS Menu / SMS IVR

This example shows you how you can use Ozeki NG SMS Gateway to create an SMS order system. This order system is a menu similar to the menu used in voice telephone systems (IVR menu). It works very simply, the mobile users sends in a message, then a system replies automatically. The mobile user can select a menu item by sending in a number.

Watch the following video:

Preparation

This service can be created using Ozeki NG SMS Gateway in a matter of minutes. The first step is to attach a GSM modem or GSM phone to your computer with a phone to PC data cable. (A list of supported GSM modems and phones can be found at http://www.ozekisms.com/index.php?owpn=148.) The next step is to download Ozeki NG SMS Gateway and to install it. Installation is simple. The Ozeki NG SMS Gateway will communicate with your GSM modem and will make sending and receiving SMS messages easy. After Ozeki NG has been installed, the GSM modem you have attached to your computer with a data cable should be setup. The SMS Quick Start Guide explains how this can be done. The final step is to test the functionality of your system, by sending and receiving a test message.

How to setup the SMS menu service

The solution uses the built in ASP script execution engine of Ozeki NG, so the setup requires you to install the ASP SMS user in the "Add user or application" screen (Figure 1). This screen can be brough up by clicking on the "Add user" menu item in the "Users and applications" menu.

install the asp user
Figure 1 - Install the ASP user

The next step is to assign a name for your service. For example you can specify "salesmenu" as the service name (Figure 2).

provide a unique name for your service
Figure 2 - Provide a unique name for your service

When you click Ok, the service will be created. On the service configuration form you need to disable the automatic response functionality by making sure the three checkboxes on the configuration form are NOT checked (Figure 3 and 4).

disable the automatic response functionality on general tab
Figure 3 - Disable the automatic response functionality on General tab

disable the automatic response functionality on service period tab
Figure 4 - Disable the automatic response functionality on Service period tab

After the checkboxes have been unchecked, click OK. The next step is to find out the path of the ASP script that will be executed when an SMS comes in. To get the location click on the script setup link in the left panel (Figure 5).

find the asp script location
Figure 5 - Find the ASP script location

When you have the path, use notepad to open this script for editing (Figure 6). Of course you may use any other text editor you like to modify the script.

use the notepad to edit your script
Figure 6 - Use notepad to edit the script

Source code

To create the SMS menu functionality copy the following source code into the sample.asp script. After you have copied this code, you need to save sample.asp and your service is ready to go.

C:\Program Files\Ozeki\OzekiNG - SMS Gateway\config\salesmenu\sample.asp

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

//************************************************************
//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"];

//************************************************************
//Create the menu
//************************************************************

Hashtable menuitems = new Hashtable();

//First level
menuitems.Add("0","1. New laptop\\0x0D\\0x0A2. Used laptop\\0x0D\\0x0A0. Main menu\\0x0D\\0x0A");

//Second level
menuitems.Add("01","1. IBM\\0x0D\\0x0A2. Dell\\0x0D\\0x0A3. Sony\\0x0D\\0x0A0. Main menu\\0x0D\\0x0A");
menuitems.Add("02","We are sorry, new used laptops are on stock at the momemnt.");

//Third level
menuitems.Add("011",
"1. IBM ThinkPad R61e 7650-DPG, USD 1000\\0x0D\\0x0A"+
"2. IBM ThinkPad X5 NF5DCHV, USD 1200\\0x0D\\0x0A"+
"0. Main menu");

menuitems.Add("012",
"DELL Inspiron 1525-97015,\\0x0D\\0x0A"+
"15.4 (1280x800) WXGA 16:9 GlareType,\\0x0D\\0x0A"+
"Intel Mobile Celeron 2000 MHz CPU,\\0x0D\\0x0A"+
"1024MB RAM,\\0x0D\\0x0A"+
"120GB HDD 5400RPM SATA\\0x0D\\0x0A"+
"Price: USD 1312\\0x0D\\0x0A"+
"Call dealer: +44555555\\0x0D\\0x0A");

menuitems.Add("013","No Sony laptops are available currently.");

//Forth level
menuitems.Add("0111","Call us for more information on IBM ThinkPad R61e. Tel: +44999999");
menuitems.Add("0112","Call us for more information on IBM ThinkPad X5. Tel: +44999999");

//************************************************************
//Process the incoming message
//************************************************************

string directory = @"C:\Program Files\Ozeki\OzekiNG - SMS Gateway\config\salesmenu\";
string filename = directory+sender+".txt";

string phonestate = "0";
//Read
if (File.Exists(filename)) {
   try {
       StreamReader sr = new StreamReader(filename);
           phonestate = sr.ReadToEnd().Trim();
           sr.Close();
   } catch {
       phonestate = "0";
   }
}

phonestate = phonestate+messagedata;

//************************************************************
//create the response message(s) in the following format:
//http://www.ozekisms.com/index.php?owpn=355
//************************************************************

string responsemessage = "";
string newstateforphone = "";

if (menuitems.Contains(phonestate)) {
    newstateforphone = phonestate;
        responsemessage = (string)menuitems[phonestate];
} else {
    newstateforphone = "0";
        responsemessage = (string)menuitems["0"];
}

string destnum = sender;
string resptype = "SMS:TEXT:FORMATTED";

string resp = "{"+resptype+"}{}{}{"+destnum+"}{"+responsemessage+"}";

Response.Write(resp);

//************************************************************
//save the state of the phone
//************************************************************
try {
    StreamWriter SW;
    SW=File.CreateText(filename);
    SW.WriteLine(newstateforphone);
    SW.Close();
} catch {
}

%>

More information