Author: Manish Prabhu and Ganesh Nyati
Twilio is a cloud communication platform used as IaaS (Infrastructure as a Service). Using twilio, we can send SMS messages, receive messages, delete messages etc. If we want to integrate twilio in mule 4, we need to import twilio connector from exchange which will have various operations shown in below snapshot.
2.0 Creating Free Trial Twilio Account
In order to integrate twilio with mule 4, you need to create an account on twilio portal.
After creating an account, you will be logged in inside twilio portal.
In your twilio dashboard, you will get ACCOUNT_SID and AUTH_TOKEN fields. These fields are required in order to configure twilio in Mule flow. In order to send SMS, you must get a number from twilio. You can do this by using twilio dashboard.
Click on get a trial number button on the dashboard.
Click on choose this number.
Click on Done. The displayed number on the screen will get added to your dashboard. Using this number, you can send the SMS.
In order to send SMS to a specific number, that number must be added and verified within twilio. In order to do this, click on three dot sign enclosed inside circle sign.
You will get various options. Select phone numbers option.
Select verified caller IDs option.
Click on Verify a number.
Select the text you instead for getting a verification code through SMS or you can enter your number to verify to get verification code via phone call.
Enter phone number that you want to verify and select text me option. You will get your verification code on given mobile number.
Enter the verification code. After verification, the number will get added to the list of verified IDs.
3.0 Integrating MuleSoft Application With Twilio Connector
Create a sample flow with an HTTP Listener, two transform messages and a twilio connector. First transform message is used to generate input payload towards Twilio.
Second Transform message will be used to generate output payload and it is response from Twilio.
Configure first transform message as per given figure below.
Body is the text that you need to send as SMS.
From is twilio number which will be displayed to recipient of sms.
To is sms recipient number.
Twilio connector will not be present by default in pallette. You need to import it from anypoint exchange. Select search in exchange option and enter twilio as a search phrase. After getting twilio connector in search result, select twilio connector and add it.
After adding the connector in pallet, select send message connector of twilio and add it inside flow. Configure the value of ACCOUNT_SID in given text box of ACCOUNT_SID(this value you can get from twilio dashboard).
Click on edit connector configuration. You need to configure username as ACCOUNT_SID, password as AUTH_TOKEN. Host, port, basePath, protocol will be taken directly when you click on edit configuration.
You can verify the configuration by clicking on the Test connection button.
Select second transform message and configure it as per given figure below.
4.0 Testing MuleSoft Application for Sending SMS
Run your anypoint project and test the flow using postman.
This is how you can integrate Twilio for sending SMS using MuleSoft.