This is a guest post by Robert Do, Product Marketing Manager on Google Cloud Platform. Robert graduated from the University of Pennsylvania with a degree in Economics and Information Systems and has worked at Google since 2009.
Robert used Google App Engine to create a new, easy way to distribute business cards via Twilio SMS. With the Twilio API, and Google App Engine’s scalable infrastructure, he had his app up and running fast.
In this post, Robert explains how to send business cards directly to email via SMS.
Have you ever met someone but are out of business cards? This was the exact situation I was in when I ran into the Twilio folks at a conference. I absolutely hate carrying bulky business cards, and then I thought, this would be a perfect idea for building a Twilio app that lets you send virtual business cards using SMS.
Several years ago there was a startup called DropCard that did this, but they’re no longer around. I thought I’d take a stab at building this app myself so I built SwapCard. This was my first project using Twilio and I found it delightfully easy to get started. I was able to get SwapCard up and running in a matter of days. Check it out! You can starting sending business cards at www.swapcard.co.
Build your own SMS to email app!
I’ll show you a very basic example in Python of how you can create a simple app on App Engine that lets you text an email address to a Twilio number which then has your App Engine app send a message to that email. This involves setting up your Twilio account to get your Twilio number and building a simple App Engine app that handles the requests from Twilio. Here’s how it works:
- You text an email address to your Twilio number
- Your Twilio number will point to your App Engine app
- Your App Engine app sends an email to the email address you texted
- Your Twilio number texts you back a confirmation that an email has been sent
Setting up the App Engine app with webapp2
First we’re going to build an app using App Engine that will send an email once that url is called as well as use the Twilio API to send a SMS confirmation.
The first step is to register your application at cloud.google.com and create a project.
App Engine provides a simple webapp2 framework we’ll be using. It also provides a very easy to use Mail API. I suggest using the App Engine launcher to create your application as it provides all the necessary foundational files. Create a new application using the App Engine launcher.
Open up main.py in an editor.
Setting up Twilio
Now we’ll add the code that will use the Twilio API to send a confirmation SMS back to the user. First, you’ll have to download the twilio-python library. You’ll also need its dependencies of httplib2 and six. Copy these libraries into your application folder. You’ll also need to sign up for an account at Twilio.com.
You need to import the library into your app and add your account SID and auth token, which you can find at the top of your Twilio account.
Now we just need to add to the bottom of the SendEmail handler the code to send the sms.
The final product should look like this.
Deploy your application. You can also download the project source files on github at https://github.com/robertdo/twilio-gae
Setting up a Twilio phone number
Now that your app is live, all you need to do is set up a Twilio phone number that points to that app whenever it receives an SMS.
Log into your account at Twilio.com and get a phone number.
In the settings for that phone number, change the SMS request URL to be http://<YOUR-APP-ENGINE-APP>.appspot.com
This tells Twilio to point to that URL whenever that phone number receives an SMS.
Now try texting an email address to your Twilio number. An email should be sent to that email address and you should get an SMS confirmation.