Make Calls with Twilio using the ThingHTTP App

Twilio is a cloud communications platform for phone calls and SMS messages. They have an API that you can send HTTP requests to and place phone calls. The API requires HTTPS and Basic Authentication which is perfect for high-level devices like phones and computers, but nearly impossible for an embedded device like the Arduino, Netduino, and mbed. The ThingHTTP App from ThingSpeak allows a device to make a simple API call over HTTP that gets relayed to to any web service or API. The App supports HTTPS and is perfect to interface with the Twilio API with your device. Now, your thing can really speak…

Setup Twilio

Twilio is a paid service. At the time of this tutorial, your account will start with some funds to play in the sandbox. You will also have access to a phone number to use. You can take the service further by adding more funds and buying a dedicated phone number.

  • Sign up for Twilio
  • Find your API Credentials [AccountSid and Auth Token] under the Developer Tools section on the Twilio Dashboard

Setup ThingHTTP Request

  • Sign into ThingSpeak
  • Click Apps
  • Select  ThingHTTP
  • Click Create New Request
  • Enter a Name for your new request: Twilio Test
  • Enter the Making Calls API URL: https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls
  • Enter your AccountSid under HTTP Auth Username
  • Enter your Auth Token under HTTP Auth Password
  • Select POST method
  • Enter Content Type: application/x-www-form-urlencoded
  • Under Body enter the required parameters of From, To, and Url: From={sandbox_number}&To=%%number%%&{link_to_Twilio_formated_document}
  • Click Edit Request

Example Body:

This example body will speak the last light level on the “my_house” public feed.

From={sandbox_number}&To=%%number%%&Url=http://api.thingspeak.com/channels/9/field/1/last.txt

Send Request to ThingHTTP

POST /apps/thinghttp/send_request HTTP/1.1
Host: api.thingspeak.com
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: (number of characters in message)

api_key=(thinghttp_api_key)&number={phone_number_to_call}

Notes

  • The formats for the phone number used by Twilio follows the E.164 format, such as +13215551212
  • The Twilio formated document can be any Url that outputs TwiML format (based on XML) – what ever this URL contains will be read back by Twilio
  • “&” must be encoded in the Twilio return Url with “%26″
  • Using the %%number%% in the ThingHTTP request allows you to dynamically change what number is called by the Twilio  request by passing the number in the request
  • Twitter
  • Facebook
  • Google Bookmarks
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Digg
  • Add to favorites

4 comments

  1. Love this hack! Might be interested Twimlets to run the TwiML portion of the call w/o requiring a web server:

    http://labs.twilio.com/twimlets/

    Also, drop us a note at help@twilio.com, we’d love to hook you up with some swag for writing such an awesome post.

  2. This is so rad I cannot wait to get hooked up, this stuff is really the next gen of IT.

  3. I’m trying to send a SMS message using this technique, but can not seem to get Twilio to acknowledge the thingspeak URL. I have no problem sending put text, but can’t seem to get a response from thingspeak to be integrated into the page. I am using the proper Twilio app, as plain text messages get through just fine.

  4. You should also add that a “Body=” parameter is required or Twilio rejects the request.

Leave a comment