Twilio. Messages
(twilio v0.2.0)
Copy Markdown
API calls: create, delete, feedback, list, retrieve, update.
Summary
Functions
Send a message
Like create/2, but returns the result or raises Infusion.Runtime.Error.
Deletes a Message resource from your account
Like delete/2, but returns the result or raises Infusion.Runtime.Error.
Create Message Feedback to confirm a tracked user action was performed by the recipient of the associated Message
Like feedback/3, but returns the result or raises Infusion.Runtime.Error.
Retrieve a list of Message resources associated with a Twilio Account
Like list/2, but returns the result or raises Infusion.Runtime.Error.
Like list/2, but returns every item, from every page: a lazy stream of Twilio.Schemas.Message.t() that fetches pages as it is read.
Like list_all/2, but returns the stream or raises Infusion.Runtime.Error.
Fetch a specific Message
Like retrieve/2, but returns the result or raises Infusion.Runtime.Error.
Update a Message resource (used to redact Message body text and to cancel not-yet-sent messages)
Like update/3, but returns the result or raises Infusion.Runtime.Error.
Functions
@spec create(map() | keyword(), keyword()) :: {:ok, Twilio.Schemas.Message.t()} | {:error, Infusion.Runtime.Error.t()}
Send a message
POST /2010-04-01/Accounts/{AccountSid}/Messages.json
{AccountSid} in the path is the :account_sid setting; pass account_sid: "..." as an option to use another.
Parameters
address_retentionapplication_sid- The SID of the associated TwiML Application. Message status callback requests are sent to the TwiML App'smessage_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 usedbody- The text content of the outgoing message. Can be up to 1,600 characters in length. SMS only: If thebodycontains 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_retentioncontent_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- Reservedfrom- 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.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 thefromparameter 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.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 isfalse.risk_checkschedule_typesend_as_mms- If set totrue, 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.shorten_urls- For Messaging Services with Link Shortening configured only: A Boolean indicating whether or not Twilio should shorten links in thebodyof 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 themessaging_service_sid, Twilio uses this URL instead of the Status Callback URL of the Messaging Service.to(required) - The recipient's phone number in E.164 format (for SMS/MMS) or channel address, e.g.whatsapp:+15552229999.traffic_typevalidity_period- The maximum length in seconds that the Message can remain in Twilio's outgoing message queue. If a queued Message exceeds thevalidity_period, the Message is not sent. Accepted values are integers from1to36000. Default value is36000. Avalidity_periodgreater than5is recommended. Learn more about the validity period
@spec create!(map() | keyword(), keyword()) :: Twilio.Schemas.Message.t()
Like create/2, but returns the result or raises Infusion.Runtime.Error.
@spec delete(String.t(), keyword()) :: {:ok, nil} | {:error, Infusion.Runtime.Error.t()}
Deletes a Message resource from your account
DELETE /2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json
Path parameters
sid(required) - The SID of the Message resource you wish to delete
{AccountSid} in the path is the :account_sid setting; pass account_sid: "..." as an option to use another.
Like delete/2, but returns the result or raises Infusion.Runtime.Error.
@spec feedback(String.t(), map() | keyword(), keyword()) :: {:ok, Twilio.Schemas.MessageFeedback.t()} | {:error, Infusion.Runtime.Error.t()}
Create Message Feedback to confirm a tracked user action was performed by the recipient of the associated Message
POST /2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Feedback.json
Path parameters
message_sid(required) - The SID of the Message resource for which to create MessageFeedback.
{AccountSid} in the path is the :account_sid setting; pass account_sid: "..." as an option to use another.
Parameters
outcome
@spec feedback!(String.t(), map() | keyword(), keyword()) :: Twilio.Schemas.MessageFeedback.t()
Like feedback/3, but returns the result or raises Infusion.Runtime.Error.
@spec list(map() | keyword(), keyword()) :: {:ok, Twilio.Schemas.MessagesListResponse.t()} | {:error, Infusion.Runtime.Error.t()}
Retrieve a list of Message resources associated with a Twilio Account
GET /2010-04-01/Accounts/{AccountSid}/Messages.json
{AccountSid} in the path is the :account_sid setting; pass account_sid: "..." as an option to use another.
Parameters
to- Filter by recipient. For example: Set this parameter to+15558881111to retrieve a list of Message resources sent to+15558881111.from- Filter by sender. For example: Set this parameter to+15552229999to retrieve a list of Message resources sent by+15552229999.date_sent- Filter by Messagesent_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).date_sent_query- Filter by Messagesent_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).date_sent_query_2- Filter by Messagesent_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).page_size- How many resources to return in each list page. The default is 50, and the maximum is 1000.page- The page index. This value is simply for client state.page_token- The page token. This is provided by the API.
To read every item across all pages, use list_all.
@spec list!(map() | keyword(), keyword()) :: Twilio.Schemas.MessagesListResponse.t()
Like list/2, but returns the result or raises Infusion.Runtime.Error.
@spec list_all(map() | keyword(), keyword()) :: {:ok, Enumerable.t()} | {:error, Infusion.Runtime.Error.t()}
Like list/2, but returns every item, from every page: a lazy stream of Twilio.Schemas.Message.t() that fetches pages as it is read.
The first page is fetched right away, so its errors are returned; a later page that fails raises Infusion.Runtime.Error. Stopping early (Enum.take/2) fetches no more pages.
@spec list_all!(map() | keyword(), keyword()) :: Enumerable.t()
Like list_all/2, but returns the stream or raises Infusion.Runtime.Error.
@spec retrieve(String.t(), keyword()) :: {:ok, Twilio.Schemas.Message.t()} | {:error, Infusion.Runtime.Error.t()}
Fetch a specific Message
GET /2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json
Path parameters
sid(required) - The SID of the Message resource to be fetched
{AccountSid} in the path is the :account_sid setting; pass account_sid: "..." as an option to use another.
@spec retrieve!(String.t(), keyword()) :: Twilio.Schemas.Message.t()
Like retrieve/2, but returns the result or raises Infusion.Runtime.Error.
@spec update(String.t(), map() | keyword(), keyword()) :: {:ok, Twilio.Schemas.Message.t()} | {:error, Infusion.Runtime.Error.t()}
Update a Message resource (used to redact Message body text and to cancel not-yet-sent messages)
POST /2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json
Path parameters
sid(required) - The SID of the Message resource to be updated
{AccountSid} in the path is the :account_sid setting; pass account_sid: "..." as an option to use another.
Parameters
body- The newbodyof the Message resource. To redact the text content of a Message, this parameter's value must be an empty stringstatus
@spec update!(String.t(), map() | keyword(), keyword()) :: Twilio.Schemas.Message.t()
Like update/3, but returns the result or raises Infusion.Runtime.Error.