Send Documents on Feature Phones with Twilio and Kloudless

Hey hey! Following an intense month of events, I got inspired by all the cool hacks at Hack(bright) for Good, companies at TechCrunch Disrupt and developers at Kloud Kantina.

I thought txt.us, a WhatsApp for feature phones (find their project source code here), was especially cool, so I wanted to see if I could take the idea one step further: the ability to send files via SMS using a link.

txt_us_hackbrightforgood_2014

Team txt.us presenting at #hackbrightforgood

[tl;dr check out the finished Twilio + Kloudless project and the source code on GitHub to see an app that lets you send files stored in the cloud via SMS]

The Code

The application provides the following commands, which are sent via SMS to the application’s Twilio phone number:

  • ls – returns indexed list of visible folders
  • cd (<index>|..) – change to listed directory or to parent respectively
  • get <index> – Get an SMS with a link to download the file
  • send <index> <phone number> – send an SMS with link to file to number (e.g. +15555555555)
  • reset – starts your session back from the beginning

It is built using the Flask application that you created by the end of the Twilio SMS and MMS Python Quickstart. I had to add a bit of extra code to make it useable as a public web application, but the main cloud storage code interaction code is in the handler.py file. There I made the following translations from what I wanted into the Kloudless Python SDK code:

  • ls for accounts: kloudless.Account.all()
    this will list all accounts that your application has access to

    • In the final product, I end up storing account ID’s with phone numbers so that not every phone number sees every account.
    • To look up an individual account, you can simply do kloudless.Account.retrieve(account_id) where account_id is the id number of the account you want.
  • ls for a directory, if you have the right account object in account and the folder id in folder_id: account.folders(id=folder_id).contents()
    • To list the contents of the root folder for a particular account (with the account object stored in account): account.folders().contents() this works because the id defaults to the root directory of the cloud storage account.
  • get if you have the file object stored in file_obj and the account in account: account.links.create(file_id=file.id)
    • This returns a link object containing a url that the user can visit to preview (if the source supports it) or download the file.
    • I decided to just return a link, since I wasn’t sure whether all file types could be sent via MMS and most phones have some kind of web browser (though it might be fairly bare bones)
  • send is basically like get except that you are sending it to someone else so you have to make an extra Twilio API call

Once the basic commands were mapped out, it was relatively simple to wrap the functionality in an object that we can easily re-use.

The Twilio functionality I used was also very straight forward. For handling web hook responses, I simply create a TWiML response like so:

resp = twilio.twiml.Response()
resp.message("This should be the response from the command handler")

This can be returned to the Twilio webhook to send a response to an incoming text message. The command handler I made just outputs the message that we want to send back.

The only other functionality that I used was sending messages, which is also really straight forward:

twilio_client = TwilioRestClient(account="blah", token="blah")
twilio_client.messages.create(to="+15555555555",
                              _from="+YOURAPPNUMBER",
                              body="This is a message!")

And that is it, those are the basic pieces I used to make this app, the core parts of this application is only about 150 lines of code, the rest is just fluff to make the application more web ready (like having an actual website to log in and manage connected accounts).

Using Twilio + Kloudless

To use Twilio+Kloudless, first click the link and enter your phone number.
Check your phone for the confirmation code and enter it into the form field. Once your account is confirmed, you can connect your different cloud storage accounts via the web interface.

From your phone, text “ls” to the stated number, which then prompts you through interacting with your connected accounts. I won’t spoil all of the fun, so I’ll let you check out the project yourself.

Conclusion

Throughout this project, I didn’t have to write a single line of cloud storage service specific code, and with just those simple commands detailed above, this app works with accounts from any of the nine services supported by Kloudless.

With Twilio and Kloudless, you can use a feature phone to send files (no need for a smartphone!). Check out the code on GitHub — feel free to fork it and build your own functionality on top. If you want to get started on your own project, sign up for Twilio or Kloudless here. To bounce ideas around, leave a comment below or drop us a line at hello@kloudless.com.

What're your thoughts!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s