class Twilio::REST::Chat::V2::ServiceContext::ChannelContext::MessageList
Public Class Methods
Initialize the MessageList
@param [Version] version Version
that contains the resource @param [String] service_sid The SID of the
{Service}[https://www.twilio.com/docs/chat/rest/service-resource] the Message resource is associated with.
@param [String] channel_sid The SID of the
{Channel}[https://www.twilio.com/docs/chat/channels] the Message resource belongs to.
@return [MessageList] MessageList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/chat/v2/service/channel/message.rb 26 def initialize(version, service_sid: nil, channel_sid: nil) 27 super(version) 28 29 # Path Solution 30 @solution = {service_sid: service_sid, channel_sid: channel_sid} 31 @uri = "/Services/#{@solution[:service_sid]}/Channels/#{@solution[:channel_sid]}/Messages" 32 end
Public Instance Methods
Create the MessageInstance
@param [String] from The Identity
of the new message's author. The default value is `system`.
@param [String] attributes A valid JSON string that contains
application-specific data.
@param [Time] date_created The date, specified in {ISO
8601}[https://en.wikipedia.org/wiki/ISO_8601] format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
@param [Time] date_updated The date, specified in {ISO
8601}[https://en.wikipedia.org/wiki/ISO_8601] format, to assign to the resource as the date it was last updated.
@param [String] last_updated_by The
{Identity}[https://www.twilio.com/docs/chat/identity] of the User who last updated the Message, if applicable.
@param [String] body The message to send to the channel. Can be an empty string
or `null`, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
@param [String] media_sid The SID of the
{Media}[https://www.twilio.com/docs/chat/rest/media] to attach 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/chat/v2/service/channel/message.rb 60 def create(from: :unset, attributes: :unset, date_created: :unset, date_updated: :unset, last_updated_by: :unset, body: :unset, media_sid: :unset, x_twilio_webhook_enabled: :unset) 61 data = Twilio::Values.of({ 62 'From' => from, 63 'Attributes' => attributes, 64 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created), 65 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated), 66 'LastUpdatedBy' => last_updated_by, 67 'Body' => body, 68 'MediaSid' => media_sid, 69 }) 70 headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) 71 72 payload = @version.create('POST', @uri, data: data, headers: headers) 73 74 MessageInstance.new( 75 @version, 76 payload, 77 service_sid: @solution[:service_sid], 78 channel_sid: @solution[:channel_sid], 79 ) 80 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/chat/v2/service/channel/message.rb 124 def each 125 limits = @version.read_limits 126 127 page = self.page(page_size: limits[:page_size], ) 128 129 @version.stream(page, 130 limit: limits[:limit], 131 page_limit: limits[:page_limit]).each {|x| yield x} 132 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/chat/v2/service/channel/message.rb 161 def get_page(target_url) 162 response = @version.domain.request( 163 'GET', 164 target_url 165 ) 166 MessagePage.new(@version, response, @solution) 167 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/chat/v2/service/channel/message.rb 95 def list(order: :unset, limit: nil, page_size: nil) 96 self.stream(order: order, limit: limit, page_size: page_size).entries 97 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/chat/v2/service/channel/message.rb 143 def page(order: :unset, page_token: :unset, page_number: :unset, page_size: :unset) 144 params = Twilio::Values.of({ 145 'Order' => order, 146 'PageToken' => page_token, 147 'Page' => page_number, 148 'PageSize' => page_size, 149 }) 150 151 response = @version.page('GET', @uri, params: params) 152 153 MessagePage.new(@version, response, @solution) 154 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/chat/v2/service/channel/message.rb 112 def stream(order: :unset, limit: nil, page_size: nil) 113 limits = @version.read_limits(limit, page_size) 114 115 page = self.page(order: order, page_size: limits[:page_size], ) 116 117 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 118 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/chat/v2/service/channel/message.rb 171 def to_s 172 '#<Twilio.Chat.V2.MessageList>' 173 end