NAME
Twilio::Rest::Api::V2010::Account::Message - The Message resource
SYNOPSIS
my $client = Twilio::Rest::Client->new($account_sid, $auth_token);
my $message = $client->messages->create($to, \%options);
for my $message ($client->messages->read({}, 20)) {
...
}
my $message = $client->messages($sid)->fetch;
$client->messages($sid)->update(\%options);
$client->messages($sid)->delete;
DESCRIPTION
A Message resource represents an inbound or outbound message.
This file holds MessageList, MessagePage, MessageContext and MessageInstance. Methods that make a request throw Twilio::Exceptions::RestException on an error response.
MessageList
Returned by $client->messages. See also Twilio::ListResource.
create
my $message = $client->messages->create($to, \%options);
Send a message. Returns a MessageInstance.
The required values are:
$to-
The recipient's phone number in E.164 format (for SMS/MMS) or channel address, e.g.
whatsapp:+15552229999.
The options are:
address_retention-
One of
retainorobfuscate. application_sid-
The SID of the associated TwiML Application. Message status callback requests are sent to the TwiML App's
message_status_callbackURL. Note that thestatus_callbackparameter of a request takes priority over theapplication_sidparameter; if both are includedapplication_sidis ignored. attempt-
Total number of attempts made (including this request) to send the message regardless of the provider used
body-
The text content of the outgoing message. Can be up to 1,600 characters in length. SMS only: If the
bodycontains more than 160 GSM-7 characters (or 70 UCS-2 characters), the message is segmented and charged accordingly. For longbodytext, consider using the send_as_mms parameter. content_retention-
One of
retainordiscard. content_sid-
For Content Editor/API only: The SID of the Content Template to be used with the Message, e.g.,
HXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. If this parameter is not provided, a Content Template is not used. Find the SID in the Console on the Content Editor page. For Content API users, the SID is found in Twilio's response when creating the Template or by fetching your Templates. content_variables-
For Content Editor/API only: Key-value pairs of Template variables and their substitution values.
content_sidparameter must also be provided. If values are not defined in thecontent_variablesparameter, the Template's default placeholder values are used. fallback_from-
A fallback SMS sender to use when the recipient cannot be reached over RCS. This parameter may only be used when also providing a Messaging Service containing an RCS sender. The fallback SMS sender must be either a Twilio phone number (in E.164 format), alphanumeric sender ID, or short code, hosted within Twilio and belong to the Account creating the Message.
force_delivery-
Reserved
from-
The sender's Twilio phone number (in E.164 format), alphanumeric sender ID, Wireless SIM, short code, or channel address (e.g.,
whatsapp:+15554449999). The value of thefromparameter must be a sender that is hosted within Twilio and belongs to the Account creating the Message. If you are usingmessaging_service_sid, this parameter can be empty (Twilio assigns afromvalue from the Messaging Service's Sender Pool) or you can provide a specific sender from your Sender Pool. max_price-
[OBSOLETE] This parameter will no longer have any effect as of 2024-06-03.
media_url-
The URL of media to include in the Message content.
jpeg,jpg,gif, andpngfile types are fully supported by Twilio and content is formatted for delivery on destination devices. The media size limit is 5 MB for supported file types (jpeg,jpg,png,gif) and 500 KB for other types of accepted media. To send more than one image in the message, provide multiplemedia_urlparameters in the POST request. You can include up to tenmedia_urlparameters per message. International and carrier limits apply. An array reference. message_intent-
Specifies the purpose or use case of the outbound communication. This parameter is used by Twilio's Traffic Shaping and Compliance Toolkit products. Possible values include:
otp,notifications,marketing,fraud,security,customercare,delivery,education,polling,announcements, andevents. messaging_service_sid-
The SID of the Messaging Service you want to associate with the Message. When this parameter is provided and the
fromparameter is omitted, Twilio selects the optimal sender from the Messaging Service's Sender Pool. You may also provide afromparameter if you want to use a specific Sender from the Sender Pool. persistent_action-
Rich actions for non-SMS/MMS channels. Used for sending location in WhatsApp messages. An array reference.
provide_feedback-
Boolean indicating whether or not you intend to provide delivery confirmation feedback to Twilio (used in conjunction with the Message Feedback subresource). Default value is
false. risk_check-
One of
enableordisable. schedule_type-
Must be
fixed. send_as_mms-
If set to
true, Twilio delivers the message as a single MMS message, regardless of the presence of media. send_at-
The time that Twilio will send the message. Must be in ISO 8601 format. A string, or an object with an
epochmethod. See "iso8601_date_time" in Twilio::Serialize. shorten_urls-
For Messaging Services with Link Shortening configured only: A Boolean indicating whether or not Twilio should shorten links in the
bodyof the Message. Default value isfalse. Iftrue, themessaging_service_sidparameter must also be provided. smart_encoded-
Whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be:
trueorfalse. status_callback-
The URL of the endpoint to which Twilio sends Message status callback requests. URL must contain a valid hostname and underscores are not allowed. If you include this parameter with the
messaging_service_sid, Twilio uses this URL instead of the Status Callback URL of the Messaging Service. traffic_type-
Must be
free. validity_period-
The maximum length in seconds that the Message can remain in Twilio's outgoing message queue. If a queued Message exceeds the
validity_period, the Message is not sent. Accepted values are integers from1to36000. Default value is36000. Avalidity_periodgreater than5is recommended. Learn more about the validity period
read
my @records = $client->messages->read(\%options, $limit, $page_size);
Retrieve a list of Message resources associated with a Twilio Account. Returns the records as a list, fetching as many pages as it needs.
The options are:
date_sent-
Filter by Message
sent_date. Accepts GMT dates in the following formats:YYYY-MM-DD(to find Messages with a specificsent_date),<=YYYY-MM-DD(to find Messages withsent_dates on and before a specific date), and>=YYYY-MM-DD(to find Messages withsent_dateson and after a specific date). A string, or an object with anepochmethod. See "iso8601_date_time" in Twilio::Serialize. date_sent_before-
Filter by Message
sent_date. Accepts GMT dates in the following formats:YYYY-MM-DD(to find Messages with a specificsent_date),<=YYYY-MM-DD(to find Messages withsent_dates on and before a specific date), and>=YYYY-MM-DD(to find Messages withsent_dateson and after a specific date). A string, or an object with anepochmethod. See "iso8601_date_time" in Twilio::Serialize. date_sent_after-
Filter by Message
sent_date. Accepts GMT dates in the following formats:YYYY-MM-DD(to find Messages with a specificsent_date),<=YYYY-MM-DD(to find Messages withsent_dates on and before a specific date), and>=YYYY-MM-DD(to find Messages withsent_dateson and after a specific date). A string, or an object with anepochmethod. See "iso8601_date_time" in Twilio::Serialize. from-
Filter by sender. For example: Set this parameter to
+15552229999to retrieve a list of Message resources sent by+15552229999. to-
Filter by recipient. For example: Set this parameter to
+15558881111to retrieve a list of Message resources sent to+15558881111.
stream
my $stream = $client->messages->stream(\%options, $limit, $page_size);
Takes the same arguments as "read", and returns a Twilio::Stream.
page
my $page = $client->messages->page(\%options, $page_size, $page_token, $page_number);
Fetches one page, and returns a Twilio::Page.
get_page
my $page = $client->messages->get_page($url);
Fetches the page at a URL given by Twilio.
get_context
my $context = $client->messages->get_context($sid);
Returns a MessageContext, and makes no request.
MessagePage
A Twilio::Page of MessageInstance objects.
records_key
build_instance
Used by Twilio::Page.
MessageContext
Returned by $client->messages($sid). It makes no request until one of these methods is called.
fetch
my $message = $client->messages($sid)->fetch;
Fetch a specific Message. Returns a MessageInstance.
update
my $message = $client->messages($sid)->update(\%options);
Update a Message resource (used to redact Message body text and to cancel not-yet-sent messages). Returns a MessageInstance.
The options are:
body-
The new
bodyof the Message resource. To redact the text content of a Message, this parameter's value must be an empty string status-
Must be
canceled.
delete
$client->messages($sid)->delete;
Deletes a Message resource from your account. Returns true.
feedback
my $list = $object->feedback;
See Twilio::Rest::Api::V2010::Account::Message::Feedback.
media
my $list = $object->media;
my $context = $object->media($sid);
See Twilio::Rest::Api::V2010::Account::Message::Media.
MessageInstance
See also Twilio::InstanceResource.
It has fetch, update, delete, feedback and media, which work as they do on the context.
Its fields are:
- account_sid
-
The SID of the Account associated with the Message resource
- api_version
-
The API version used to process the Message
- body
-
The text content of the message
- date_created
-
The RFC 2822 timestamp (in GMT) of when the Message resource was created A Time::Piece object in UTC. See "date_time" in Twilio::Deserialize.
- date_sent
-
The RFC 2822 timestamp (in GMT) of when the Message was sent. For an outgoing message, this is when Twilio sent the message. For an incoming message, this is when Twilio sent the HTTP request to your incoming message webhook URL. A Time::Piece object in UTC. See "date_time" in Twilio::Deserialize.
- date_updated
-
The RFC 2822 timestamp (in GMT) of when the Message resource was last updated A Time::Piece object in UTC. See "date_time" in Twilio::Deserialize.
- direction
-
One of
inbound,outbound-api,outbound-calloroutbound-reply. - error_code
-
The error code returned if the Message
statusisfailedorundelivered. If no error was encountered, the value isnull. The value returned in this field for a specific error cause is subject to change as Twilio improves errors. Users should not use theerror_codeanderror_messagefields programmatically. - error_message
-
The description of the
error_codeif the Messagestatusisfailedorundelivered. If no error was encountered, the value isnull. The value returned in this field for a specific error cause is subject to change as Twilio improves errors. Users should not use theerror_codeanderror_messagefields programmatically. - from
-
The sender's phone number (in E.164 format), alphanumeric sender ID, Wireless SIM, short code, or channel address (e.g.,
whatsapp:+15554449999). For incoming messages, this is the number or channel address of the sender. For outgoing messages, this value is a Twilio phone number, alphanumeric sender ID, short code, or channel address from which the message is sent. - messaging_service_sid
-
The SID of the Messaging Service associated with the Message resource. A unique default value is assigned if a Messaging Service is not used.
- num_media
-
The number of media files associated with the Message resource.
- num_segments
-
The number of segments that make up the complete message. SMS message bodies that exceed the character limit are segmented and charged as multiple messages. Note: For messages sent via a Messaging Service,
num_segmentsis initially0, since a sender hasn't yet been assigned. - price
-
The amount billed for the message in the currency specified by
price_unit. Thepriceis populated after the message has been sent/received, and may not be immediately availalble. View the Pricing page for more details. - price_unit
-
The currency in which
priceis measured, in ISO 4127 format (e.g.usd,eur,jpy). - sid
-
The unique, Twilio-provided string that identifies the Message resource.
- status
-
One of
queued,sending,sent,failed,delivered,undelivered,receiving,received,accepted,scheduled,read,partially_deliveredorcanceled. - subresource_uris
-
A list of related resources identified by their URIs relative to
https://api.twilio.com - to
-
The recipient's phone number (in E.164 format) or channel address (e.g.
whatsapp:+15552229999) - uri
-
The URI of the Message resource, relative to
https://api.twilio.com.
CONSTRUCTORS
new
Objects here come from the methods above, so there is no need to call new directly.
LICENSE
Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.