lib/twilio-ruby/rest/conversations/v1/service/conversation.rb in twilio-ruby-5.77.0 vs lib/twilio-ruby/rest/conversations/v1/service/conversation.rb in twilio-ruby-6.0.0.pre.rc.1

- old
+ new

@@ -1,633 +1,616 @@ ## -# This code was generated by -# \ / _ _ _| _ _ -# | (_)\/(_)(_|\/| |(/_ v1.0.0 -# / / +# This code was generated by +# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ +# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ +# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ # -# frozen_string_literal: true +# Twilio - Conversations +# This is the public Twilio REST API. +# +# NOTE: This class is auto generated by OpenAPI Generator. +# https://openapi-generator.tech +# Do not edit the class manually. +# + module Twilio - module REST - class Conversations < Domain - class V1 < Version - class ServiceContext < InstanceContext - class ConversationList < ListResource - ## - # Initialize the ConversationList - # @param [Version] version Version that contains the resource - # @param [String] chat_service_sid The unique ID of the {Conversation - # Service}[https://www.twilio.com/docs/conversations/api/service-resource] this - # conversation belongs to. - # @return [ConversationList] ConversationList - def initialize(version, chat_service_sid: nil) - super(version) + module REST + class Conversations < ConversationsBase + class V1 < Version + class ServiceContext < InstanceContext - # Path Solution - @solution = {chat_service_sid: chat_service_sid} - @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations" - end + class ConversationList < ListResource + ## + # Initialize the ConversationList + # @param [Version] version Version that contains the resource + # @return [ConversationList] ConversationList + def initialize(version, chat_service_sid: nil) + super(version) + # Path Solution + @solution = { chat_service_sid: chat_service_sid } + @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations" + + end + ## + # Create the ConversationInstance + # @param [String] friendly_name The human-readable name of this conversation, limited to 256 characters. Optional. + # @param [String] unique_name An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL. + # @param [String] attributes An optional 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] messaging_service_sid The unique ID of the [Messaging Service](https://www.twilio.com/docs/sms/services/api) this conversation belongs to. + # @param [Time] date_created The date that this resource was created. + # @param [Time] date_updated The date that this resource was last updated. + # @param [State] state + # @param [String] timers_inactive ISO8601 duration when conversation will be switched to `inactive` state. Minimum value for this timer is 1 minute. + # @param [String] timers_closed ISO8601 duration when conversation will be switched to `closed` state. Minimum value for this timer is 10 minutes. + # @param [ServiceConversationEnumWebhookEnabledType] x_twilio_webhook_enabled The X-Twilio-Webhook-Enabled HTTP request header + # @return [ConversationInstance] Created ConversationInstance + def create( + friendly_name: :unset, + unique_name: :unset, + attributes: :unset, + messaging_service_sid: :unset, + date_created: :unset, + date_updated: :unset, + state: :unset, + timers_inactive: :unset, + timers_closed: :unset, + x_twilio_webhook_enabled: :unset + ) - ## - # Create the ConversationInstance - # @param [String] friendly_name The human-readable name of this conversation, - # limited to 256 characters. Optional. - # @param [String] unique_name An application-defined string that uniquely - # identifies the resource. It can be used to address the resource in place of the - # resource's `sid` in the URL. - # @param [String] attributes An optional 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] messaging_service_sid The unique ID of the {Messaging - # Service}[https://www.twilio.com/docs/sms/services/api] this conversation belongs - # to. - # @param [Time] date_created The date that this resource was created. - # @param [Time] date_updated The date that this resource was last updated. - # @param [conversation.State] state Current state of this conversation. Can be - # either `active`, `inactive` or `closed` and defaults to `active` - # @param [String] timers_inactive ISO8601 duration when conversation will be - # switched to `inactive` state. Minimum value for this timer is 1 minute. - # @param [String] timers_closed ISO8601 duration when conversation will be - # switched to `closed` state. Minimum value for this timer is 10 minutes. - # @param [conversation.WebhookEnabledType] x_twilio_webhook_enabled The - # X-Twilio-Webhook-Enabled HTTP request header - # @return [ConversationInstance] Created ConversationInstance - def create(friendly_name: :unset, unique_name: :unset, attributes: :unset, messaging_service_sid: :unset, date_created: :unset, date_updated: :unset, state: :unset, timers_inactive: :unset, timers_closed: :unset, x_twilio_webhook_enabled: :unset) - data = Twilio::Values.of({ - 'FriendlyName' => friendly_name, - 'UniqueName' => unique_name, - 'Attributes' => attributes, - 'MessagingServiceSid' => messaging_service_sid, - 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created), - 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated), - 'State' => state, - 'Timers.Inactive' => timers_inactive, - 'Timers.Closed' => timers_closed, - }) - headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) + data = Twilio::Values.of({ + 'FriendlyName' => friendly_name, + 'UniqueName' => unique_name, + 'Attributes' => attributes, + 'MessagingServiceSid' => messaging_service_sid, + 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created), + 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated), + 'State' => state, + 'Timers.Inactive' => timers_inactive, + 'Timers.Closed' => timers_closed, + }) - payload = @version.create('POST', @uri, data: data, headers: headers) + headers = Twilio::Values.of({ 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) + payload = @version.create('POST', @uri, data: data, headers: headers) + ConversationInstance.new( + @version, + payload, + chat_service_sid: @solution[:chat_service_sid], + ) + end - ConversationInstance.new(@version, payload, chat_service_sid: @solution[:chat_service_sid], ) - end + + ## + # Lists ConversationInstance records from the API as a list. + # Unlike stream(), this operation is eager and will load `limit` records into + # memory before returning. + # @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 + def list(limit: nil, page_size: nil) + self.stream( + limit: limit, + page_size: page_size + ).entries + end - ## - # Lists ConversationInstance records from the API as a list. - # Unlike stream(), this operation is eager and will load `limit` records into - # memory before returning. - # @param [String] start_date Start date or time in ISO8601 format for filtering - # list of Conversations. If a date is provided, the start time of the date is used - # (YYYY-MM-DDT00:00:00Z). Can be combined with other filters. - # @param [String] end_date End date or time in ISO8601 format for filtering list - # of Conversations. If a date is provided, the end time of the date is used - # (YYYY-MM-DDT23:59:59Z). Can be combined with other filters. - # @param [conversation.State] state State for sorting and filtering list of - # Conversations. Can be `active`, `inactive` or `closed` - # @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 - def list(start_date: :unset, end_date: :unset, state: :unset, limit: nil, page_size: nil) - self.stream( - start_date: start_date, - end_date: end_date, - state: state, - limit: limit, - page_size: page_size - ).entries - end + ## + # Streams Instance records from the API as an Enumerable. + # This operation lazily loads records as efficiently as possible until the limit + # is reached. + # @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 + def stream(limit: nil, page_size: nil) + limits = @version.read_limits(limit, page_size) - ## - # Streams ConversationInstance records from the API as an Enumerable. - # This operation lazily loads records as efficiently as possible until the limit - # is reached. - # @param [String] start_date Start date or time in ISO8601 format for filtering - # list of Conversations. If a date is provided, the start time of the date is used - # (YYYY-MM-DDT00:00:00Z). Can be combined with other filters. - # @param [String] end_date End date or time in ISO8601 format for filtering list - # of Conversations. If a date is provided, the end time of the date is used - # (YYYY-MM-DDT23:59:59Z). Can be combined with other filters. - # @param [conversation.State] state State for sorting and filtering list of - # Conversations. Can be `active`, `inactive` or `closed` - # @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 - def stream(start_date: :unset, end_date: :unset, state: :unset, limit: nil, page_size: nil) - limits = @version.read_limits(limit, page_size) + page = self.page( + page_size: limits[:page_size], ) - page = self.page( - start_date: start_date, - end_date: end_date, - state: state, - page_size: limits[:page_size], - ) + @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) + end - @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) - end + ## + # When passed a block, yields ConversationInstance records from the API. + # This operation lazily loads records as efficiently as possible until the limit + # is reached. + def each + limits = @version.read_limits - ## - # When passed a block, yields ConversationInstance records from the API. - # This operation lazily loads records as efficiently as possible until the limit - # is reached. - def each - limits = @version.read_limits + page = self.page(page_size: limits[:page_size], ) - page = self.page(page_size: limits[:page_size], ) + @version.stream(page, + limit: limits[:limit], + page_limit: limits[:page_limit]).each {|x| yield x} + end - @version.stream(page, - limit: limits[:limit], - page_limit: limits[:page_limit]).each {|x| yield x} - end + ## + # Retrieve a single page of ConversationInstance records from the API. + # Request is executed immediately. + # @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 ConversationInstance + def page(page_token: :unset, page_number: :unset, page_size: :unset) + params = Twilio::Values.of({ + + 'PageToken' => page_token, + 'Page' => page_number, + 'PageSize' => page_size, + }) - ## - # Retrieve a single page of ConversationInstance records from the API. - # Request is executed immediately. - # @param [String] start_date Start date or time in ISO8601 format for filtering - # list of Conversations. If a date is provided, the start time of the date is used - # (YYYY-MM-DDT00:00:00Z). Can be combined with other filters. - # @param [String] end_date End date or time in ISO8601 format for filtering list - # of Conversations. If a date is provided, the end time of the date is used - # (YYYY-MM-DDT23:59:59Z). Can be combined with other filters. - # @param [conversation.State] state State for sorting and filtering list of - # Conversations. Can be `active`, `inactive` or `closed` - # @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 ConversationInstance - def page(start_date: :unset, end_date: :unset, state: :unset, page_token: :unset, page_number: :unset, page_size: :unset) - params = Twilio::Values.of({ - 'StartDate' => start_date, - 'EndDate' => end_date, - 'State' => state, - 'PageToken' => page_token, - 'Page' => page_number, - 'PageSize' => page_size, - }) + response = @version.page('GET', @uri, params: params) - response = @version.page('GET', @uri, params: params) + ConversationPage.new(@version, response, @solution) + end - ConversationPage.new(@version, response, @solution) - end + ## + # Retrieve a single page of ConversationInstance records from the API. + # Request is executed immediately. + # @param [String] target_url API-generated URL for the requested results page + # @return [Page] Page of ConversationInstance + def get_page(target_url) + response = @version.domain.request( + 'GET', + target_url + ) + ConversationPage.new(@version, response, @solution) + end + - ## - # Retrieve a single page of ConversationInstance records from the API. - # Request is executed immediately. - # @param [String] target_url API-generated URL for the requested results page - # @return [Page] Page of ConversationInstance - def get_page(target_url) - response = @version.domain.request( - 'GET', - target_url - ) - ConversationPage.new(@version, response, @solution) - end - ## - # Provide a user friendly representation - def to_s - '#<Twilio.Conversations.V1.ConversationList>' - end - end + # Provide a user friendly representation + def to_s + '#<Twilio.Conversations.V1.ConversationList>' + end + end - class ConversationPage < Page - ## - # Initialize the ConversationPage - # @param [Version] version Version that contains the resource - # @param [Response] response Response from the API - # @param [Hash] solution Path solution for the resource - # @return [ConversationPage] ConversationPage - def initialize(version, response, solution) - super(version, response) - # Path Solution - @solution = solution - end + class ConversationContext < InstanceContext + ## + # Initialize the ConversationContext + # @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 Conversation resource is associated with. + # @param [String] sid A 34 character string that uniquely identifies this resource. Can also be the `unique_name` of the Conversation. + # @return [ConversationContext] ConversationContext + def initialize(version, chat_service_sid, sid) + super(version) - ## - # Build an instance of ConversationInstance - # @param [Hash] payload Payload response from the API - # @return [ConversationInstance] ConversationInstance - def get_instance(payload) - ConversationInstance.new(@version, payload, chat_service_sid: @solution[:chat_service_sid], ) - end + # Path Solution + @solution = { chat_service_sid: chat_service_sid, sid: sid, } + @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations/#{@solution[:sid]}" - ## - # Provide a user friendly representation - def to_s - '<Twilio.Conversations.V1.ConversationPage>' - end - end + # Dependents + @participants = nil + @messages = nil + @webhooks = nil + end + ## + # Delete the ConversationInstance + # @param [ServiceConversationEnumWebhookEnabledType] x_twilio_webhook_enabled The X-Twilio-Webhook-Enabled HTTP request header + # @return [Boolean] True if delete succeeds, false otherwise + def delete( + x_twilio_webhook_enabled: :unset + ) - class ConversationContext < InstanceContext - ## - # Initialize the ConversationContext - # @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 - # Conversation resource is associated with. - # @param [String] sid A 34 character string that uniquely identifies this - # resource. Can also be the `unique_name` of the Conversation. - # @return [ConversationContext] ConversationContext - def initialize(version, chat_service_sid, sid) - super(version) + headers = Twilio::Values.of({ 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) + @version.delete('DELETE', @uri, headers: headers) + end - # Path Solution - @solution = {chat_service_sid: chat_service_sid, sid: sid, } - @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations/#{@solution[:sid]}" + ## + # Fetch the ConversationInstance + # @return [ConversationInstance] Fetched ConversationInstance + def fetch - # Dependents - @participants = nil - @messages = nil - @webhooks = nil - end + payload = @version.fetch('GET', @uri) + ConversationInstance.new( + @version, + payload, + chat_service_sid: @solution[:chat_service_sid], + sid: @solution[:sid], + ) + end - ## - # Update the ConversationInstance - # @param [String] friendly_name The human-readable name of this conversation, - # limited to 256 characters. Optional. - # @param [Time] date_created The date that this resource was created. - # @param [Time] date_updated The date that this resource was last updated. - # @param [String] attributes An optional 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] messaging_service_sid The unique ID of the {Messaging - # Service}[https://www.twilio.com/docs/sms/services/api] this conversation belongs - # to. - # @param [conversation.State] state Current state of this conversation. Can be - # either `active`, `inactive` or `closed` and defaults to `active` - # @param [String] timers_inactive ISO8601 duration when conversation will be - # switched to `inactive` state. Minimum value for this timer is 1 minute. - # @param [String] timers_closed ISO8601 duration when conversation will be - # switched to `closed` state. Minimum value for this timer is 10 minutes. - # @param [String] unique_name An application-defined string that uniquely - # identifies the resource. It can be used to address the resource in place of the - # resource's `sid` in the URL. - # @param [conversation.WebhookEnabledType] x_twilio_webhook_enabled The - # X-Twilio-Webhook-Enabled HTTP request header - # @return [ConversationInstance] Updated ConversationInstance - def update(friendly_name: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, messaging_service_sid: :unset, state: :unset, timers_inactive: :unset, timers_closed: :unset, unique_name: :unset, x_twilio_webhook_enabled: :unset) - data = Twilio::Values.of({ - 'FriendlyName' => friendly_name, - 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created), - 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated), - 'Attributes' => attributes, - 'MessagingServiceSid' => messaging_service_sid, - 'State' => state, - 'Timers.Inactive' => timers_inactive, - 'Timers.Closed' => timers_closed, - 'UniqueName' => unique_name, - }) - headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) + ## + # Update the ConversationInstance + # @param [String] friendly_name The human-readable name of this conversation, limited to 256 characters. Optional. + # @param [Time] date_created The date that this resource was created. + # @param [Time] date_updated The date that this resource was last updated. + # @param [String] attributes An optional 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] messaging_service_sid The unique ID of the [Messaging Service](https://www.twilio.com/docs/sms/services/api) this conversation belongs to. + # @param [State] state + # @param [String] timers_inactive ISO8601 duration when conversation will be switched to `inactive` state. Minimum value for this timer is 1 minute. + # @param [String] timers_closed ISO8601 duration when conversation will be switched to `closed` state. Minimum value for this timer is 10 minutes. + # @param [String] unique_name An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL. + # @param [ServiceConversationEnumWebhookEnabledType] x_twilio_webhook_enabled The X-Twilio-Webhook-Enabled HTTP request header + # @return [ConversationInstance] Updated ConversationInstance + def update( + friendly_name: :unset, + date_created: :unset, + date_updated: :unset, + attributes: :unset, + messaging_service_sid: :unset, + state: :unset, + timers_inactive: :unset, + timers_closed: :unset, + unique_name: :unset, + x_twilio_webhook_enabled: :unset + ) - payload = @version.update('POST', @uri, data: data, headers: headers) + data = Twilio::Values.of({ + 'FriendlyName' => friendly_name, + 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created), + 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated), + 'Attributes' => attributes, + 'MessagingServiceSid' => messaging_service_sid, + 'State' => state, + 'Timers.Inactive' => timers_inactive, + 'Timers.Closed' => timers_closed, + 'UniqueName' => unique_name, + }) - ConversationInstance.new( - @version, - payload, - chat_service_sid: @solution[:chat_service_sid], - sid: @solution[:sid], - ) - end + headers = Twilio::Values.of({ 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) + payload = @version.update('POST', @uri, data: data, headers: headers) + ConversationInstance.new( + @version, + payload, + chat_service_sid: @solution[:chat_service_sid], + sid: @solution[:sid], + ) + end - ## - # Delete the ConversationInstance - # @param [conversation.WebhookEnabledType] x_twilio_webhook_enabled The - # X-Twilio-Webhook-Enabled HTTP request header - # @return [Boolean] true if delete succeeds, false otherwise - def delete(x_twilio_webhook_enabled: :unset) - headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) + ## + # Access the participants + # @return [ParticipantList] + # @return [ParticipantContext] if sid was passed. + def participants(sid=:unset) - @version.delete('DELETE', @uri, headers: headers) - end + raise ArgumentError, 'sid cannot be nil' if sid.nil? - ## - # Fetch the ConversationInstance - # @return [ConversationInstance] Fetched ConversationInstance - def fetch - payload = @version.fetch('GET', @uri) + if sid != :unset + return ParticipantContext.new(@version, @solution[:chat_service_sid], @solution[:sid],sid ) + end - ConversationInstance.new( - @version, - payload, - chat_service_sid: @solution[:chat_service_sid], - sid: @solution[:sid], - ) - end + unless @participants + @participants = ParticipantList.new( + @version, + chat_service_sid: @solution[:chat_service_sid], + conversation_sid: @solution[:sid] + + ) + end - ## - # Access the participants - # @return [ParticipantList] - # @return [ParticipantContext] if sid was passed. - def participants(sid=:unset) - raise ArgumentError, 'sid cannot be nil' if sid.nil? + @participants + end + ## + # Access the messages + # @return [MessageList] + # @return [MessageContext] if sid was passed. + def messages(sid=:unset) - if sid != :unset - return ParticipantContext.new(@version, @solution[:chat_service_sid], @solution[:sid], sid, ) - end + raise ArgumentError, 'sid cannot be nil' if sid.nil? - unless @participants - @participants = ParticipantList.new( - @version, - chat_service_sid: @solution[:chat_service_sid], - conversation_sid: @solution[:sid], - ) - end + if sid != :unset + return MessageContext.new(@version, @solution[:chat_service_sid], @solution[:sid],sid ) + end - @participants - end + unless @messages + @messages = MessageList.new( + @version, + chat_service_sid: @solution[:chat_service_sid], + conversation_sid: @solution[:sid] + + ) + end - ## - # Access the messages - # @return [MessageList] - # @return [MessageContext] if sid was passed. - def messages(sid=:unset) - raise ArgumentError, 'sid cannot be nil' if sid.nil? + @messages + end + ## + # Access the webhooks + # @return [WebhookList] + # @return [WebhookContext] if sid was passed. + def webhooks(sid=:unset) - if sid != :unset - return MessageContext.new(@version, @solution[:chat_service_sid], @solution[:sid], sid, ) - end + raise ArgumentError, 'sid cannot be nil' if sid.nil? - unless @messages - @messages = MessageList.new( - @version, - chat_service_sid: @solution[:chat_service_sid], - conversation_sid: @solution[:sid], - ) - end + if sid != :unset + return WebhookContext.new(@version, @solution[:chat_service_sid], @solution[:sid],sid ) + end - @messages - end + unless @webhooks + @webhooks = WebhookList.new( + @version, + chat_service_sid: @solution[:chat_service_sid], + conversation_sid: @solution[:sid] + + ) + end - ## - # Access the webhooks - # @return [WebhookList] - # @return [WebhookContext] if sid was passed. - def webhooks(sid=:unset) - raise ArgumentError, 'sid cannot be nil' if sid.nil? + @webhooks + end - if sid != :unset - return WebhookContext.new(@version, @solution[:chat_service_sid], @solution[:sid], sid, ) - end + ## + # Provide a user friendly representation + def to_s + context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') + "#<Twilio.Conversations.V1.ConversationContext #{context}>" + end - unless @webhooks - @webhooks = WebhookList.new( - @version, - chat_service_sid: @solution[:chat_service_sid], - conversation_sid: @solution[:sid], - ) - end + ## + # Provide a detailed, user friendly representation + def inspect + context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') + "#<Twilio.Conversations.V1.ConversationContext #{context}>" + end + end - @webhooks - end + class ConversationPage < Page + ## + # Initialize the ConversationPage + # @param [Version] version Version that contains the resource + # @param [Response] response Response from the API + # @param [Hash] solution Path solution for the resource + # @return [ConversationPage] ConversationPage + def initialize(version, response, solution) + super(version, response) - ## - # Provide a user friendly representation - def to_s - context = @solution.map {|k, v| "#{k}: #{v}"}.join(',') - "#<Twilio.Conversations.V1.ConversationContext #{context}>" - end + # Path Solution + @solution = solution + end - ## - # Provide a detailed, user friendly representation - def inspect - context = @solution.map {|k, v| "#{k}: #{v}"}.join(',') - "#<Twilio.Conversations.V1.ConversationContext #{context}>" - end - end + ## + # Build an instance of ConversationInstance + # @param [Hash] payload Payload response from the API + # @return [ConversationInstance] ConversationInstance + def get_instance(payload) + ConversationInstance.new(@version, payload, chat_service_sid: @solution[:chat_service_sid]) + end - class ConversationInstance < InstanceResource - ## - # Initialize the ConversationInstance - # @param [Version] version Version that contains the resource - # @param [Hash] payload payload that contains response from Twilio - # @param [String] chat_service_sid The unique ID of the {Conversation - # Service}[https://www.twilio.com/docs/conversations/api/service-resource] this - # conversation belongs to. - # @param [String] sid A 34 character string that uniquely identifies this - # resource. Can also be the `unique_name` of the Conversation. - # @return [ConversationInstance] ConversationInstance - def initialize(version, payload, chat_service_sid: nil, sid: nil) - super(version) + ## + # Provide a user friendly representation + def to_s + '<Twilio.Conversations.V1.ConversationPage>' + end + end + class ConversationInstance < InstanceResource + ## + # Initialize the ConversationInstance + # @param [Version] version Version that contains the resource + # @param [Hash] payload payload that contains response from Twilio + # @param [String] account_sid The SID of the + # {Account}[https://www.twilio.com/docs/iam/api/account] that created this Conversation + # resource. + # @param [String] sid The SID of the Call resource to fetch. + # @return [ConversationInstance] ConversationInstance + def initialize(version, payload , chat_service_sid: nil, sid: nil) + super(version) + + # Marshaled Properties + @properties = { + 'account_sid' => payload['account_sid'], + 'chat_service_sid' => payload['chat_service_sid'], + 'messaging_service_sid' => payload['messaging_service_sid'], + 'sid' => payload['sid'], + 'friendly_name' => payload['friendly_name'], + 'unique_name' => payload['unique_name'], + 'attributes' => payload['attributes'], + 'state' => payload['state'], + 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']), + 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']), + 'timers' => payload['timers'], + 'url' => payload['url'], + 'links' => payload['links'], + 'bindings' => payload['bindings'], + } - # Marshaled Properties - @properties = { - 'account_sid' => payload['account_sid'], - 'chat_service_sid' => payload['chat_service_sid'], - 'messaging_service_sid' => payload['messaging_service_sid'], - 'sid' => payload['sid'], - 'friendly_name' => payload['friendly_name'], - 'unique_name' => payload['unique_name'], - 'attributes' => payload['attributes'], - 'state' => payload['state'], - 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']), - 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']), - 'timers' => payload['timers'], - 'url' => payload['url'], - 'links' => payload['links'], - 'bindings' => payload['bindings'], - } + # Context + @instance_context = nil + @params = { 'chat_service_sid' => chat_service_sid || @properties['chat_service_sid'] ,'sid' => sid || @properties['sid'] , } + end - # Context - @instance_context = nil - @params = {'chat_service_sid' => chat_service_sid, 'sid' => sid || @properties['sid'], } - end + ## + # Generate an instance context for the instance, the context is capable of + # performing various actions. All instance actions are proxied to the context + # @return [ConversationContext] CallContext for this CallInstance + def context + unless @instance_context + @instance_context = ConversationContext.new(@version , @params['chat_service_sid'], @params['sid']) + end + @instance_context + end + + ## + # @return [String] The unique ID of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this conversation. + def account_sid + @properties['account_sid'] + end + + ## + # @return [String] The unique ID of the [Conversation Service](https://www.twilio.com/docs/conversations/api/service-resource) this conversation belongs to. + def chat_service_sid + @properties['chat_service_sid'] + end + + ## + # @return [String] The unique ID of the [Messaging Service](https://www.twilio.com/docs/sms/services/api) this conversation belongs to. + def messaging_service_sid + @properties['messaging_service_sid'] + end + + ## + # @return [String] A 34 character string that uniquely identifies this resource. + def sid + @properties['sid'] + end + + ## + # @return [String] The human-readable name of this conversation, limited to 256 characters. Optional. + def friendly_name + @properties['friendly_name'] + end + + ## + # @return [String] An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL. + def unique_name + @properties['unique_name'] + end + + ## + # @return [String] An optional 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. + def attributes + @properties['attributes'] + end + + ## + # @return [State] + def state + @properties['state'] + end + + ## + # @return [Time] The date that this resource was created. + def date_created + @properties['date_created'] + end + + ## + # @return [Time] The date that this resource was last updated. + def date_updated + @properties['date_updated'] + end + + ## + # @return [Hash] Timer date values representing state update for this conversation. + def timers + @properties['timers'] + end + + ## + # @return [String] An absolute API resource URL for this conversation. + def url + @properties['url'] + end + + ## + # @return [Hash] Contains absolute URLs to access the [participants](https://www.twilio.com/docs/conversations/api/conversation-participant-resource), [messages](https://www.twilio.com/docs/conversations/api/conversation-message-resource) and [webhooks](https://www.twilio.com/docs/conversations/api/conversation-scoped-webhook-resource) of this conversation. + def links + @properties['links'] + end + + ## + # @return [Hash] + def bindings + @properties['bindings'] + end + + ## + # Delete the ConversationInstance + # @param [ServiceConversationEnumWebhookEnabledType] x_twilio_webhook_enabled The X-Twilio-Webhook-Enabled HTTP request header + # @return [Boolean] True if delete succeeds, false otherwise + def delete( + x_twilio_webhook_enabled: :unset + ) - ## - # Generate an instance context for the instance, the context is capable of - # performing various actions. All instance actions are proxied to the context - # @return [ConversationContext] ConversationContext for this ConversationInstance - def context - unless @instance_context - @instance_context = ConversationContext.new(@version, @params['chat_service_sid'], @params['sid'], ) - end - @instance_context - end + context.delete( + x_twilio_webhook_enabled: x_twilio_webhook_enabled, + ) + end - ## - # @return [String] The unique ID of the Account responsible for this conversation. - def account_sid - @properties['account_sid'] - end + ## + # Fetch the ConversationInstance + # @return [ConversationInstance] Fetched ConversationInstance + def fetch - ## - # @return [String] The unique ID of the Conversation Service this conversation belongs to. - def chat_service_sid - @properties['chat_service_sid'] - end + context.fetch + end - ## - # @return [String] The unique ID of the Messaging Service this conversation belongs to. - def messaging_service_sid - @properties['messaging_service_sid'] - end + ## + # Update the ConversationInstance + # @param [String] friendly_name The human-readable name of this conversation, limited to 256 characters. Optional. + # @param [Time] date_created The date that this resource was created. + # @param [Time] date_updated The date that this resource was last updated. + # @param [String] attributes An optional 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] messaging_service_sid The unique ID of the [Messaging Service](https://www.twilio.com/docs/sms/services/api) this conversation belongs to. + # @param [State] state + # @param [String] timers_inactive ISO8601 duration when conversation will be switched to `inactive` state. Minimum value for this timer is 1 minute. + # @param [String] timers_closed ISO8601 duration when conversation will be switched to `closed` state. Minimum value for this timer is 10 minutes. + # @param [String] unique_name An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL. + # @param [ServiceConversationEnumWebhookEnabledType] x_twilio_webhook_enabled The X-Twilio-Webhook-Enabled HTTP request header + # @return [ConversationInstance] Updated ConversationInstance + def update( + friendly_name: :unset, + date_created: :unset, + date_updated: :unset, + attributes: :unset, + messaging_service_sid: :unset, + state: :unset, + timers_inactive: :unset, + timers_closed: :unset, + unique_name: :unset, + x_twilio_webhook_enabled: :unset + ) - ## - # @return [String] A 34 character string that uniquely identifies this resource. - def sid - @properties['sid'] - end + context.update( + friendly_name: friendly_name, + date_created: date_created, + date_updated: date_updated, + attributes: attributes, + messaging_service_sid: messaging_service_sid, + state: state, + timers_inactive: timers_inactive, + timers_closed: timers_closed, + unique_name: unique_name, + x_twilio_webhook_enabled: x_twilio_webhook_enabled, + ) + end - ## - # @return [String] The human-readable name of this conversation. - def friendly_name - @properties['friendly_name'] - end + ## + # Access the participants + # @return [participants] participants + def participants + context.participants + end - ## - # @return [String] An application-defined string that uniquely identifies the resource - def unique_name - @properties['unique_name'] - end + ## + # Access the messages + # @return [messages] messages + def messages + context.messages + end - ## - # @return [String] An optional string metadata field you can use to store any data you wish. - def attributes - @properties['attributes'] - end + ## + # Access the webhooks + # @return [webhooks] webhooks + def webhooks + context.webhooks + end - ## - # @return [conversation.State] Current state of this conversation. - def state - @properties['state'] - end + ## + # Provide a user friendly representation + def to_s + values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") + "<Twilio.Conversations.V1.ConversationInstance #{values}>" + end - ## - # @return [Time] The date that this resource was created. - def date_created - @properties['date_created'] - end + ## + # Provide a detailed, user friendly representation + def inspect + values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ") + "<Twilio.Conversations.V1.ConversationInstance #{values}>" + end + end - ## - # @return [Time] The date that this resource was last updated. - def date_updated - @properties['date_updated'] + end end - - ## - # @return [Hash] Timer date values for this conversation. - def timers - @properties['timers'] - end - - ## - # @return [String] An absolute URL for this conversation. - def url - @properties['url'] - end - - ## - # @return [String] Absolute URLs to access the participants, messages and webhooks of this conversation. - def links - @properties['links'] - end - - ## - # @return [Hash] The bindings - def bindings - @properties['bindings'] - end - - ## - # Update the ConversationInstance - # @param [String] friendly_name The human-readable name of this conversation, - # limited to 256 characters. Optional. - # @param [Time] date_created The date that this resource was created. - # @param [Time] date_updated The date that this resource was last updated. - # @param [String] attributes An optional 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] messaging_service_sid The unique ID of the {Messaging - # Service}[https://www.twilio.com/docs/sms/services/api] this conversation belongs - # to. - # @param [conversation.State] state Current state of this conversation. Can be - # either `active`, `inactive` or `closed` and defaults to `active` - # @param [String] timers_inactive ISO8601 duration when conversation will be - # switched to `inactive` state. Minimum value for this timer is 1 minute. - # @param [String] timers_closed ISO8601 duration when conversation will be - # switched to `closed` state. Minimum value for this timer is 10 minutes. - # @param [String] unique_name An application-defined string that uniquely - # identifies the resource. It can be used to address the resource in place of the - # resource's `sid` in the URL. - # @param [conversation.WebhookEnabledType] x_twilio_webhook_enabled The - # X-Twilio-Webhook-Enabled HTTP request header - # @return [ConversationInstance] Updated ConversationInstance - def update(friendly_name: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, messaging_service_sid: :unset, state: :unset, timers_inactive: :unset, timers_closed: :unset, unique_name: :unset, x_twilio_webhook_enabled: :unset) - context.update( - friendly_name: friendly_name, - date_created: date_created, - date_updated: date_updated, - attributes: attributes, - messaging_service_sid: messaging_service_sid, - state: state, - timers_inactive: timers_inactive, - timers_closed: timers_closed, - unique_name: unique_name, - x_twilio_webhook_enabled: x_twilio_webhook_enabled, - ) - end - - ## - # Delete the ConversationInstance - # @param [conversation.WebhookEnabledType] x_twilio_webhook_enabled The - # X-Twilio-Webhook-Enabled HTTP request header - # @return [Boolean] true if delete succeeds, false otherwise - def delete(x_twilio_webhook_enabled: :unset) - context.delete(x_twilio_webhook_enabled: x_twilio_webhook_enabled, ) - end - - ## - # Fetch the ConversationInstance - # @return [ConversationInstance] Fetched ConversationInstance - def fetch - context.fetch - end - - ## - # Access the participants - # @return [participants] participants - def participants - context.participants - end - - ## - # Access the messages - # @return [messages] messages - def messages - context.messages - end - - ## - # Access the webhooks - # @return [webhooks] webhooks - def webhooks - context.webhooks - end - - ## - # Provide a user friendly representation - def to_s - values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") - "<Twilio.Conversations.V1.ConversationInstance #{values}>" - end - - ## - # Provide a detailed, user friendly representation - def inspect - values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ") - "<Twilio.Conversations.V1.ConversationInstance #{values}>" - end - end end - end end - end -end \ No newline at end of file +end + +