2-Way SMS Returning a Non-Text Response

Posted by on Feb 7, 2003 in Support Blog

Topic Keywords:

It is a relatively simple process to define a 2-way command that returns a text response to the message sender. The “2-Way” page of the NowSMS configuration dialog allows you to define commands that are executed when an SMS message is received. The receipt of an inbound SMS message by the gateway can cause an executable command to be executed, or the gateway can connect to an HTTP URL to run a script on a separate web server. If “Command returns response text” is set for the command, it is simple for the command to return a text response back to the sender of the SMS. In the case of an HTTP URL, the HTTP URL can return a simple text response with a MIME type for the response set as “text/plain”, and the gateway will automatically send this text as a response back to the sender of the SMS.

In the example shown in the screen shot above, the receipt of a text SMS message causes the gateway to connect to the HTTP URL:

http://192.168.1.102/cgi-bin/sms.cgi?Sender=@@Sender@@&Text=@@FullSMS@@

When a message is processed, the “@@Sender@@” value is replaced with the phone number of the sender of the received message, and @@FullSMS@@ contains the complete text of the received message.

What if an HTTP script wants to return a response back to the sender that is a non-text SMS format, such as WAP OTA settings, a Nokia smart messaging message, or even an MMS message?

The HTTP script could always include its own processing logic to spawn a command that issues a request back to the NowSMS gateway, but this can be difficult. An alternative approach is for the HTTP response to return a “redirect” response, where the redirect URL is a URL pointer back to the NowSMS gateway, for example http://127.0.0.1:8800/?PhoneNumber=%2b12125551212&… (If you want to be able to test your HTTP script by executing it from a web browser, you will need to substitute the real IP address of your NowSMS server for the 127.0.0.1 address.)

If your NowSMS server requires authentication, a username and password can be included in the redirect response using the URL format http://user:password@server.name/path.

Any URL that would work when sent directly to the NowSMS server can be returned as a “redirect” response. If a script will be returning a “redirect” response, it is important that “Command returns response text” is NOT checked for the command on the “2-Way” configuration dialog. This is because a redirect response simply instructs the HTTP client to retrieve a different URL. The NowSMS gateway will not return the actual response from that URL request to the client.

An HTTP redirect response is an HTTP 302 response, with the redirect URL included in the “Location:” header, for example:

HTTP/1.0 302 Redirect
Location: http://127.0.0.1:8800/?PhoneNumber=…
<blank line>

Most scripting languages have built-in support for returning a redirect response. For example, in an ASP script, Response.Redirect (“http://127.0.0.1:8800/?PhoneNumber=…) is used to send a redirect response. Other scripting languages have similar support.

For comments and further discussion, please click here to visit the NowSMS Technical Forums (Discussion Board)...

2 Responses to “2-Way SMS Returning a Non-Text Response”

  1. Hi i really need help pleas for my fyp.

    i am developing a system that sends and receives sms.
    now i can send and receive the sms but the problem is when i receive an sms, there is infinite loop that inserted the sms into the inbox table in mysql database. i am using php language.
    this the last part of the code:

    }
    else
    $sms=”Sorry!+you+have+to+register+first+before+you+use+our+service”;
    $sql = “INSERT INTO inbox (sender_mobile, message_content, message_status, message_date) VALUES (‘$sender’, ‘$text’, ‘$mess_status’, ‘$mess_date’)” ;
    $res=mysql_query($sql);
    if($res){
    header(“Location:http://127.0.0.1:8800/?PhoneNumber=$sender&Text=$sms“);
    die();}

    • I’d suggest that you post your question with more detail in our discussion forum at http://www.nowsms.com/messages

      To understand your problem, we would probably need to see your SMSDEBUG.LOG. This would give us a better idea of what commands are being executed, and how your system is configured, so that we could tell you how to fix the loop.

      Head over to http://www.nowsms.com/messages and start a new thread.