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

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

Defined Under Namespace

Classes: MessageContext, MessageInstance, MessageInstanceMetadata, MessageList, MessageListResponse, MessagePage, MessagePageMetadata, ParticipantContext, ParticipantInstance, ParticipantInstanceMetadata, ParticipantList, ParticipantListResponse, ParticipantPage, ParticipantPageMetadata, WebhookContext, WebhookInstance, WebhookInstanceMetadata, WebhookList, WebhookListResponse, WebhookPage, WebhookPageMetadata

Instance Method Summary collapse

Constructor Details

#initialize(version, chat_service_sid, sid) ⇒ ConversationContext

Initialize the ConversationContext

Parameters:

  • version (Version)

    Version that contains the resource

  • chat_service_sid (String)

    The SID of the [Conversation Service](www.twilio.com/docs/conversations/api/service-resource) the Conversation resource is associated with.

  • sid (String)

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



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

def initialize(version, chat_service_sid, sid)
    super(version)
    

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

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

Instance Method Details

#delete(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the ConversationInstance

Parameters:

  • x_twilio_webhook_enabled (ServiceConversationEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



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

def delete(
    x_twilio_webhook_enabled: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    

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

#delete_with_metadata(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the ConversationInstanceMetadata

Parameters:

  • x_twilio_webhook_enabled (ServiceConversationEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



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

def (
  x_twilio_webhook_enabled: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    
      response = @version.('DELETE', @uri, headers: headers)
      conversation_instance = ConversationInstance.new(
          @version,
          response.body,
          account_sid: @solution[:account_sid],
          sid: @solution[:sid],
      )
      .new(@version, conversation_instance, response.headers, response.status_code)
end

#fetchConversationInstance

Fetch the ConversationInstance

Returns:



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 362

def fetch

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.fetch('GET', @uri, headers: headers)
    ConversationInstance.new(
        @version,
        payload,
        chat_service_sid: @solution[:chat_service_sid],
        sid: @solution[:sid],
    )
end

#fetch_with_metadataConversationInstance

Fetch the ConversationInstanceMetadata

Returns:



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 382

def 

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('GET', @uri, headers: headers)
    conversation_instance = ConversationInstance.new(
        @version,
        response.body,
        chat_service_sid: @solution[:chat_service_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        conversation_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



596
597
598
599
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 596

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)


571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 571

def messages(sid=:unset)

    raise ArgumentError, 'sid cannot be nil' if sid.nil?

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

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

 @messages
end

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

Access the participants

Returns:

Raises:

  • (ArgumentError)


533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 533

def participants(sid=:unset)

    raise ArgumentError, 'sid cannot be nil' if sid.nil?

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

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

 @participants
end

#to_sObject

Provide a user friendly representation



589
590
591
592
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 589

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, bindings_email_address: :unset, bindings_email_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](www.twilio.com/docs/messaging/api/service-resource) this conversation belongs to.

  • state (State) (defaults to: :unset)
  • 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.

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

    The default email address that will be used when sending outbound emails in this conversation.

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

    The default name that will be used when sending outbound emails in this conversation.

  • x_twilio_webhook_enabled (ServiceConversationEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 420

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, 
    bindings_email_address: :unset, 
    bindings_email_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,
        'Bindings.Email.Address' => bindings_email_address,
        'Bindings.Email.Name' => bindings_email_name,
    })

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', '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

#update_with_metadata(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, bindings_email_address: :unset, bindings_email_name: :unset, x_twilio_webhook_enabled: :unset) ⇒ ConversationInstance

Update the ConversationInstanceMetadata

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](www.twilio.com/docs/messaging/api/service-resource) this conversation belongs to.

  • state (State) (defaults to: :unset)
  • 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.

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

    The default email address that will be used when sending outbound emails in this conversation.

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

    The default name that will be used when sending outbound emails in this conversation.

  • x_twilio_webhook_enabled (ServiceConversationEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 479

def (
  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, 
  bindings_email_address: :unset, 
  bindings_email_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,
        'Bindings.Email.Address' => bindings_email_address,
        'Bindings.Email.Name' => bindings_email_name,
    })

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    
    
    
    response = @version.('POST', @uri, data: data, headers: headers)
    conversation_instance = ConversationInstance.new(
        @version,
        response.body,
        chat_service_sid: @solution[:chat_service_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        conversation_instance,
        response.headers,
        response.status_code
    )
end

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

Access the webhooks

Returns:

Raises:

  • (ArgumentError)


552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation.rb', line 552

def webhooks(sid=:unset)

    raise ArgumentError, 'sid cannot be nil' if sid.nil?

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

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

 @webhooks
end