3.4.5 Twilio
Last updated
Last updated
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
Click on the red "Plus" icon.
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.
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.
You will be shown a screen like this one below where they confirm all capabilities, the number, and other details.
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.
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)
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
You will see a list of fields like this one
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.
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.
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.
Click on the red "+" button to create a new app. You will see a screen like the one below.
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)".
Follow this formula to get your Request URL:
Your deployment URL: "https://**yourdeploymentname**.ushahidi.io"
The API URL: "https://**yourdeploymentname.api**.ushahidi.io"
The Request URL then would be "https://yourdeploymentname.api.ushahidi.io/sms/twilio". is what you will enter in the "Request URL" field.
After you are done with adding Messaging and friendly name, you can click the red "Save" button.
Go to your list of active phone numbers and click on the number you purchased https://www.twilio.com/console/phone-numbers/incoming
Click on your number.
Scroll down and you will see a form like this one.
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.
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.
Example of a single message below.
Go to the Ushahidi Platform
Go to the data view
You should see the messages you sent in the data view list