Topic Keywords: 2-way SMS
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:
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:firstname.lastname@example.org/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
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)...