Integrate SMS in your web application using TextMarks, Part 2

Posted by Matt Thommes on January 3, 2008

Previously, we overviewed how SMS can be used to access or manage web applications. Using the TextMarks API, we are able to send and receive text messages right from our own code. This article will explain more specifically how you can interact with TextMarks.

First, you need to create a unique TextMarks keyword. This keyword will be used to tell TextMarks how you want to proceed when someone sends a text message containing that keyword. A couple examples of how TextMarks allows you to proceed:

  1. Respond with a default text message.
  2. Respond with text from a web page.

Respond with a default text message

If you have a basic need for SMS responses, you could choose #1, which allows you to include a custom text response anytime someone sends a text message with your keyword. To maintain the content of the text response, you simply log into the TextMarks web page, and there you can manage your keyword account. You can change the SMS response at any time.

Screenshot of TextMarks.com

Using a default text message allows you plenty of creative freedom to adapt your response to changing events. For example, let's say you're coordinating a paintball outing, and you'd like to use SMS as a way to inform participants of the event information.

Perhaps your keyword is paintballguys.

Interested parties simply text the keyword "paintballguys" to 41411, and they'll immediately receive a response text message - the content of which you, as the owner of the keyword, maintain.

Screenshot of TextMarks.com

Your initial response could be:

New outing scheduled for Saturday the 19th. 9 AM. Text back tomorrow for more info.

Think of it as a way for interested parties to remain informed while on the go.

Respond with text from a web page

Responding with a default text message is nice and simple, but the true power lies in using an existing web page to dynamically send responses, or even update your own database!

By choosing option #2, Respond with text from a web page, you are allowed to provide a single URL, which could point to your external application. When a user sends a text message with your keyword, TextMarks will send the message to your web app, where you can perform whatever action needs to be done, and send back a custom response.

Screenshot of TextMarks.com

For example, let's use paintballguys as our keyword again.

Here's a text message that users could send, to retrieve dynamic information:

paintballguys 1/2/08

Here we precede the entire message with the unique keyword, "paintballguys," then we append our query, "1/2/08." The query is used to ask our own database for some information (for example, send me back the results from Jan 2, 2008). When someone sends this text message to TextMarks, our custom URL will be requested, with certain variables appended:

http://mydomain.com/api/textmarks.php?user=\p&req0=\0& req1=\1&req2=\2

Above is an example URL we could supply to TextMarks, which is invoked whenever someone texts our keyword, "paintballguys." Specifically, pay attention to this part:

?user=\p&req0=\0&req1=\1&req2=\2

When our application is sent this URL, the above variables can be obtained. Here's an example using PHP to obtain the values of these variables:

<?php

    // ASSIGN VARIABLES FROM URL.

    $phoneNumber = $_REQUEST["user"];
    $fullString = $_REQUEST["req0"];
    $string1 = $_REQUEST["req1"];
    $string2 = $_REQUEST["req2"];

    // PROCEED TO QUERY DATABASE.

?>

Here's what the variables mean:

  • \p is the phone number of the user who sent the text message.
  • \0 is the full string being sent.
  • \1 is the first segment.
  • \2 is the second segment.
  • \3 is the third segment, etc.

Let's view our example text message again:

paintballguys 1/2/08

Here's how this would translate into our own application:

  • \p = users phone number (format: +14325662232)
  • \0 = paintballguys 1/2/08
  • \1 = 1/2/08
  • \2 = (nothing for this example)

From here, we can take this information and query or update our own database.

To reply back to users via SMS, you need to sign up for a TextMarks API key. Using this, you can send text messages at any time through your web application.

To understand more, view the TextMarks Developers reference page.

About the author(s)

Matt Thommes is an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Comments

Note: Comments may be viewed by authors, but if you have a more specific question you'd like to ask them, please email matt.thommes@paininthetech.com.