Section 10.1.

Using a Mashup: 411Sync >

Chapter 10. Using a Mashup: 411Sync

411Sync (http://www.411sync.com) is a service that provides a web-based API to let you create your own application on top of their SMS functionality. It's a free, easy to use method to implement a lookup-type SMS service. The usage paradigm is straightforward:

  • Register a keyword with 411Sync, such as smsbook.

  • Provide an URL for 411Sync to call when someone sends them an SMS with that keyword.

  • Your URL should return an RSS or Atom feed to 411Sync, which they use to construct a reply SMS.

For example, we registered the keyword smsbook in the process of writing this guide. Its purpose was to allow people to easily add themselves to a mailing list that would inform them when the guide was published.

Here's an example of sending using the service (you can try it yourself).

If you send the following text message to (415) 676 8397(411Sync's SMS number),

smsbook youremail@yourdomain.com

You will receive an SMS back from (415) 676 8397 that reads:

More Info at http://tinyurl.com/2phuke -- youremail@yourdomain.com added to mailing list -- - Reply back ?? to get alerts

Now, that probably looks a bit confusing. 411Sync adds the header ("More info at http://tinyurl.com/xxxxxx") and footer ("- Reply back ??to get alerts") to your message (and, yes, that comes out of your 160 character allotment).

10.1.

10.1.1. Advantages and disadvantages

This biggest advantage of 411sync is the cost: free. With no money and very little code, you can run a service that sends and receives text messages. Great, right?

What you get in cost, you give up in flexibility. The chief disadvantage of using 411Sync is the loss of control over the message format. Remember that header and footer that you saw in the example above? Do you want that as part of your service? Even if you don't, you can't change or remove it.

10.1.2. Example service: Email registration

As we mentioned above, we created a simple sign-up service when we were writing this short cut that let people who ask about it sign up to receive a notification when the short cut was ready. Anyone who sent the message:

smsbook youremail@yourdomain.com

to 411Sync would get a message back telling them we'd notify them when the short cut was ready (and we added their email address to our database).

Let's take a look at how we did it.

10.1.3. How to: Email registration service with 411Sync

To run our service, you'll need:

  • A web server capable of executing Python CGI scripts

  • SQLite on the same server

See the "Chapter 7" section for information on how to set these up if you haven't already.

10.1.3.1. Register with 411Sync

First step to creating your service will be to register with 411Sync. Just fill out the simple form at http://www.411sync.com/cgi-bin/Register, provide the verification number he'll send to you as a text message and sign back in.

NOTE

Did you notice that 411Sync asks for your service provider (carrier) when you register, in order to text message you your verification code? Can you guess why it needs this information?

Flip back to the "Chapter 9" section in this guide for a hint!

10.1.3.2. Create the service

The code running our smsbook service is quite simple:

smsbook.cgi:

#!/usr/bin/python import sys import cgi import cgitb; cgitb.enable() form = cgi.FieldStorage() request = form.getfirst("request") if not request:        response = "--Include your email after smsbook--" elif len(request.split("@")) != 2:        response = "--Include a valid email after smsbook--" else:        email_file = file("emails.txt", "a")        email_file.write(request + "\n")        response = "--%s added to mailing list--" % request        email_file.close() print """ <?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0"> <channel>        <title>Email Reg</title>        <link></link>        <description>test</description>        <language>en-us</language>        <copyright></copyright>        <item>               <title> %s </title>               <description></description>        </item> </channel> </rss> """ % response     

When 411Sync invokes this script, it will pass in any parameters (text included in a message after our keyword) as a request, so the first thing our script does is grab that for processing. In our example, we check it to ensure that it isn't empty and to make sure it looks at least a little bit like an email address.

Provided that everything checks out, we open a file called emails.txt in append mode, and write the email address that was stored in request into the file.

The last thing we do is return a response to 411Sync. 411Sync is pretty peculiar about the format of the response, and it isn't incredibly well documented on its web site.

The text that actually gets displayed to the user is tucked inside the title tag of the item element. The content of that tag is %s in our example, which is being substituted with the value of response.

10.1.3.3. Register your keyword

In order to register your keyword with 411Sync, you'll need to actually have the XML response ready for it to test, so make sure you've completed the previous step before you start this step.

From 411Sync's home page, click the "My Mobile Search Keywords" link and then click "Create Mobile Search Keyword." The form looks a bit more complicated than it is. Most of the questions it asks have to do with how your service will be advertised on its web site. The fields you need to worry about are the ones where you specify your keyword and the HTTP location of your XML data (i.e., the callback URL 411Sync will invoke when someone sends them a text message with your keyword).

10.1.3.4. Try it

You're ready to go. Try sending a text message with your keyword and an email address to 411Sync. I'd suggest sending a message with the smsbook keyword, too, but I guess if you're reading this, you're all set.

If you're interested in doing more with 411Sync than we describe here, you should check out its full API description at http://www.411sync.com/cgi-bin/Developer.

 

 



How to Build an SMS Service
How to Build an SMS Service
ISBN: 789742233
EAN: N/A
Year: 2007
Pages: 52
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net