class Twilio::REST::Conversations::V1::ServiceContext::ConversationContext::MessageList

Public Class Methods

new(version, chat_service_sid: nil, conversation_sid: nil) click to toggle source

Initialize the MessageList @param [Version] version Version that contains the resource @param [String] chat_service_sid The SID of the {Conversation

Service}[https://www.twilio.com/docs/conversations/api/service-resource] the
Participant resource is associated with.

@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

Calls superclass method Twilio::REST::ListResource::new
   # File lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb
26 def initialize(version, chat_service_sid: nil, conversation_sid: nil)
27   super(version)
28 
29   # Path Solution
30   @solution = {chat_service_sid: chat_service_sid, conversation_sid: conversation_sid}
31   @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations/#{@solution[:conversation_sid]}/Messages"
32 end

Public Instance Methods

create(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, media_sid: :unset, x_twilio_webhook_enabled: :unset) click to toggle source

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/service/conversation/message.rb
50 def create(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, media_sid: :unset, x_twilio_webhook_enabled: :unset)
51   data = Twilio::Values.of({
52       'Author' => author,
53       'Body' => body,
54       'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
55       'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
56       'Attributes' => attributes,
57       'MediaSid' => media_sid,
58   })
59   headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
60 
61   payload = @version.create('POST', @uri, data: data, headers: headers)
62 
63   MessageInstance.new(
64       @version,
65       payload,
66       chat_service_sid: @solution[:chat_service_sid],
67       conversation_sid: @solution[:conversation_sid],
68   )
69 end
each() { |x| ... } click to toggle source

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/service/conversation/message.rb
113 def each
114   limits = @version.read_limits
115 
116   page = self.page(page_size: limits[:page_size], )
117 
118   @version.stream(page,
119                   limit: limits[:limit],
120                   page_limit: limits[:page_limit]).each {|x| yield x}
121 end
get_page(target_url) click to toggle source

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/service/conversation/message.rb
150 def get_page(target_url)
151   response = @version.domain.request(
152       'GET',
153       target_url
154   )
155   MessagePage.new(@version, response, @solution)
156 end
list(order: :unset, limit: nil, page_size: nil) click to toggle source

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/service/conversation/message.rb
84 def list(order: :unset, limit: nil, page_size: nil)
85   self.stream(order: order, limit: limit, page_size: page_size).entries
86 end
page(order: :unset, page_token: :unset, page_number: :unset, page_size: :unset) click to toggle source

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/service/conversation/message.rb
132 def page(order: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
133   params = Twilio::Values.of({
134       'Order' => order,
135       'PageToken' => page_token,
136       'Page' => page_number,
137       'PageSize' => page_size,
138   })
139 
140   response = @version.page('GET', @uri, params: params)
141 
142   MessagePage.new(@version, response, @solution)
143 end
stream(order: :unset, limit: nil, page_size: nil) click to toggle source

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/service/conversation/message.rb
101 def stream(order: :unset, limit: nil, page_size: nil)
102   limits = @version.read_limits(limit, page_size)
103 
104   page = self.page(order: order, page_size: limits[:page_size], )
105 
106   @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
107 end
to_s() click to toggle source

Provide a user friendly representation

    # File lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb
160 def to_s
161   '#<Twilio.Conversations.V1.MessageList>'
162 end