Class: Twilio::REST::Conversations::V1::ConversationContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/conversations/v1/conversation.rb,
lib/twilio-ruby/rest/conversations/v1/conversation/message.rb,
lib/twilio-ruby/rest/conversations/v1/conversation/webhook.rb,
lib/twilio-ruby/rest/conversations/v1/conversation/participant.rb,
lib/twilio-ruby/rest/conversations/v1/conversation/message/delivery_receipt.rb

Defined Under Namespace

Classes: MessageContext, MessageInstance, MessageList, MessagePage, ParticipantContext, ParticipantInstance, ParticipantList, ParticipantPage, WebhookContext, WebhookInstance, WebhookList, WebhookPage

Instance Method Summary collapse

Constructor Details

#initialize(version, sid) ⇒ ConversationContext

Initialize the ConversationContext

Parameters:

  • version (Version)

    Version that contains the resource

  • sid (String)

    A 34 character string that uniquely identifies this resource. Can also be the ‘unique_name` of the Conversation.



225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 225

def initialize(version, sid)
  super(version)

  # Path Solution
  @solution = {sid: sid, }
  @uri = "/Conversations/#{@solution[:sid]}"

  # Dependents
  @participants = nil
  @messages = nil
  @webhooks = nil
end

Instance Method Details

#delete(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the ConversationInstance

Parameters:

  • x_twilio_webhook_enabled (conversation.WebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    true if delete succeeds, false otherwise



287
288
289
290
291
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 287

def delete(x_twilio_webhook_enabled: :unset)
  headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })

   @version.delete('DELETE', @uri, headers: headers)
end

#fetchConversationInstance

Fetch the ConversationInstance

Returns:



296
297
298
299
300
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 296

def fetch
  payload = @version.fetch('GET', @uri)

  ConversationInstance.new(@version, payload, sid: @solution[:sid], )
end

#inspectObject

Provide a detailed, user friendly representation



365
366
367
368
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 365

def inspect
  context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
  "#<Twilio.Conversations.V1.ConversationContext #{context}>"
end

#messages(sid = :unset) ⇒ MessageList, MessageContext

Access the messages

Returns:

Raises:

  • (ArgumentError)


324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 324

def messages(sid=:unset)
  raise ArgumentError, 'sid cannot be nil' if sid.nil?

  if sid != :unset
    return MessageContext.new(@version, @solution[:sid], sid, )
  end

  unless @messages
    @messages = MessageList.new(@version, conversation_sid: @solution[:sid], )
  end

  @messages
end

#participants(sid = :unset) ⇒ ParticipantList, ParticipantContext

Access the participants

Returns:

Raises:

  • (ArgumentError)


306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 306

def participants(sid=:unset)
  raise ArgumentError, 'sid cannot be nil' if sid.nil?

  if sid != :unset
    return ParticipantContext.new(@version, @solution[:sid], sid, )
  end

  unless @participants
    @participants = ParticipantList.new(@version, conversation_sid: @solution[:sid], )
  end

  @participants
end

#to_sObject

Provide a user friendly representation



358
359
360
361
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 358

def to_s
  context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
  "#<Twilio.Conversations.V1.ConversationContext #{context}>"
end

#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) ⇒ ConversationInstance

Update the ConversationInstance

Parameters:

  • friendly_name (String) (defaults to: :unset)

    The human-readable name of this conversation, limited to 256 characters. Optional.

  • date_created (Time) (defaults to: :unset)

    The date that this resource was created.

  • date_updated (Time) (defaults to: :unset)

    The date that this resource was last updated.

  • attributes (String) (defaults to: :unset)

    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.

  • messaging_service_sid (String) (defaults to: :unset)

    The unique ID of the Messaging Service this conversation belongs to.

  • state (conversation.State) (defaults to: :unset)

    Current state of this conversation. Can be either ‘active`, `inactive` or `closed` and defaults to `active`

  • timers_inactive (String) (defaults to: :unset)

    ISO8601 duration when conversation will be switched to ‘inactive` state. Minimum value for this timer is 1 minute.

  • timers_closed (String) (defaults to: :unset)

    ISO8601 duration when conversation will be switched to ‘closed` state. Minimum value for this timer is 10 minutes.

  • unique_name (String) (defaults to: :unset)

    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.

  • x_twilio_webhook_enabled (conversation.WebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 263

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, })

  payload = @version.update('POST', @uri, data: data, headers: headers)

  ConversationInstance.new(@version, payload, sid: @solution[:sid], )
end

#webhooks(sid = :unset) ⇒ WebhookList, WebhookContext

Access the webhooks

Returns:

Raises:

  • (ArgumentError)


342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 342

def webhooks(sid=:unset)
  raise ArgumentError, 'sid cannot be nil' if sid.nil?

  if sid != :unset
    return WebhookContext.new(@version, @solution[:sid], sid, )
  end

  unless @webhooks
    @webhooks = WebhookList.new(@version, conversation_sid: @solution[:sid], )
  end

  @webhooks
end