3.4.5 Twilio

Twilio allows you to programmatically make and receive phone calls and send and receive text messages using its web service APIs.

NB: You need a Twilio account to be able to configure this as a data source. To sign up, go to **[_https://www.twilio.com/try-twilio**_](https://www.twilio.com/try-twilio)

To get started with Twilio set up,

  • Log into your twilio account.

  • You’ll need to buy a number to use. Click on the hashtag icon

Buy a number - # icon highlighted in the sidebar
Buy a number - # icon highlighted in the sidebar
  • Click on the red "Plus" icon.

Click on the red (+) icon highlighted
Click on the red (+) icon highlighted
  • Select the desired criteria for your phone number In the number selection/purchase screen

    • Select the country where you need a phone number. This is the number that people will use when sending a report through SMS.

    • Location/Number: You can search numbers by digits/phrases or by location. This is optional.

    • Capabilities (Voice, SMS, Fax, MMS): Make sure you tick the "SMS" checkbox. We want to make sure Twilio only shows us numbers with SMS capabilities. If it can't be ticked/clicked, then it means that Twilio doesn't have any numbers with SMS capabilities in that country.

Setting up a Twilio number. Capabilities selected: SMS. Select your Country, and a number. Then hit the search button.
Setting up a Twilio number. Capabilities selected: SMS. Select your Country, and a number. Then hit the search button.
  • Click on **_Search**_. A list of available numbers with their rates based on the criteria set above will appear

  • Click Buy on the number you’d like to use.

List of Twilio numbers. Click Buy to get one.
List of Twilio numbers. Click Buy to get one.
  • You will be shown a screen like this one below where they confirm all capabilities, the number, and other details.

Click the buy button purchase the number
Click the buy button purchase the number
  • Click the buy button at the bottom right hand of the screen to purchase your number.

  • Once you have a phone number, note it down as you’ll need it to configure your data source later on.

Configuring Ushahidi Platform to use your Twilio phone number

First, we need to get the following information from your Twilio account:

  • Phone Number: the number you just purchased. If you forgot it, you click the "Hashtag" icon in Twilio again to see your available numbers.

  • Account SID

    • You will see a panel like the one below with details about your project. Get the Account SID from it (we've highlighted it in the screenshot as a reference)

Account SID field highlighted
Account SID field highlighted
  • Auth Token

    • In the same panel as the account SID, you will see a "view" link next to "Auth token" as shown on the diagram above.

    • Click it, and it will display your account's auth token.

Next, with the Account SID, Auth Token and Phone number you just obtained:

  • Go to your Datasources settings page on your Ushahidi deployment.

  • Click on the drop down icon on the right as shown

Twilio data source configuration.
Twilio data source configuration.
  • You will see a list of fields like this one

Twilio datasource configuration in Ushahidi Platform.
Twilio datasource configuration in Ushahidi Platform.
  • Enter the following details, which you got earlier from your Twilio Account

    • From: Enter the phone number you got from Twilio.

    • ACCOUNT SID: Enter the account SID of your Twilio account

    • AUTH TOKEN: Enter the Auth Token retrieved from your Twilio account Dashboard page

    • SMS Auto Response: This will be sent automatically when a user sends a message to your Twilio number. You could use it to provide reference information, like thanking the user or just confirm receipt.

    • Click on Save **and this data source’s settings will be saved. Unstructured posts from SMS will now be pulled into the platform from Twilio.

  • To enable/disable the Twilio data source and choose which survey to import to, simply click on the green toggles.

Enable survey submissions from Twilio.
Enable survey submissions from Twilio.
  • At this point, your Twilio setup in Ushahidi Platform is ready to use but we need to do some follow up tasks in Twilio to connect both of them.

Twilio setup for Ushahidi Platform SMS connectivity

Go to https://www.twilio.com/console/phone-numbers/runtime/twiml-apps where you can create Twiml apps. This is where we can make Twilio aware of the existence of your Ushahidi deployment and help them connect with each other.

Twilio Page - TwiML Apps to setup Ushahidi Platform SMS connectivity
Twilio Page - TwiML Apps to setup Ushahidi Platform SMS connectivity
  • Click on the red "+" button to create a new app. You will see a screen like the one below.

Create TwiML App
Create TwiML App

Fill in these details;

  • Friendly name: Write down a name that helps you remember what this app does. We usually choose the deployment name as the "friendly name" in Twilio.

  • Messaging: In this **section you will need to add your deployment's Twilio endpoint URL. This is the API Url to your deployment + the endpoint to connect to.

    For Ushahidi.io deployments, the rule is always the same. Given a deployment with the following url "https://**yourdeploymentname**.[ushahidi.io](http://ushahidi.io)" + the API Url will be = "https://**yourdeploymentname.api**.[ushahidi.io](http://ushahidi.io)".

  • After you are done with adding Messaging and friendly name, you can click the red "Save" button.

Configure your phone number to send messages to Ushahidi platform

Configure with "TwiML App" and Enter the TWIML App friendly name
Configure with "TwiML App" and Enter the TwiML App friendly name
  • In the configure with field: Select TwiML App

  • in the TWIML APP field: Enter the Friendly name you created above for your deployment. This will ensure that when you get an SMS, Twilio sends a request to Ushahidi platform to save the message.

Trying this out

Checking that Twilio gets the message

  • Send an SMS to the phone number you purchased and configured (ie from your own phone).

  • You can validate that messages are getting to Twilio by going to the Programmable SMS logs https://www.twilio.com/console/sms/logs

  • You will see the messages your Twilio number has received and sent in the list

  • The list will look like this. You can click on the red link under "Date" to see the details of each message.

SMS Logs
SMS Logs
  • Example of a single message below.

Details of a single Message
Details of a single Message

Checking that Ushahidi Platform gets the message

  • Go to the Ushahidi Platform

  • Go to the data view

  • You should see the messages you sent in the data view list

Last updated