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

Inherits:
InstanceContext show all
Defined in:
lib/twilio-ruby/rest/chat/v2/service.rb,
lib/twilio-ruby/rest/chat/v2/service/role.rb,
lib/twilio-ruby/rest/chat/v2/service/user.rb,
lib/twilio-ruby/rest/chat/v2/service/binding.rb,
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,
lib/twilio-ruby/rest/chat/v2/service/user/user_binding.rb,
lib/twilio-ruby/rest/chat/v2/service/user/user_channel.rb

Defined Under Namespace

Classes: BindingContext, BindingInstance, BindingList, BindingPage, 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 SID of the Service resource to update.



152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 152

def initialize(version, sid)
    super(version)

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

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

Instance Method Details

#bindings(sid = :unset) ⇒ BindingList, BindingContext

Access the bindings

Returns:

Raises:

  • (ArgumentError)


300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 300

def bindings(sid=:unset)

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

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

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

 @bindings
end

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

Access the channels

Returns:

Raises:

  • (ArgumentError)


319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 319

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

#deleteBoolean

Delete the ServiceInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



168
169
170
171
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 168

def delete

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

#fetchServiceInstance

Fetch the ServiceInstance

Returns:



176
177
178
179
180
181
182
183
184
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 176

def fetch

    payload = @version.fetch('GET', @uri)
    ServiceInstance.new(
        @version,
        payload,
        sid: @solution[:sid],
    )
end

#inspectObject

Provide a detailed, user friendly representation



382
383
384
385
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 382

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

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

Access the roles

Returns:

Raises:

  • (ArgumentError)


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 338

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_sObject

Provide a user friendly representation



375
376
377
378
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 375

def to_s
    context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
    "#<Twilio.Chat.V2.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_new_message_sound: :unset, notifications_new_message_badge_count_enabled: :unset, notifications_added_to_channel_enabled: :unset, notifications_added_to_channel_template: :unset, notifications_added_to_channel_sound: :unset, notifications_removed_from_channel_enabled: :unset, notifications_removed_from_channel_template: :unset, notifications_removed_from_channel_sound: :unset, notifications_invited_to_channel_enabled: :unset, notifications_invited_to_channel_template: :unset, notifications_invited_to_channel_sound: :unset, pre_webhook_url: :unset, post_webhook_url: :unset, webhook_method: :unset, webhook_filters: :unset, limits_channel_members: :unset, limits_user_channels: :unset, media_compatibility_message: :unset, pre_webhook_retry_count: :unset, post_webhook_retry_count: :unset, notifications_log_enabled: :unset) ⇒ ServiceInstance

Update the ServiceInstance

Parameters:

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

    A descriptive string that you create to describe the resource.

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

    The service role assigned to users when they are added to the service. See the [Role resource](www.twilio.com/docs/chat/rest/role-resource) for more info about roles.

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

    The channel role assigned to users when they are added to a channel. See the [Role resource](www.twilio.com/docs/chat/rest/role-resource) for more info about roles.

  • 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 [Role resource](www.twilio.com/docs/chat/rest/role-resource) for more info about roles.

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

    Whether to enable the [Message Consumption Horizon](www.twilio.com/docs/chat/consumption-horizon) feature. The default is ‘true`.

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

    Whether to enable the [Reachability Indicator](www.twilio.com/docs/chat/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. 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_new_message_sound (String) (defaults to: :unset)

    The name of the sound to play when a new message is added to a channel and ‘notifications.new_message.enabled` is `true`.

  • notifications_new_message_badge_count_enabled (Boolean) (defaults to: :unset)

    Whether the new message badge is enabled. The default is ‘false`.

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

    Whether to send a notification when a member is added to a channel. 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_added_to_channel_sound (String) (defaults to: :unset)

    The name of the sound to play 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. 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_removed_from_channel_sound (String) (defaults to: :unset)

    The name of the sound to play 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. 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`.

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

    The name of the sound to play 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](www.twilio.com/docs/chat/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](www.twilio.com/docs/chat/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](www.twilio.com/docs/chat/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](www.twilio.com/docs/chat/webhook-events) for more details.

  • 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.

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

    The message to send when a media message has no text. Can be used as placeholder message.

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

    The number of times to retry a call to the ‘pre_webhook_url` if the request times out (after 5 seconds) or it receives a 429, 503, or 504 HTTP response. Default retry count is 0 times, which means the call won’t be retried.

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

    The number of times to retry a call to the ‘post_webhook_url` if the request times out (after 5 seconds) or it receives a 429, 503, or 504 HTTP response. The default is 0, which means the call won’t be retried.

  • notifications_log_enabled (Boolean) (defaults to: :unset)

    Whether to log notifications. The default is ‘false`.

Returns:



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 220

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_new_message_sound: :unset, 
    notifications_new_message_badge_count_enabled: :unset, 
    notifications_added_to_channel_enabled: :unset, 
    notifications_added_to_channel_template: :unset, 
    notifications_added_to_channel_sound: :unset, 
    notifications_removed_from_channel_enabled: :unset, 
    notifications_removed_from_channel_template: :unset, 
    notifications_removed_from_channel_sound: :unset, 
    notifications_invited_to_channel_enabled: :unset, 
    notifications_invited_to_channel_template: :unset, 
    notifications_invited_to_channel_sound: :unset, 
    pre_webhook_url: :unset, 
    post_webhook_url: :unset, 
    webhook_method: :unset, 
    webhook_filters: :unset, 
    limits_channel_members: :unset, 
    limits_user_channels: :unset, 
    media_compatibility_message: :unset, 
    pre_webhook_retry_count: :unset, 
    post_webhook_retry_count: :unset, 
    notifications_log_enabled: :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.NewMessage.Sound' => notifications_new_message_sound,
        'Notifications.NewMessage.BadgeCountEnabled' => notifications_new_message_badge_count_enabled,
        'Notifications.AddedToChannel.Enabled' => notifications_added_to_channel_enabled,
        'Notifications.AddedToChannel.Template' => notifications_added_to_channel_template,
        'Notifications.AddedToChannel.Sound' => notifications_added_to_channel_sound,
        'Notifications.RemovedFromChannel.Enabled' => notifications_removed_from_channel_enabled,
        'Notifications.RemovedFromChannel.Template' => notifications_removed_from_channel_template,
        'Notifications.RemovedFromChannel.Sound' => notifications_removed_from_channel_sound,
        'Notifications.InvitedToChannel.Enabled' => notifications_invited_to_channel_enabled,
        'Notifications.InvitedToChannel.Template' => notifications_invited_to_channel_template,
        'Notifications.InvitedToChannel.Sound' => notifications_invited_to_channel_sound,
        'PreWebhookUrl' => pre_webhook_url,
        'PostWebhookUrl' => post_webhook_url,
        'WebhookMethod' => webhook_method,
        'WebhookFilters' => Twilio.serialize_list(webhook_filters) { |e| e },
        'Limits.ChannelMembers' => limits_channel_members,
        'Limits.UserChannels' => limits_user_channels,
        'Media.CompatibilityMessage' => media_compatibility_message,
        'PreWebhookRetryCount' => pre_webhook_retry_count,
        'PostWebhookRetryCount' => post_webhook_retry_count,
        'Notifications.LogEnabled' => notifications_log_enabled,
    })

    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)


357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/twilio-ruby/rest/chat/v2/service.rb', line 357

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