Twilio

Sms Verb - Sent In Call

The <Sms> verb sends a SMS message to a phone number.

Nouns

The "Noun" of a Twilio verb is the body of the element, the thing the verb acts upon. In the case of <Sms>, the noun is the text you wish to be sent.

Form Parameters

If an action URL attribute is provided, <Sms> will submit the following parameters on completion.

Form Parameters
Parameter Description
SmsSid The Sid for the SMS message
SmsStatus The current status of the SMS message
Possible SmsStatus Values
Value Description
sending The message has been added to the message queue and will be delivered shortly
invalid Twilio was unable to deliver the message because one or more attributes you provided were not valid

See Also

Twilio SMS Messages Resource - Sending outbound SMS messages

Verb Attributes

The following optional XML attributes may be used with the <Sms> verb to change its behavior:

SMS Attributes
Attribute Name Allowed Values Default Value
to phone number see below
from phone number see below
action relative or absolute URL none
method GET, POST POST
statusCallback relative or absolute URL none

to

The 'to' attribute takes a valid phone number as an argument. Twilio will send the SMS to the number provided. If no 'to' attribute is provided, Twilio will pick a default: When sending an SMS in response to an incoming SMS, 'to' defaults to the current sender.

Note: If your account is a Free Trial account, the provided 'To' phone number must be [validated with Twilio](../user/account/phone-numbers/). You can however, reply to an SMS to any phone without explicitly specifying a 'To' number.

from

The 'from' attribute takes a valid phone number as an argument. This number must be a phone number that you've purchased from Twilio. If no from attribute is provided, Twilio will pick a default: When sending an SMS in response to an incoming SMS, 'from' defaults to phone number that received the message. If you specify a 'from' value, it must be an SMS-capable local phone number assigned to your account. If the phone number isn't SMS-capable, then <Sms> will not send an SMS message.

action

The action attribute takes a URL as an argument. After processing the <Sms>,Twilio will make a GET or POST request to this URL with the form parameters "SmsStatus" and "SmsSid". Using an 'action,' your application can receive a synchronous feedback as to if the message was successfully enqueued. If no action is provided, <Sms> will unconditionally move on to the next verb in the document.

method

The method attribute takes the value GET or POST. This tells Twilio whether to submit the action URL as a GET or POST method. This attribute is modeled after the HTML form method attribute. POST is the default value.

statusCallback{#statusCallback}

The statusCallback attribute takes a URL as an argument. When the message is actually sent, or if sending fails, Twilio will make POST request to this URL with the form parameters 'SmsStatus' and 'SmsSid'. Note, statusCallback always uses HTTP POST to request the given url.

Nesting Rules

The <Sms> verb can be nested in the following elements:

No elements may be nested within <Sms>

See Also

Twilio SMS Messages REST Resource - Using REST to retrieve and send SMS message

Examples

Example 1: Simple SMS use case

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Sms>Store Location: 123 Easy St.</SMS>
</Response>    

This is the simplest case for <Sms>. Twilio sends an SMS with the location of your wonderful retail establishment.

Example 2: SmsStatus reporting

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Sms action="/SmsHandler.php" method="POST">Store Location: 123 Easy St.</Sms>
</Response>

In this use case, we have provided an action url and method. Now when the message is queued for delivery, Twilio will submit to the action URL with the parameter 'SmsStatus'. If the messages is queued and waiting to be sent, SmsStatus=sending. If an invalid attribute was provided, then SmsStatus=invalid.

Your web application can look at the 'SmsStatus' parameter and decide what to do next.

If an action URL is provided for <Sms>, flow of your application will continue at that URL. All verbs remaining in the document will be unreachable and ignored.

Example 3: statusCallback reporting

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Sms statusCallback="/SMSHandler.php">Store Location: 123 Easy St.</SMS>
</Response>

In this use case, we have provided a statusCallback url. When the message is finished sending (not just enqueued), Twilio will asynchronously submit to the action URL with the parameter SmsStatus. If the messages was successfully sent, SmsStatus=sent.
If the message failed to send, SmsStatus=failed.