Send SMS Using Twilio Connector

 

In this tutorial we will demonstrate how can we Send SMS Using Twilio Connector,Twilio allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs

Anypoint Connector for Twilio (Twilio Connector) is a cloud communications infrastructure as a service (IaaS).The Twilio platform serves APIs for text messaging, VoIP, and voice calls. Twilio Connector provides connectivity to the Twilio text messaging API

This connector provides an API for sending and receiving text messages

Prerequisites:

  • You should have account for Twilio
  • Module should be added in Anypoint Studio(Please visit to add module from exchange)

Operations Supported by Twilio Connector In Mulesoft

  • Send Message
  • Get Message
  • Get Media
  • Get Media List
  • Get Message List
  • Redact Message
  • Delete Media
  • Delete Message

Create twilio Account using below url:

https://twilio.com/try-twilio

 

Mail has been sent to registered email, Kindly verify the account

Note the Account SID and Auth Token for further use for connector configuration

 

Click on manage numbers and get your first twilio phone number to send message/phone calls

 

Congratulations message will be shown

 

Create a mule application in studio and configure the listener to trigger the request

Create a transform message(payload) to send message from Twilio connector

Note: From Number and To Number should be in E.164 Format

E.164 Format: E.164 is the international telephone numbering plan that ensures each device on the PSTN has globally unique number.This number allows phone calls and text messages can be correctly routed to individual phones in different countries. E.164 numbers are formatted [+] [country code] [subscriber number including area code] and can have a maximum of fifteen digits

 

 

Dataweave expression:

%dw 2.0
output application/json
---
{
    Body: "Hello this is Mulesy team and sending you test message",
    From: "+17137664893",
    To: "+91XXXXXXXXXX"
}

 

Drag and drop Send message from mule palette and configure the username(AccountSID) and password(AuthToken)

Send SMS Using Twilio Connector

 

Test the connection

Send SMS Using Twilio Connector

 

Pass the account sid and message to sent

Send SMS Using Twilio Connector

 

Create the transform message to receive the success message

Send SMS Using Twilio Connector

 

Deploy the application and test from soap ui

 

Message Received on Phone:

 

Sample application: twilio-sample-services

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tsaalbi
Tsaalbi
4 years ago

hello it does not work. I received following answer from postman. Please help

“You called the function ‘formUrlEncoded’ with these arguments: 
 1: Null (null as Null {encoding: “UTF-8”, mediaType: “application/json; charset=UTF-8″…)

But it expects arguments of these types:
 1: Object

9| formUrlEncoded(vars[‘send-message-request-data’])
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
 at formUrlEncoded (line: 9, column: 1)
 at main (line: 9, column: 1)” evaluating expression: “output application/x-www-form-urlencoded
fun formUrlEncoded(obj: Object) = obj mapObject {
($$) : $ match {
case x is Object -> write(x, “application/json”)
case x is Array -> write(x, “application/json”)
else -> $
}}

formUrlEncoded(vars[‘send-message-request-data’])”.

Mohammed
Mohammed
4 years ago

Followed the steps , getting below error INFO 2021-01-11 13:17:05,061 [[whatsapp].HTTP_Listener_Configuration.worker.01] org.mule.module.xml.transformer.jaxb.JAXBContextResolver: No common Object of type ‘class javax.xml.bind.JAXBContext’ configured, creating a local one for: SimpleDataType{type=com.mulesoft.weave.reader.ByteArraySeekableStream, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=org.mule.modules.twilio.pojo.sendmessagerequest.MessageInput, mimeType=’*/*’, encoding=’null’} ERROR 2021-01-11 13:17:05,223 [[whatsapp].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:  ******************************************************************************** Message        : null (javax.xml.bind.UnmarshalException) Payload        : {  “body”: “Test”,  “from”: “+16179936216”,  “to”: “+918328676825” } Transformer      : JAXBUnmarshallerTransformer{this=1b576897, name=’null’, ignoreBadInput=false, returnClass=SimpleDataType{type=org.mule.modules.twilio.pojo.sendmessagerequest.MessageInput, mimeType=’*/*’, encoding=’null’}, sourceTypes=[SimpleDataType{type=java.lang.String, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=java.io.Writer, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=java.io.File, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=java.net.URL, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=org.w3c.dom.Node, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=java.io.InputStream, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=javax.xml.transform.Source, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=javax.xml.stream.XMLStreamReader, mimeType=’*/*’, encoding=’null’}, SimpleDataType{type=javax.xml.stream.XMLEventReader, mimeType=’*/*’, encoding=’null’}]} Element        : /whatsappFlow/processors/3 @ whatsapp ——————————————————————————– Root Exception stack trace: org.xml.sax.SAXParseException: Content is not allowed in prolog. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown… Read more »