class Twilio::REST::Api::V2010::AccountContext::MessageList
Public Class Methods
Initialize the MessageList
@param [Version] version Version
that contains the resource @param [String] account_sid The SID of the
{Account}[https://www.twilio.com/docs/iam/api/account] that sent the message that created the resource.
@return [MessageList] MessageList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/api/v2010/account/message.rb 22 def initialize(version, account_sid: nil) 23 super(version) 24 25 # Path Solution 26 @solution = {account_sid: account_sid} 27 @uri = "/Accounts/#{@solution[:account_sid]}/Messages.json" 28 end
Public Instance Methods
Create the MessageInstance
@param [String] to The destination phone number in
{E.164}[https://www.twilio.com/docs/glossary/what-e164] format for SMS/MMS or {Channel user address}[https://www.twilio.com/docs/sms/channels#channel-addresses] for other 3rd-party channels.
@param [String] status_callback The URL we should call using the
`status_callback_method` to send status information to your application. If specified, we POST these message status changes to the URL: `queued`, `failed`, `sent`, `delivered`, or `undelivered`. Twilio will POST its {standard request parameters}[https://www.twilio.com/docs/sms/twiml#request-parameters] as well as some additional parameters including `MessageSid`, `MessageStatus`, and `ErrorCode`. If you include this parameter with the `messaging_service_sid`, we use this URL instead of the Status Callback URL of the {Messaging Service}[https://www.twilio.com/docs/sms/services/api]. URLs must contain a valid hostname and underscores are not allowed.
@param [String] application_sid The SID of the application that should receive
message status. We POST a `message_sid` parameter and a `message_status` parameter with a value of `sent` or `failed` to the {application}[https://www.twilio.com/docs/usage/api/applications]'s `message_status_callback`. If a `status_callback` parameter is also passed, it will be ignored and the application's `message_status_callback` parameter will be used.
@param [String] max_price The maximum total price in US dollars that you will
pay for the message to be delivered. Can be a decimal value that has up to 4 decimal places. All messages are queued for delivery and the message cost is checked before the message is sent. If the cost exceeds `max_price`, the message will fail and a status of `Failed` is sent to the status callback. If `MaxPrice` is not set, the message cost is not checked.
@param [Boolean] provide_feedback Whether to confirm delivery of the message.
Set this value to `true` if you are sending messages that have a trackable user action and you intend to confirm delivery of the message using the {Message Feedback API}[https://www.twilio.com/docs/sms/api/message-feedback-resource]. This parameter is `false` by default.
@param [String] attempt Total number of attempts made ( including this ) to send
out the message regardless of the provider used
@param [String] validity_period How long in seconds the message can remain in
our outgoing message queue. After this period elapses, the message fails and we call your status callback. Can be between 1 and the default value of 14,400 seconds. After a message has been accepted by a carrier, however, we cannot guarantee that the message will not be queued after this period. We recommend that this value be at least 5 seconds.
@param [Boolean] force_delivery Reserved @param [message.ContentRetention] content_retention Determines if the message
content can be stored or redacted based on privacy settings
@param [message.AddressRetention] address_retention Determines if the address
can be stored or obfuscated based on privacy settings
@param [Boolean] smart_encoded Whether to detect Unicode characters that have a
similar GSM-7 character and replace them. Can be: `true` or `false`.
@param [Array] persistent_action Rich actions for Channels Messages. @param [String] from A Twilio
phone number in
{E.164}[https://www.twilio.com/docs/glossary/what-e164] format, an {alphanumeric sender ID}[https://www.twilio.com/docs/sms/send-messages#use-an-alphanumeric-sender-id], or a {Channel Endpoint address}[https://www.twilio.com/docs/sms/channels#channel-addresses] that is enabled for the type of message you want to send. Phone numbers or {short codes}[https://www.twilio.com/docs/sms/api/short-code] purchased from Twilio also work here. You cannot, for example, spoof messages from a private cell phone number. If you are using `messaging_service_sid`, this parameter must be empty.
@param [String] messaging_service_sid The SID of the {Messaging
Service}[https://www.twilio.com/docs/sms/services#send-a-message-with-copilot] you want to associate with the Message. Set this parameter to use the {Messaging Service Settings and Copilot Features}[https://www.twilio.com/console/sms/services] you have configured and leave the `from` parameter empty. When only this parameter is set, Twilio will use your enabled Copilot Features to select the `from` phone number for delivery.
@param [String] body The text of the message you want to send. Can be up to
1,600 characters in length.
@param [Array] media_url The URL of the media to send with the message.
The media can be of type `gif`, `png`, and `jpeg` and will be formatted correctly on the recipient's device. The media size limit is 5MB for supported file types (JPEG, PNG, GIF) and 500KB for {other types}[https://www.twilio.com/docs/sms/accepted-mime-types] of accepted media. To send more than one image in the message body, provide multiple `media_url` parameters in the POST request. You can include up to 10 `media_url` parameters per message. You can send images in an SMS message in only the US and Canada.
@return [MessageInstance] Created MessageInstance
# File lib/twilio-ruby/rest/api/v2010/account/message.rb 111 def create(to: nil, status_callback: :unset, application_sid: :unset, max_price: :unset, provide_feedback: :unset, attempt: :unset, validity_period: :unset, force_delivery: :unset, content_retention: :unset, address_retention: :unset, smart_encoded: :unset, persistent_action: :unset, from: :unset, messaging_service_sid: :unset, body: :unset, media_url: :unset) 112 data = Twilio::Values.of({ 113 'To' => to, 114 'From' => from, 115 'MessagingServiceSid' => messaging_service_sid, 116 'Body' => body, 117 'MediaUrl' => Twilio.serialize_list(media_url) { |e| e }, 118 'StatusCallback' => status_callback, 119 'ApplicationSid' => application_sid, 120 'MaxPrice' => max_price, 121 'ProvideFeedback' => provide_feedback, 122 'Attempt' => attempt, 123 'ValidityPeriod' => validity_period, 124 'ForceDelivery' => force_delivery, 125 'ContentRetention' => content_retention, 126 'AddressRetention' => address_retention, 127 'SmartEncoded' => smart_encoded, 128 'PersistentAction' => Twilio.serialize_list(persistent_action) { |e| e }, 129 }) 130 131 payload = @version.create('POST', @uri, data: data) 132 133 MessageInstance.new(@version, payload, account_sid: @solution[:account_sid], ) 134 end
When passed a block, yields MessageInstance
records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.
# File lib/twilio-ruby/rest/api/v2010/account/message.rb 201 def each 202 limits = @version.read_limits 203 204 page = self.page(page_size: limits[:page_size], ) 205 206 @version.stream(page, 207 limit: limits[:limit], 208 page_limit: limits[:page_limit]).each {|x| yield x} 209 end
Retrieve a single page of MessageInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of MessageInstance
# File lib/twilio-ruby/rest/api/v2010/account/message.rb 246 def get_page(target_url) 247 response = @version.domain.request( 248 'GET', 249 target_url 250 ) 251 MessagePage.new(@version, response, @solution) 252 end
Lists MessageInstance
records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. @param [String] to Read messages sent to only this phone number. @param [String] from Read messages sent from only this phone number or
alphanumeric sender ID.
@param [Time] date_sent_before Filter by date sent @param [Time] date_sent Filter by date sent @param [Time] date_sent_after Filter by date sent @param [Integer] limit Upper limit for the number of records to return. stream()
guarantees to never return more than limit. Default is no limit
@param [Integer] page_size Number of records to fetch per request, when
not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000)
@return [Array] Array of up to limit results
# File lib/twilio-ruby/rest/api/v2010/account/message.rb 153 def list(to: :unset, from: :unset, date_sent_before: :unset, date_sent: :unset, date_sent_after: :unset, limit: nil, page_size: nil) 154 self.stream( 155 to: to, 156 from: from, 157 date_sent_before: date_sent_before, 158 date_sent: date_sent, 159 date_sent_after: date_sent_after, 160 limit: limit, 161 page_size: page_size 162 ).entries 163 end
Retrieve a single page of MessageInstance
records from the API. Request
is executed immediately. @param [String] to Read messages sent to only this phone number. @param [String] from Read messages sent from only this phone number or
alphanumeric sender ID.
@param [Time] date_sent_before Filter by date sent @param [Time] date_sent Filter by date sent @param [Time] date_sent_after Filter by date sent @param [String] page_token PageToken provided by the API @param [Integer] page_number Page
Number, this value is simply for client state @param [Integer] page_size Number of records to return, defaults to 50 @return [Page] Page
of MessageInstance
# File lib/twilio-ruby/rest/api/v2010/account/message.rb 224 def page(to: :unset, from: :unset, date_sent_before: :unset, date_sent: :unset, date_sent_after: :unset, page_token: :unset, page_number: :unset, page_size: :unset) 225 params = Twilio::Values.of({ 226 'To' => to, 227 'From' => from, 228 'DateSent<' => Twilio.serialize_iso8601_datetime(date_sent_before), 229 'DateSent' => Twilio.serialize_iso8601_datetime(date_sent), 230 'DateSent>' => Twilio.serialize_iso8601_datetime(date_sent_after), 231 'PageToken' => page_token, 232 'Page' => page_number, 233 'PageSize' => page_size, 234 }) 235 236 response = @version.page('GET', @uri, params: params) 237 238 MessagePage.new(@version, response, @solution) 239 end
Streams MessageInstance
records from the API as an Enumerable. This operation lazily loads records as efficiently as possible until the limit is reached. @param [String] to Read messages sent to only this phone number. @param [String] from Read messages sent from only this phone number or
alphanumeric sender ID.
@param [Time] date_sent_before Filter by date sent @param [Time] date_sent Filter by date sent @param [Time] date_sent_after Filter by date sent @param [Integer] limit Upper limit for the number of records to return. stream()
guarantees to never return more than limit. Default is no limit.
@param [Integer] page_size Number of records to fetch per request, when
not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000)
@return [Enumerable] Enumerable that will yield up to limit results
# File lib/twilio-ruby/rest/api/v2010/account/message.rb 182 def stream(to: :unset, from: :unset, date_sent_before: :unset, date_sent: :unset, date_sent_after: :unset, limit: nil, page_size: nil) 183 limits = @version.read_limits(limit, page_size) 184 185 page = self.page( 186 to: to, 187 from: from, 188 date_sent_before: date_sent_before, 189 date_sent: date_sent, 190 date_sent_after: date_sent_after, 191 page_size: limits[:page_size], 192 ) 193 194 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 195 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/api/v2010/account/message.rb 256 def to_s 257 '#<Twilio.Api.V2010.MessageList>' 258 end