class Twilio::REST::Chat::V1::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/api/chat/rest/services] the resource is associated with.
@param [String] channel_sid The unique ID of the
{Channel}[https://www.twilio.com/docs/api/chat/rest/channels] the Message resource belongs to.
@return [MessageList] MessageList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/chat/v1/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] body The message to send to the channel. Can also 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] from The
{identity}[https://www.twilio.com/docs/api/chat/guides/identity] of the new message's author. The default value is `system`.
@param [String] attributes A valid JSON string that contains
application-specific data.
@return [MessageInstance] Created MessageInstance
# File lib/twilio-ruby/rest/chat/v1/service/channel/message.rb 45 def create(body: nil, from: :unset, attributes: :unset) 46 data = Twilio::Values.of({'Body' => body, 'From' => from, 'Attributes' => attributes, }) 47 48 payload = @version.create('POST', @uri, data: data) 49 50 MessageInstance.new( 51 @version, 52 payload, 53 service_sid: @solution[:service_sid], 54 channel_sid: @solution[:channel_sid], 55 ) 56 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/v1/service/channel/message.rb 100 def each 101 limits = @version.read_limits 102 103 page = self.page(page_size: limits[:page_size], ) 104 105 @version.stream(page, 106 limit: limits[:limit], 107 page_limit: limits[:page_limit]).each {|x| yield x} 108 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/v1/service/channel/message.rb 137 def get_page(target_url) 138 response = @version.domain.request( 139 'GET', 140 target_url 141 ) 142 MessagePage.new(@version, response, @solution) 143 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/v1/service/channel/message.rb 71 def list(order: :unset, limit: nil, page_size: nil) 72 self.stream(order: order, limit: limit, page_size: page_size).entries 73 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/v1/service/channel/message.rb 119 def page(order: :unset, page_token: :unset, page_number: :unset, page_size: :unset) 120 params = Twilio::Values.of({ 121 'Order' => order, 122 'PageToken' => page_token, 123 'Page' => page_number, 124 'PageSize' => page_size, 125 }) 126 127 response = @version.page('GET', @uri, params: params) 128 129 MessagePage.new(@version, response, @solution) 130 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/v1/service/channel/message.rb 88 def stream(order: :unset, limit: nil, page_size: nil) 89 limits = @version.read_limits(limit, page_size) 90 91 page = self.page(order: order, page_size: limits[:page_size], ) 92 93 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 94 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/chat/v1/service/channel/message.rb 147 def to_s 148 '#<Twilio.Chat.V1.MessageList>' 149 end