SMS Auto-Responder App

One software project I wrote on the side was an SMS autoresponder, or SMS bot.

The fun began as early as planning, and I had some neat features to build into it. For one, a bus schedule lookup. And random fortune cookies. Also the obligatory weather report. Plus a stateful game of Farkle, because why not?

After wasting time and money looking at GSM modems (Sierra Wireless 8881U) and third party APIs (Tropo, Twilio), I settled on doing it myself. I had a spare Blackberry Bold 9000 around that ran a more or less complete version of the JRE 4. I purchased a prepaid SIM card with a simple call-and-text package and got to work. There was no need for a data package because the phone could be left at my home, perpetually connected to the WiFi network.

The Blackberry OS' API for receiving text messages was easy to work with. Just register a class and it would be called anytime something came in. Sending messages was substantially harder if the size was greater than 160 characters. The API wouldn't split it into individual payloads itself, so I had to write code just for that.

The SIM card plan I used included caller ID, without which the project would have been impossible. The app parsed the area code to block long-distance senders.

Request processing was done using the Command pattern so that I could add more features, which I referred to as "talents" in code, easily. Some requests required one or more calls to the Internet, and others relied on the app's internal SQLite database.

The database is also where state was kept, such as user accounts, user history, and game state, of course. Each user was identified by their phone number and had a default low privilege. I had my own high-privilege account, and I could as an admin grant/deny specific talents to specific users. For instance, the admin talent was only accessible to users with a sufficiently high account privilege. Because I didn't want to spend a lot of money on this project, users were also rate-limited to a couple thousand messages a month.

The bot was fun while it lasted, but the fact it cost real money was a deterrent. I had hopes of converting it to a BBM (Blackberry Messenger) bot because it would only need Internet and no cell plan, but that was 2011 and people were moving away from Blackberry rapidly, myself included. Now that everyone has low-latency 4G smartphones with instantaneous voice-recognition, the value of the bot would be a lot less. However there is still something to be said about a customizable home-brewed solution.


The control talents were START AND STOP, which created/enabled and disabled accounts, respectively. In addition, the LAST (alias L) command behaved as though you had repeated your last non-LAST message. That was great for repeating a query without having to use your phone's native resend feature which might be hidden in menus.

The HELP talent did just that and was used by including the name of a talent. Yes, HELP HELP returned a valid message, although I'm thinking now that it may have been a good place to hide an easter egg. Oh well.

One of the most useful talents was BUS. It accepted route numbers, stop numbers, and directions in the form of destination names. Stop numbers could be saved with nicknames for easy access without having to remember all the numbers. This talent needed to hit the city's bus schedule website to scrape the data when the request was made, so response times were longer than a pure SMS round trip.

Unfortunately the WEATHER (alias WX) talent didn't use realtime data from, say, Wunderground, but it used Google's unofficial weather API. The info was up to an hour old, so it was much easier to just look at the sky.

I included METAR and TAF talents for my own use that gathered the info for the specified airport ICAO code and returned the most recent full text of the METAR/TAF. In a similar manner as BUS, airport codes could be saved with nicknames.

There was a randomized talent called FORTUNE that took no arguments and replied with a fortune cookie message out of a database of 450. They were stored locally on the phone which meant they were very fast to use. There may or may not have been an additional undocumented talent PICKUP that replied with a randomized pickup line for laughs from a database even larger.

A friend asks only for your time not your money.

You are going to have some new clothes.

One that would have the fruit must climb the tree.

Finally, I spent dozens of hours racking up points on the Farkle dice game on Facebook. I was curious how fair the dice in the game were, and I was writing this bot, so I added a FARKLE game talent. The single-player game has several variations but is similar to Yahtzee in that six dice are rolled and certain combinations are worth certain points. After choosing a combination on a roll, the remaining dice can be re-rolled until there are no more dice in which case all six are available again, or there are no valid combinations of dice in which case the turn, and all points earned in it, is forfeit. The game lasts a fixed number of turns or until a certain score is reached.