Class: Twilio::REST::Chat::V1::ServiceContext

Inherits:
InstanceContext show all
Defined in:
lib/twilio-ruby/rest/chat/v1/service.rb,
lib/twilio-ruby/rest/chat/v1/service/role.rb,
lib/twilio-ruby/rest/chat/v1/service/user.rb,
lib/twilio-ruby/rest/chat/v1/service/channel.rb,
lib/twilio-ruby/rest/chat/v1/service/channel/invite.rb,
lib/twilio-ruby/rest/chat/v1/service/channel/member.rb,
lib/twilio-ruby/rest/chat/v1/service/channel/message.rb,
lib/twilio-ruby/rest/chat/v1/service/user/user_channel.rb

Defined Under Namespace

Classes: ChannelContext, ChannelInstance, ChannelList, ChannelPage, RoleContext, RoleInstance, RoleList, RolePage, UserContext, UserInstance, UserList, UserPage

Instance Method Summary collapse

Constructor Details

#initialize(version, sid) ⇒ ServiceContext

Initialize the ServiceContext

Parameters:

  • version (Version) —

    Version that contains the resource

  • sid (String) —

    The Twilio-provided string that uniquely identifies the Service resource to fetch.



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 162

def initialize(version, sid)
  super(version)

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

  # Dependents
  @channels = nil
  @roles = nil
  @users = nil
end

Instance Method Details

#channels(sid = :unset) ⇒ ChannelList, ChannelContext

Access the channels

Returns:

Raises:

  • (ArgumentError)


404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 404

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

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

  unless @channels
    @channels = ChannelList.new(@version, service_sid: @solution[:sid], )
  end

  @channels
end

#delete ⇒ Boolean

Delete the ServiceInstance

Returns:

  • (Boolean) —

    true if delete succeeds, false otherwise



187
188
189
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 187

def delete
   @version.delete('DELETE', @uri)
end

#fetch ⇒ ServiceInstance

Fetch the ServiceInstance

Returns:



178
179
180
181
182
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 178

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

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

#inspect ⇒ Object

Provide a detailed, user friendly representation



463
464
465
466
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 463

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

#roles(sid = :unset) ⇒ RoleList, RoleContext

Access the roles

Returns:

Raises:

  • (ArgumentError)


422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 422

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

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

  unless @roles
    @roles = RoleList.new(@version, service_sid: @solution[:sid], )
  end

  @roles
end

#to_s ⇒ Object

Provide a user friendly representation



456
457
458
459
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 456

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

#update(friendly_name: :unset, default_service_role_sid: :unset, default_channel_role_sid: :unset, default_channel_creator_role_sid: :unset, read_status_enabled: :unset, reachability_enabled: :unset, typing_indicator_timeout: :unset, consumption_report_interval: :unset, notifications_new_message_enabled: :unset, notifications_new_message_template: :unset, notifications_added_to_channel_enabled: :unset, notifications_added_to_channel_template: :unset, notifications_removed_from_channel_enabled: :unset, notifications_removed_from_channel_template: :unset, notifications_invited_to_channel_enabled: :unset, notifications_invited_to_channel_template: :unset, pre_webhook_url: :unset, post_webhook_url: :unset, webhook_method: :unset, webhook_filters: :unset, webhooks_on_message_send_url: :unset, webhooks_on_message_send_method: :unset, webhooks_on_message_update_url: :unset, webhooks_on_message_update_method: :unset, webhooks_on_message_remove_url: :unset, webhooks_on_message_remove_method: :unset, webhooks_on_channel_add_url: :unset, webhooks_on_channel_add_method: :unset, webhooks_on_channel_destroy_url: :unset, webhooks_on_channel_destroy_method: :unset, webhooks_on_channel_update_url: :unset, webhooks_on_channel_update_method: :unset, webhooks_on_member_add_url: :unset, webhooks_on_member_add_method: :unset, webhooks_on_member_remove_url: :unset, webhooks_on_member_remove_method: :unset, webhooks_on_message_sent_url: :unset, webhooks_on_message_sent_method: :unset, webhooks_on_message_updated_url: :unset, webhooks_on_message_updated_method: :unset, webhooks_on_message_removed_url: :unset, webhooks_on_message_removed_method: :unset, webhooks_on_channel_added_url: :unset, webhooks_on_channel_added_method: :unset, webhooks_on_channel_destroyed_url: :unset, webhooks_on_channel_destroyed_method: :unset, webhooks_on_channel_updated_url: :unset, webhooks_on_channel_updated_method: :unset, webhooks_on_member_added_url: :unset, webhooks_on_member_added_method: :unset, webhooks_on_member_removed_url: :unset, webhooks_on_member_removed_method: :unset, limits_channel_members: :unset, limits_user_channels: :unset) ⇒ ServiceInstance

Update the ServiceInstance

Parameters:

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

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

  • default_service_role_sid (String) (defaults to: :unset) —

    The service role assigned to users when they are added to the service. See the Roles endpoint for more details.

  • default_channel_role_sid (String) (defaults to: :unset) —

    The channel role assigned to users when they are added to a channel. See the Roles endpoint for more details.

  • default_channel_creator_role_sid (String) (defaults to: :unset) —

    The channel role assigned to a channel creator when they join a new channel. See the Roles endpoint for more details.

  • read_status_enabled (Boolean) (defaults to: :unset) —

    Whether to enable the Message Consumption Horizon feature. The default is true.

  • reachability_enabled (Boolean) (defaults to: :unset) —

    Whether to enable the Reachability Indicator for this Service instance. The default is false.

  • typing_indicator_timeout (String) (defaults to: :unset) —

    How long in seconds after a started typing event until clients should assume that user is no longer typing, even if no ended typing message was received. The default is 5 seconds.

  • consumption_report_interval (String) (defaults to: :unset) —

    DEPRECATED. The interval in seconds between consumption reports submission batches from client endpoints.

  • notifications_new_message_enabled (Boolean) (defaults to: :unset) —

    Whether to send a notification when a new message is added to a channel. Can be: true or false and the default is false.

  • notifications_new_message_template (String) (defaults to: :unset) —

    The template to use to create the notification text displayed when a new message is added to a channel and notifications.new_message.enabled is true.

  • notifications_added_to_channel_enabled (Boolean) (defaults to: :unset) —

    Whether to send a notification when a member is added to a channel. Can be: true or false and the default is false.

  • notifications_added_to_channel_template (String) (defaults to: :unset) —

    The template to use to create the notification text displayed when a member is added to a channel and notifications.added_to_channel.enabled is true.

  • notifications_removed_from_channel_enabled (Boolean) (defaults to: :unset) —

    Whether to send a notification to a user when they are removed from a channel. Can be: true or false and the default is false.

  • notifications_removed_from_channel_template (String) (defaults to: :unset) —

    The template to use to create the notification text displayed to a user when they are removed from a channel and notifications.removed_from_channel.enabled is true.

  • notifications_invited_to_channel_enabled (Boolean) (defaults to: :unset) —

    Whether to send a notification when a user is invited to a channel. Can be: true or false and the default is false.

  • notifications_invited_to_channel_template (String) (defaults to: :unset) —

    The template to use to create the notification text displayed when a user is invited to a channel and notifications.invited_to_channel.enabled is true.

  • pre_webhook_url (String) (defaults to: :unset) —

    The URL for pre-event webhooks, which are called by using the webhook_method. See Webhook Events for more details.

  • post_webhook_url (String) (defaults to: :unset) —

    The URL for post-event webhooks, which are called by using the webhook_method. See Webhook Events for more details.

  • webhook_method (String) (defaults to: :unset) —

    The HTTP method to use for calls to the pre_webhook_url and post_webhook_url webhooks. Can be: POST or GET and the default is POST. See Webhook Events for more details.

  • webhook_filters (Array[String]) (defaults to: :unset) —

    The list of WebHook events that are enabled for this Service instance. See Webhook Events for more details.

  • webhooks_on_message_send_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_message_send event using the webhooks.on_message_send.method HTTP method.

  • webhooks_on_message_send_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_message_send.url.

  • webhooks_on_message_update_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_message_update event using the webhooks.on_message_update.method HTTP method.

  • webhooks_on_message_update_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_message_update.url.

  • webhooks_on_message_remove_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_message_remove event using the webhooks.on_message_remove.method HTTP method.

  • webhooks_on_message_remove_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_message_remove.url.

  • webhooks_on_channel_add_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_channel_add event using the webhooks.on_channel_add.method HTTP method.

  • webhooks_on_channel_add_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_channel_add.url.

  • webhooks_on_channel_destroy_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_channel_destroy event using the webhooks.on_channel_destroy.method HTTP method.

  • webhooks_on_channel_destroy_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_channel_destroy.url.

  • webhooks_on_channel_update_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_channel_update event using the webhooks.on_channel_update.method HTTP method.

  • webhooks_on_channel_update_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_channel_update.url.

  • webhooks_on_member_add_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_member_add event using the webhooks.on_member_add.method HTTP method.

  • webhooks_on_member_add_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_member_add.url.

  • webhooks_on_member_remove_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_member_remove event using the webhooks.on_member_remove.method HTTP method.

  • webhooks_on_member_remove_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_member_remove.url.

  • webhooks_on_message_sent_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_message_sent event using the webhooks.on_message_sent.method HTTP method.

  • webhooks_on_message_sent_method (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_message_sent event`.

  • webhooks_on_message_updated_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_message_updated event using the webhooks.on_message_updated.method HTTP method.

  • webhooks_on_message_updated_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_message_updated.url.

  • webhooks_on_message_removed_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_message_removed event using the webhooks.on_message_removed.method HTTP method.

  • webhooks_on_message_removed_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_message_removed.url.

  • webhooks_on_channel_added_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_channel_added event using the webhooks.on_channel_added.method HTTP method.

  • webhooks_on_channel_added_method (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_channel_added event`.

  • webhooks_on_channel_destroyed_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_channel_added event using the webhooks.on_channel_destroyed.method HTTP method.

  • webhooks_on_channel_destroyed_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_channel_destroyed.url.

  • webhooks_on_channel_updated_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_channel_updated event using the webhooks.on_channel_updated.method HTTP method.

  • webhooks_on_channel_updated_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_channel_updated.url.

  • webhooks_on_member_added_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_channel_updated event using the webhooks.on_channel_updated.method HTTP method.

  • webhooks_on_member_added_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_channel_updated.url.

  • webhooks_on_member_removed_url (String) (defaults to: :unset) —

    The URL of the webhook to call in response to the on_member_removed event using the webhooks.on_member_removed.method HTTP method.

  • webhooks_on_member_removed_method (String) (defaults to: :unset) —

    The HTTP method to use when calling the webhooks.on_member_removed.url.

  • limits_channel_members (String) (defaults to: :unset) —

    The maximum number of Members that can be added to Channels within this Service. Can be up to 1,000.

  • limits_user_channels (String) (defaults to: :unset) —

    The maximum number of Channels Users can be a Member of within this Service. Can be up to 1,000.

Returns:



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 337

def update(friendly_name: :unset, default_service_role_sid: :unset, default_channel_role_sid: :unset, default_channel_creator_role_sid: :unset, read_status_enabled: :unset, reachability_enabled: :unset, typing_indicator_timeout: :unset, consumption_report_interval: :unset, notifications_new_message_enabled: :unset, notifications_new_message_template: :unset, notifications_added_to_channel_enabled: :unset, notifications_added_to_channel_template: :unset, notifications_removed_from_channel_enabled: :unset, notifications_removed_from_channel_template: :unset, notifications_invited_to_channel_enabled: :unset, notifications_invited_to_channel_template: :unset, pre_webhook_url: :unset, post_webhook_url: :unset, webhook_method: :unset, webhook_filters: :unset, webhooks_on_message_send_url: :unset, webhooks_on_message_send_method: :unset, webhooks_on_message_update_url: :unset, webhooks_on_message_update_method: :unset, webhooks_on_message_remove_url: :unset, webhooks_on_message_remove_method: :unset, webhooks_on_channel_add_url: :unset, webhooks_on_channel_add_method: :unset, webhooks_on_channel_destroy_url: :unset, webhooks_on_channel_destroy_method: :unset, webhooks_on_channel_update_url: :unset, webhooks_on_channel_update_method: :unset, webhooks_on_member_add_url: :unset, webhooks_on_member_add_method: :unset, webhooks_on_member_remove_url: :unset, webhooks_on_member_remove_method: :unset, webhooks_on_message_sent_url: :unset, webhooks_on_message_sent_method: :unset, webhooks_on_message_updated_url: :unset, webhooks_on_message_updated_method: :unset, webhooks_on_message_removed_url: :unset, webhooks_on_message_removed_method: :unset, webhooks_on_channel_added_url: :unset, webhooks_on_channel_added_method: :unset, webhooks_on_channel_destroyed_url: :unset, webhooks_on_channel_destroyed_method: :unset, webhooks_on_channel_updated_url: :unset, webhooks_on_channel_updated_method: :unset, webhooks_on_member_added_url: :unset, webhooks_on_member_added_method: :unset, webhooks_on_member_removed_url: :unset, webhooks_on_member_removed_method: :unset, limits_channel_members: :unset, limits_user_channels: :unset)
  data = Twilio::Values.of({
      'FriendlyName' => friendly_name,
      'DefaultServiceRoleSid' => default_service_role_sid,
      'DefaultChannelRoleSid' => default_channel_role_sid,
      'DefaultChannelCreatorRoleSid' => default_channel_creator_role_sid,
      'ReadStatusEnabled' => read_status_enabled,
      'ReachabilityEnabled' => reachability_enabled,
      'TypingIndicatorTimeout' => typing_indicator_timeout,
      'ConsumptionReportInterval' => consumption_report_interval,
      'Notifications.NewMessage.Enabled' => notifications_new_message_enabled,
      'Notifications.NewMessage.Template' => notifications_new_message_template,
      'Notifications.AddedToChannel.Enabled' => notifications_added_to_channel_enabled,
      'Notifications.AddedToChannel.Template' => notifications_added_to_channel_template,
      'Notifications.RemovedFromChannel.Enabled' => notifications_removed_from_channel_enabled,
      'Notifications.RemovedFromChannel.Template' => notifications_removed_from_channel_template,
      'Notifications.InvitedToChannel.Enabled' => notifications_invited_to_channel_enabled,
      'Notifications.InvitedToChannel.Template' => notifications_invited_to_channel_template,
      'PreWebhookUrl' => pre_webhook_url,
      'PostWebhookUrl' => post_webhook_url,
      'WebhookMethod' => webhook_method,
      'WebhookFilters' => Twilio.serialize_list(webhook_filters) { |e| e },
      'Webhooks.OnMessageSend.Url' => webhooks_on_message_send_url,
      'Webhooks.OnMessageSend.Method' => webhooks_on_message_send_method,
      'Webhooks.OnMessageUpdate.Url' => webhooks_on_message_update_url,
      'Webhooks.OnMessageUpdate.Method' => webhooks_on_message_update_method,
      'Webhooks.OnMessageRemove.Url' => webhooks_on_message_remove_url,
      'Webhooks.OnMessageRemove.Method' => webhooks_on_message_remove_method,
      'Webhooks.OnChannelAdd.Url' => webhooks_on_channel_add_url,
      'Webhooks.OnChannelAdd.Method' => webhooks_on_channel_add_method,
      'Webhooks.OnChannelDestroy.Url' => webhooks_on_channel_destroy_url,
      'Webhooks.OnChannelDestroy.Method' => webhooks_on_channel_destroy_method,
      'Webhooks.OnChannelUpdate.Url' => webhooks_on_channel_update_url,
      'Webhooks.OnChannelUpdate.Method' => webhooks_on_channel_update_method,
      'Webhooks.OnMemberAdd.Url' => webhooks_on_member_add_url,
      'Webhooks.OnMemberAdd.Method' => webhooks_on_member_add_method,
      'Webhooks.OnMemberRemove.Url' => webhooks_on_member_remove_url,
      'Webhooks.OnMemberRemove.Method' => webhooks_on_member_remove_method,
      'Webhooks.OnMessageSent.Url' => webhooks_on_message_sent_url,
      'Webhooks.OnMessageSent.Method' => webhooks_on_message_sent_method,
      'Webhooks.OnMessageUpdated.Url' => webhooks_on_message_updated_url,
      'Webhooks.OnMessageUpdated.Method' => webhooks_on_message_updated_method,
      'Webhooks.OnMessageRemoved.Url' => webhooks_on_message_removed_url,
      'Webhooks.OnMessageRemoved.Method' => webhooks_on_message_removed_method,
      'Webhooks.OnChannelAdded.Url' => webhooks_on_channel_added_url,
      'Webhooks.OnChannelAdded.Method' => webhooks_on_channel_added_method,
      'Webhooks.OnChannelDestroyed.Url' => webhooks_on_channel_destroyed_url,
      'Webhooks.OnChannelDestroyed.Method' => webhooks_on_channel_destroyed_method,
      'Webhooks.OnChannelUpdated.Url' => webhooks_on_channel_updated_url,
      'Webhooks.OnChannelUpdated.Method' => webhooks_on_channel_updated_method,
      'Webhooks.OnMemberAdded.Url' => webhooks_on_member_added_url,
      'Webhooks.OnMemberAdded.Method' => webhooks_on_member_added_method,
      'Webhooks.OnMemberRemoved.Url' => webhooks_on_member_removed_url,
      'Webhooks.OnMemberRemoved.Method' => webhooks_on_member_removed_method,
      'Limits.ChannelMembers' => limits_channel_members,
      'Limits.UserChannels' => limits_user_channels,
  })

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

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

#users(sid = :unset) ⇒ UserList, UserContext

Access the users

Returns:

Raises:

  • (ArgumentError)


440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/twilio-ruby/rest/chat/v1/service.rb', line 440

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

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

  unless @users
    @users = UserList.new(@version, service_sid: @solution[:sid], )
  end

  @users
end