Twilio is a cloud communications Infrastructure as a Service (IaaS).
MuleSoft maintains this connector under the Select support policy.
About the Twilio Connector
This connector provides an API for making and receiving telephone calls, and sending and receiving text messages. To get started with Twilio, follow the steps below to gain access to their free sandbox service to send SMS text-messages. You can configure the Twilio connector in Anypoint Studio with your API credentials.
Note: To use the Twilio connector, you must have an active Twilio.com account, either as a Trial or Paid. To create an account, see Try Twilio.
The Anypoint Connector for Twilio provides connectivity to the Twilio platform, which serves APIs for text messaging, VoIP, and voice calls.
You can use this document to understand how to set up and configure a basic flow using the connector. You can track feature additions, compatibility, limitations, and API version updates with each release of the connector using the Connector Release Notes. Review the connector operations and functionality using the Technical Reference with the demo applications.
About Prerequisites
This document assumes that you are familiar with Mule, Anypoint Connectors, and Anypoint Studio. To increase your familiarity with Studio, consider completing a Anypoint Studio Tutorial. This page requires some basic knowledge of Mule Concepts, Elements in a Mule Flow, and Global Elements.
About Hardware and Software Requirements
For hardware and software requirements, visit the Hardware and Software Requirements page.
To Create a New Twilio Account
To create a new Twilio account:
-
Browse to Try Twilio.
-
After you log in to your developer account, you see the Twilio dashboard. Note the Account SID and Auth Token values, and copy the credentials to the Twilio connector configuration menu in Anypoint Studio.
With a free developer account, you need to verify your SMS-enabled phone before you can send text messages to it.
-
Click Numbers in the Twilio website navigation to go to the Manage Numbers portion of their website.
-
Click Verify Numbers, and then click Verify a number.
-
Enter your cell phone number, and click Call this number. Follow the instructions provided to validate your number. You receive an automated phone call and need to enter an authorization code.
-
Finally, to send SMS-messages, you need to use the Sandbox
from
number. This phone number needs to be entered into the Twilio connector configuration menu in Anypoint Studio. This Sandbox number is also located on the Twilio dashboard, with the Account SID and Auth Token.
Tip: As you copy fields from the Twilio website to the Anypoint Studio connector configuration, be sure to not copy in additional leading/trailing characters or spaces. It is a good idea to visually confirm that your copy and paste functions did not capture surrounding characters.
To Install the Connector in Studio
You can install the connector in Anypoint Studio using the instructions in Installing a Connector from Anypoint Exchange.
To Upgrade from an Older Version
If you’re currently using an older version of the connector, a small popup appears in the bottom right corner of Anypoint Studio with an "Updates Available" message.
-
Click the popup and check for available updates.
-
Click the Connector version checkbox and click Next and follow the instructions provided by the user interface.
-
Restart Studio when prompted.
-
After restarting, when creating a flow and using the connector, if you have several versions of the connector installed, you may be asked which version you would like to use. Choose the version you would like to use.
Additionally, we recommend that you keep Studio up to date with its latest version.
To Configure Global Properties in Studio
To use the Twilio connector in your Mule project, search for "twilio" and drag the connector to your Studio canvas. Click the green plus sign to the right of Connector Configuration and set the fields as shown in this example.
Field | Description |
---|---|
Basic Settings: |
Name of the connector configuration. Type: String |
Connection: |
Your username (Account SID) to access Twilio API. Type: String |
Password |
Your password (Auth Token) to access Twilio API. Type: String |
General: |
Twilio API you want to access. Type: String |
After setting the parameters, click Test Connection to ensure you can reach the Twilio.com API.
About Configuring Operations
You can set the following operations:
-
Get Message List
-
Get Message
-
Send Message
-
Redact Message
-
Delete Message
-
Get Media List
-
Get Media
-
Delete Media
About the Connector’s Namespace and Schema
When designing your application in Studio, the act of dragging the connector from the palette onto the Anypoint Studio canvas automatically populates the XML code with the connector namespace and schema location.
-
Namespace:
http://www.mulesoft.org/schema/mule/twilio
-
Schema Location:
http://www.mulesoft.org/schema/mule/connector/current/mule-twilio.xsd
If you are manually coding the Mule application in Studio’s XML editor or other text editor, define the namespace and schema location in the header of your Configuration XML, inside the <mule> tag.
|
1
2
3
4
5
6
7
8
9
10
11
12
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:twilio="http://www.mulesoft.org/schema/mule/twilio"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/twilio
http://www.mulesoft.org/schema/mule/twilio/current/mule-twilio.xsd">
<!-- put your global configuration elements and flows here -->
</mule>
Maven Dependency Information
If Maven is backing the application, this XML snippet must be included in your pom.xml
file.
1
2
3
4
5
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-twilio</artifactId>
<version>2.0.0</version>
</dependency>
Inside the |
To Configure Use Cases
The following are common use cases for the Twilio connector:
To Configure Send and Redact Message
In the following example, a Mule application sends a message to a phone number, and then redacts it.
-
Create a new Mule application and add the following properties to the
mule-app.properties
file:Property Description accountSid
Your Account SID.
authToken
Your Authentication Token.
fromNumber
The phone number from where SMS is to be sent. This is configured inside the Twilio instance.
-
Add an empty flow and drag an HTTP endpoint to the inbound part of the flow. Set its path to
/send/{toNumber}
. -
Drag a Transform Message at the flow and prepare the input for the Twilio connector:
1 2 3 4 5 6 7 8 9 10
%dw 1.0 %output application/java --- { body: "You are now subscribed!", from: "${fromNumber}", to: "+" ++ inboundProperties.'http.uri.params'.toNumber } as :object { class : "org.mule.modules.twilio.pojo.sendmessagerequest.MessageInput" }
-
Add a Twilio Connector after the Transform Message and apply the following settings:
-
Select the Send Message operation.
-
Set Account Sid to
${accountSid}
, and Entity Reference to#[payload]
.
-
-
Drag a Variable component and configure the following parameters:
-
Set Name to
messageSid
. -
Set Value to
#[payload.getSid()]
.
-
-
Add another Transform Message to create the input for the Redact Message operation:
1 2 3 4 5 6 7 8 9 10
%dw 1.0 %output application/java --- { body: "", from: payload.from, to: payload.'to' } as :object { class : "org.mule.modules.twilio.pojo.redactmessagerequest.MessageInput" }
-
Drag a Twilio Connector after the Transform Message and apply the following settings:
-
Select the Redact Message operation.
-
Set Account Sid to
${accountSid}
. -
Set Message Sid to
\#[messageSid]
(this is the variable we stored two steps above). -
Set Entity Reference to
#[payload]
.
-
-
Put an Object to JSON transformer at the end of the flow.
-
Run the application and point your browser to http://localhost:8081/send/{toNumber}, replacing the
toNumber
with a valid mobile phone number.
About Connector Performance
To define the pooling profile for the connector manually, access the Pooling Profile tab in the applicable global element for the connector. For background information on pooling, see Tuning Performance.
About Other Resources
-
Access the Twilio Connector Release Notes.
-
Visit Twilio’s official REST API Reference.