MuleSoft Integration With Twilio
Learn how to integrate the cloud communication platform Twilio with MuleSoft, and configure and use it to create a demo app.
Join the DZone community and get the full member experience.
Join For FreeTwilio is a cloud communication platform which allows applications to send and receive text messages, make and receive phone calls by exposing the APIs. MuleSoft provides a Twilio connector which is available on Anypoint Exchange to integrate apps developed in Anypoint Studio. You can use the steps in this post to configure Twilio and develop a demo app.
To start the integration with Twilio, please download the Twilio connector from the exchange.
To connect with Twilio, you should have an active account with Twilio.com. For demo purposes, Twilio allows developers to create a free trial account.
Once you create a trial account, you can login to your account and can find the details required to configure the Twilio connector. Go to Twilio Dashboard (twilio.com/console) to find the Account SID and Auth Token.
Go to the Phone Numbers page to create a phone number from which the SMS will be sent in this demo.
Verify your caller ID under Verified Called IDs. Twilio APIs will allow sending an SMS only to verified caller IDs.
To start, create a new Mule project. Please drag and drop the connectors as shown in the below flow:
Once you have all the pallettes, use the following configs-
HTTP: Port 8091, path: /send/{toNumber}
Transform message:
% dw 1.0
% output application / java
-- - {
body: "Message from mulesoft via Twilio",
from: "${fromNumber}",
to: inboundProperties.
'http.uri.params'.toNumber
}
as: object {
class: "org.mule.modules.twilio.pojo.sendmessagerequest.MessageInput"
}
Twilio connector:
Click the green plus sign to the right of "Connector Configuration" and set the fields as shown in the below example.
Provide the AccountSid and Authtoken which we got from the Twilio account. Use this URL to configure API URL: https://api.twilio.com/2010-04-01. This was the latest URL when this blog was written, it may change.
Use Test Connection to test the connectivity, to see if the connector is able to connect to Twilio successfully.
The operation will be "Send Message" as this demo is for sending an SMS.
Entity Reference: #[payload]
As we have configured all components, our app is ready to be deployed and tested. Just run it and deploy it on your Mule Runtime env.
Now your app is ready to send an SMS through Twilio. If you open your browser and hit http://localhost:8091/send/9726932341, you will see the following page:
You will receive the SMS on your phone:
For new Mule learners, try this example to get started. Also, explore the Anypoint Exchange to see other resources you can leverage.
Please refer to this video for a live demo.
Opinions expressed by DZone contributors are their own.
Comments