class Twilio::REST::Conversations::V1::ConversationContext::MessageList
Public Class Methods
Initialize the MessageList
@param [Version] version Version
that contains the resource @param [String] conversation_sid The unique ID of the
{Conversation}[https://www.twilio.com/docs/conversations/api/conversation-resource] for this message.
@return [MessageList] MessageList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/conversations/v1/conversation/message.rb 22 def initialize(version, conversation_sid: nil) 23 super(version) 24 25 # Path Solution 26 @solution = {conversation_sid: conversation_sid} 27 @uri = "/Conversations/#{@solution[:conversation_sid]}/Messages" 28 end
Public Instance Methods
Create the MessageInstance
@param [String] author The channel specific identifier of the message's author.
Defaults to `system`.
@param [String] body The content of the message, can be up to 1,600 characters
long.
@param [Time] date_created The date that this resource was created. @param [Time] date_updated The date that this resource was last updated. `null`
if the message has not been edited.
@param [String] attributes A string metadata field you can use to store any data
you wish. The string value must contain structurally valid JSON if specified. **Note** that if the attributes are not set "{}" will be returned.
@param [String] media_sid The Media SID to be attached to the new Message. @param [message.WebhookEnabledType] x_twilio_webhook_enabled The
X-Twilio-Webhook-Enabled HTTP request header
@return [MessageInstance] Created MessageInstance
# File lib/twilio-ruby/rest/conversations/v1/conversation/message.rb 46 def create(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, media_sid: :unset, x_twilio_webhook_enabled: :unset) 47 data = Twilio::Values.of({ 48 'Author' => author, 49 'Body' => body, 50 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created), 51 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated), 52 'Attributes' => attributes, 53 'MediaSid' => media_sid, 54 }) 55 headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) 56 57 payload = @version.create('POST', @uri, data: data, headers: headers) 58 59 MessageInstance.new(@version, payload, conversation_sid: @solution[:conversation_sid], ) 60 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/conversations/v1/conversation/message.rb 104 def each 105 limits = @version.read_limits 106 107 page = self.page(page_size: limits[:page_size], ) 108 109 @version.stream(page, 110 limit: limits[:limit], 111 page_limit: limits[:page_limit]).each {|x| yield x} 112 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/conversations/v1/conversation/message.rb 141 def get_page(target_url) 142 response = @version.domain.request( 143 'GET', 144 target_url 145 ) 146 MessagePage.new(@version, response, @solution) 147 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 [message.OrderType] order The sort order of the returned messages. Can
be: `asc` (ascending) or `desc` (descending), with `asc` as the default.
@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/conversations/v1/conversation/message.rb 75 def list(order: :unset, limit: nil, page_size: nil) 76 self.stream(order: order, limit: limit, page_size: page_size).entries 77 end
Retrieve a single page of MessageInstance
records from the API. Request
is executed immediately. @param [message.OrderType] order The sort order of the returned messages. Can
be: `asc` (ascending) or `desc` (descending), with `asc` as the default.
@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/conversations/v1/conversation/message.rb 123 def page(order: :unset, page_token: :unset, page_number: :unset, page_size: :unset) 124 params = Twilio::Values.of({ 125 'Order' => order, 126 'PageToken' => page_token, 127 'Page' => page_number, 128 'PageSize' => page_size, 129 }) 130 131 response = @version.page('GET', @uri, params: params) 132 133 MessagePage.new(@version, response, @solution) 134 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 [message.OrderType] order The sort order of the returned messages. Can
be: `asc` (ascending) or `desc` (descending), with `asc` as the default.
@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/conversations/v1/conversation/message.rb 92 def stream(order: :unset, limit: nil, page_size: nil) 93 limits = @version.read_limits(limit, page_size) 94 95 page = self.page(order: order, page_size: limits[:page_size], ) 96 97 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 98 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/conversations/v1/conversation/message.rb 151 def to_s 152 '#<Twilio.Conversations.V1.MessageList>' 153 end