Gist of the Day: Using Mojo, Mongo, and SL4A to send SMS Messages (1 of 2)

I got a little bored with what I had been posting (I suspect you did, too), so I’m doing something neat. I’m going to write a full (though limited) program for you. Here are the user stories (if you don’t know what user stories are, see here before continuing):

  • As a web user I can enter a phone number and a SMS message into a queue so that it can be sent by a mobile handset.
  • As a mobile handset user, I can push a button to dequeue a message and send it via SMS so that I might risk my device’s stability and my own financial solvency by opening up the internet to sending messages through my phone.

A Little More Definition

So, I’m really not going to let you send SMS messages through my phone, that would be really stupid for me to open that sort of thing up. I will, however, give you the code so that you can demo it to our friends.

Technologies Used

Here’s the Code

So here are a few things you will probably notice right away:

  • I’m using the __DATA__ segment of the script to store all of my templates. Mojolicious::Lite lets you do that, it’s pretty cool.
  • I’m using Mojolicious in CGI mode, mainly to keep things simple for the demo. Mojo also supports hypnotoad and morbo, as well as a bunch of other things which I have been assured the cool kids are totally using. I like hypnotoad and morbo (for development only) both quite a bit.

Let’s go into the code a bit

  1. The '/' route is the landing page, it just presents you with the form.
  2. When you submit that form, you go to the ‘/sms’ route (via POST only). This then allows you to queue up your message in the Mongo collection.
  3. Then there’s the '/dequeue' route which does a find_and_modify() call against the collection. The reason I’m doing it this way is because this is an atomic action in MongoDB, so I don’t have to worry about anybody trying to modify or remove the record while I’m fetching and removing it.
  4. Then I take the entry and print it out in JSON.

Tomorrow I will write an SL4A script which will consume the '/dequeue' route to fetch a record for transmission.

The Conclusion

This one isn’t terribly fancy, but I thought it’d be nice to stick a bunch of stuff together for a quick demo, and it’s been a while since I played with SL4A. I hope you liked reading this as much as I enjoyed writing it.
Be on the lookout tomorrow for when I do the SL4A component.

One thought on “Gist of the Day: Using Mojo, Mongo, and SL4A to send SMS Messages (1 of 2)”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.