This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Working with Twilio SMS messages

Overview

The following operations are available for working with SMS messages. Click an operation name to see details on how to use it.

For a sample proxy service that illustrates how to work with SMS messages, see Sample configuration.

OperationDescription
sendSmsSends a new outgoing SMS message.
getSmsListRetrieves a list of SMS messages associated with your account.
getSmsRetrieves information about a specific SMS message.

Operation details

This section provides further details on the operations related to SMS messages

Sending an SMS message 

sendSms
<twilioRest.sendSms> 
    <messageBody>{$ctx:messageBody}</messageBody>
    <to>{$ctx:to}</to> 
    <from>{$ctx:from}</from> 
    <statusCallbackUrl>{$ctx:statusCallbackUrl}</statusCallBackUrl> 
    <applicationSid>{$ctx:applicationSid}</applicationSid>  	
</twilioRest.sendSms>

To send an SMS message, use twilioRest.sendSms and specify the following properties.

Properties
  • messageBody: The text of the message you want to send, up to 160 characters.
  • to: The destination phone number. Format with a '+' and country code, e.g., +16175551212 (E.164 format). For 'To' numbers without a '+', Twilio will use the same country code as the 'From' number. Twilio will also attempt to handle locally formatted numbers for that country code (e.g., (415) 555-1212 for US, 07400123456 for GB). If you are sending to a different country than the 'From' number, you must include a '+' and the country code to ensure proper delivery.
  • from: A Twilio phone number enabled for SMS. Only phone numbers  purchased from Twilio work here; for example, you cannot spoof SMS messages from your own cell phone number.
  • statusCallbackUrl: Optional. A URL that Twilio will POST to when your message is processed. Twilio will POST the SMS SID as well as status sent or failed.
  • applicationSid: Optional. Twilio will POST the SMS SID as well as status sent or failed to the URL in the SMS status callback property of this application. If the statusCallBackUrl parameter above is also passed, the application's SMS status callback parameter will take precedence.
Sample request

Following is a sample REST/JSON request that can be handled by the sendSms operation.

Sample Request for sendSms
{
	"accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6",
	"authToken":"cdd1fdb143d482a05e4f1f6fdb195395",
	"apiUrl":"https://api.twilio.com",
	"apiVersion":"2010-04-01",
	"messageBody":"Hi ,Test for sendSms",
	"to":"+447891063180",
	"from":"+442033229574",
	"statusCallbackUrl":"http://demo.twilio.com/docs/statuscallback.xml",
	"applicationSid":"AP2a0747eba6abf96b7e3c3ff0b4530f6e"
}
Related Twilio documentation

https://www.twilio.com/docs/api/rest/sending-sms

Getting a list of SMS messages 

getSmsList
<twilioRest.getSmsList> 
    <to>{$ctx:to}</to> 
    <from>{$ctx:from}</from> 
    <dateSent>{$ctx:dateSent}</dateSent> 
</twilioRest.getSmsList>

To get a list of SMS messages associated with this account, including the SID, status, and more for each message, use twilioRest.getSmsList and specify the following properties. The list includes paging information.

Properties
  • to: Optional. Only shows messages to the specified phone number.
  • from: Optional. Only shows messages from the specified phone number.
  • dateSent: Optional. Only shows messages sent on this date (in GMT format), given as YYYY-MM-DD. You can also specify inequality, such as <=YYYY-MM-DD for SMS messages that were sent on or before midnight on a date, and >=YYYY-MM-DD for SMS messages sent on or after midnight on a date.
Sample request

Following is a sample REST/JSON request that can be handled by the getSmsList operation.

Sample Request for getSmsList
{
	"accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6",
	"authToken":"cdd1fdb143d482a05e4f1f6fdb195395",
	"apiUrl":"https://api.twilio.com",
	"apiVersion":"2010-04-01",
	"to":"+447891063180",
	"from":"+442033229574",
	"dateSent":"2015-08-25"
}
Related Twilio documentation

https://www.twilio.com/docs/api/rest/sms#list-get

Getting a specific SMS message 

getSms
<twilioRest.getSms> 
    <messageSid>{$ctx:messageSid}</messageSid> 
</twilioRest.getSms>

To get information about a specific SMS message, including the SID, status, and more, use twilioRest.getSms and specify the following properties.

Properties
  • messageSid: The 34-character string that uniquely identifies this SMS message.
Sample request

Following is a sample REST/JSON request that can be handled by the getSms operation.

Sample Request for getSms
{
	"accountSid":"AC3c4055d0dd73aab7b5b1b26c0794e9c6",
	"authToken":"cdd1fdb143d482a05e4f1f6fdb195395",
	"apiUrl":"https://api.twilio.com",
	"apiVersion":"2010-04-01",
	"messageSid":"SM9e1e9c906e2d477c992ac05ab88d3ffb"
}
Related Twilio documentation

https://www.twilio.com/docs/api/rest/sms#instance-get

Sample configuration

Following is a sample proxy service that illustrates how to connect to TwilioRest with the init operation and use the sendsms operation. The sample request for this proxy can be found in sendSms sample request. You can use this sample as a template for using other operations in this category.

Sample Proxy
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="twilioRest"
       transports="https,http" statistics="disable" trace="disable"
       startOnLoad="true">
    <target>
        <inSequence onError="faultHandlerSeq">
            <property name="accountSid" expression="//accountSid/text()"/>
            <property name="authToken" expression="//authToken/text()"/>
            <property name="apiUrl" expression="//apiUrl/text()"/>
            <property name="apiVersion" expression="//apiVersion/text()"/>
            <property name="messageBody" expression="//messageBody/text()"/>
			<property name="to" expression="//to/text()"/>
			<property name="from" expression="//from/text()"/>
			<property name="statusCallbackUrl" expression="//statusCallbackUrl/text()"/>
			<property name="applicationSid" expression="//applicationSid/text()"/>      
            <twilioRest.init>
                <accountSid>{$ctx:accountSid}</accountSid>
                <authToken>{$ctx:authToken}</authToken>
                <apiUrl>{$ctx:apiUrl}</apiUrl>
                <apiVersion>{$ctx:apiVersion}</apiVersion>
            </twilioRest.init>
            <twilioRest.sendSms>
    			<messageBody>{$ctx:messageBody}</messageBody>
    			<to>{$ctx:to}</to>
    			<from>{$ctx:from}</from>
    			<statusCallbackUrl>{$ctx:statusCallbackUrl}</statusCallbackUrl>
    			<applicationSid>{$ctx:applicationSid}</applicationSid>
			</twilioRest.sendSms>       
            <respond/>
        </inSequence>
        <outSequence>
            <log/>
            <send/>
        </outSequence>
    </target>
    <description/>
</proxy>