Class: Twilio::REST::Chat::V2::ServiceContext::ChannelContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/chat/v2/service/channel.rb,
lib/twilio-ruby/rest/chat/v2/service/channel/invite.rb,
lib/twilio-ruby/rest/chat/v2/service/channel/member.rb,
lib/twilio-ruby/rest/chat/v2/service/channel/message.rb,
lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb

Defined Under Namespace

Classes: InviteContext, InviteInstance, InviteInstanceMetadata, InviteList, InviteListResponse, InvitePage, InvitePageMetadata, MemberContext, MemberInstance, MemberInstanceMetadata, MemberList, MemberListResponse, MemberPage, MemberPageMetadata, MessageContext, MessageInstance, MessageInstanceMetadata, MessageList, MessageListResponse, MessagePage, MessagePageMetadata, WebhookContext, WebhookInstance, WebhookInstanceMetadata, WebhookList, WebhookListResponse, WebhookPage, WebhookPageMetadata

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, sid) ⇒ ChannelContext

Initialize the ChannelContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The SID of the [Service](www.twilio.com/docs/chat/rest/service-resource) to update the Channel resource in.

  • sid (String)

    The SID of the Channel resource to update. This value can be either the sid or the unique_name of the Channel resource to update.



270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 270

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

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

    # Dependents
    @webhooks = nil
    @members = nil
    @messages = nil
    @invites = nil
end

Instance Method Details

#delete(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the ChannelInstance

Parameters:

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

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



288
289
290
291
292
293
294
295
296
297
298
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 288

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 ChannelInstanceMetadata

Parameters:

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

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 304

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)
      channel_instance = ChannelInstance.new(
          @version,
          response.body,
          account_sid: @solution[:account_sid],
          sid: @solution[:sid],
      )
      .new(@version, channel_instance, response.headers, response.status_code)
end

#fetchChannelInstance

Fetch the ChannelInstance

Returns:



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 325

def fetch

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

#fetch_with_metadataChannelInstance

Fetch the ChannelInstanceMetadata

Returns:



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 345

def 

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

#inspectObject

Provide a detailed, user friendly representation



548
549
550
551
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 548

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

#invites(sid = :unset) ⇒ InviteList, InviteContext

Access the invites

Returns:

Raises:

  • (ArgumentError)


523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 523

def invites(sid=:unset)

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

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

    unless @invites
        @invites = InviteList.new(
            @version, service_sid: @solution[:service_sid], channel_sid: @solution[:sid], )
    end

 @invites
end

#members(sid = :unset) ⇒ MemberList, MemberContext

Access the members

Returns:

Raises:

  • (ArgumentError)


485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 485

def members(sid=:unset)

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

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

    unless @members
        @members = MemberList.new(
            @version, service_sid: @solution[:service_sid], channel_sid: @solution[:sid], )
    end

 @members
end

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

Access the messages

Returns:

Raises:

  • (ArgumentError)


504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 504

def messages(sid=:unset)

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

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

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

 @messages
end

#to_sObject

Provide a user friendly representation



541
542
543
544
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 541

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

#update(friendly_name: :unset, unique_name: :unset, attributes: :unset, date_created: :unset, date_updated: :unset, created_by: :unset, x_twilio_webhook_enabled: :unset) ⇒ ChannelInstance

Update the ChannelInstance

Parameters:

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

    A descriptive string that you create to describe the resource. It can be up to 256 characters long.

  • 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. This value must be 256 characters or less in length and unique within the Service.

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

    A valid JSON string that contains application-specific data.

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

    The date, specified in [ISO 8601](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. Note that this should only be used in cases where a Channel is being recreated from a backup/separate source.

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

    The date, specified in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.

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

    The identity of the User that created the channel. Default is: system.

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

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 378

def update(
    friendly_name: :unset, 
    unique_name: :unset, 
    attributes: :unset, 
    date_created: :unset, 
    date_updated: :unset, 
    created_by: :unset, 
    x_twilio_webhook_enabled: :unset
)

    data = Twilio::Values.of({
        'FriendlyName' => friendly_name,
        'UniqueName' => unique_name,
        'Attributes' => attributes,
        'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
        'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
        'CreatedBy' => created_by,
    })

    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)
    ChannelInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
end

#update_with_metadata(friendly_name: :unset, unique_name: :unset, attributes: :unset, date_created: :unset, date_updated: :unset, created_by: :unset, x_twilio_webhook_enabled: :unset) ⇒ ChannelInstance

Update the ChannelInstanceMetadata

Parameters:

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

    A descriptive string that you create to describe the resource. It can be up to 256 characters long.

  • 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. This value must be 256 characters or less in length and unique within the Service.

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

    A valid JSON string that contains application-specific data.

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

    The date, specified in [ISO 8601](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. Note that this should only be used in cases where a Channel is being recreated from a backup/separate source.

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

    The date, specified in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.

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

    The identity of the User that created the channel. Default is: system.

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

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



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
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 422

def (
  friendly_name: :unset, 
  unique_name: :unset, 
  attributes: :unset, 
  date_created: :unset, 
  date_updated: :unset, 
  created_by: :unset, 
  x_twilio_webhook_enabled: :unset
)

    data = Twilio::Values.of({
        'FriendlyName' => friendly_name,
        'UniqueName' => unique_name,
        'Attributes' => attributes,
        'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
        'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
        'CreatedBy' => created_by,
    })

    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)
    channel_instance = ChannelInstance.new(
        @version,
        response.body,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        channel_instance,
        response.headers,
        response.status_code
    )
end

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

Access the webhooks

Returns:

Raises:

  • (ArgumentError)


466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/twilio-ruby/rest/chat/v2/service/channel.rb', line 466

def webhooks(sid=:unset)

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

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

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

 @webhooks
end