Class: Twilio::REST::Proxy::V1::ServiceContext

Inherits:
InstanceContext show all
Defined in:
lib/twilio-ruby/rest/proxy/v1/service.rb,
lib/twilio-ruby/rest/proxy/v1/service/session.rb,
lib/twilio-ruby/rest/proxy/v1/service/short_code.rb,
lib/twilio-ruby/rest/proxy/v1/service/phone_number.rb,
lib/twilio-ruby/rest/proxy/v1/service/session/interaction.rb,
lib/twilio-ruby/rest/proxy/v1/service/session/participant.rb,
lib/twilio-ruby/rest/proxy/v1/service/session/participant/message_interaction.rb

Overview

PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.

Defined Under Namespace

Classes: PhoneNumberContext, PhoneNumberInstance, PhoneNumberList, PhoneNumberPage, SessionContext, SessionInstance, SessionList, SessionPage, ShortCodeContext, ShortCodeInstance, ShortCodeList, ShortCodePage

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.



220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 220

def initialize(version, sid)
  super(version)

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

  # Dependents
  @sessions = nil
  @phone_numbers = nil
  @short_codes = nil
end

Instance Method Details

#deleteBoolean

Deletes the ServiceInstance

Returns:

  • (Boolean)

    true if delete succeeds, true otherwise



251
252
253
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 251

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

#fetchServiceInstance

Fetch a ServiceInstance

Returns:



236
237
238
239
240
241
242
243
244
245
246
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 236

def fetch
  params = Twilio::Values.of({})

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

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

#inspectObject

Provide a detailed, user friendly representation



380
381
382
383
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 380

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

#phone_numbers(sid = :unset) ⇒ PhoneNumberList, PhoneNumberContext

Access the phone_numbers

Returns:

Raises:

  • (ArgumentError)


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

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

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

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

  @phone_numbers
end

#sessions(sid = :unset) ⇒ SessionList, SessionContext

Access the sessions

Returns:

Raises:

  • (ArgumentError)


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

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

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

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

  @sessions
end

#short_codes(sid = :unset) ⇒ ShortCodeList, ShortCodeContext

Access the short_codes

Returns:

Raises:

  • (ArgumentError)


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

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

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

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

  @short_codes
end

#to_sObject

Provide a user friendly representation



373
374
375
376
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 373

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

#update(unique_name: :unset, default_ttl: :unset, callback_url: :unset, geo_match_level: :unset, number_selection_behavior: :unset, intercept_callback_url: :unset, out_of_session_callback_url: :unset, chat_instance_sid: :unset) ⇒ ServiceInstance

Update the ServiceInstance

Parameters:

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

    An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**

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

    The default ‘ttl` value to set for Sessions created in the Service. The TTL (time to live) is measured in seconds after the Session’s last create or last Interaction. The default value of ‘0` indicates an unlimited Session length. You can override a Session’s default TTL value by setting its ‘ttl` value.

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

    The URL we should call when the interaction status changes.

  • geo_match_level (service.GeoMatchLevel) (defaults to: :unset)

    Where a proxy number must be located relative to the participant identifier. Can be: ‘country`, `area-code`, or `extended-area-code`. The default value is `country` and more specific areas than `country` are only available in North America.

  • number_selection_behavior (service.NumberSelectionBehavior) (defaults to: :unset)

    The preference for Proxy Number selection in the Service instance. Can be: ‘prefer-sticky` or `avoid-sticky` and the default is `prefer-sticky`. `prefer-sticky` means that we will try and select the same Proxy Number for a given participant if they have previous [Sessions](www.twilio.com/docs/proxy/api/session), but we will not fail if that Proxy Number cannot be used. `avoid-sticky` means that we will try to use different Proxy Numbers as long as that is possible within a given pool rather than try and use a previously assigned number.

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

    The URL we call on each interaction. If we receive a 403 status, we block the interaction; otherwise the interaction continues.

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

    The URL we should call when an inbound call or SMS action occurs on a closed or non-existent Session. If your server (or a Twilio [function](www.twilio.com/functions)) responds with valid [TwiML](www.twilio.com/docs/voice/twiml), we will process it. This means it is possible, for example, to play a message for a call, send an automated text message response, or redirect a call to another Phone Number. See [Out-of-Session Callback Response Guide](www.twilio.com/docs/proxy/out-session-callback-response-guide) for more information.

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

    The SID of the Chat Service Instance managed by Proxy Service. The Chat Service enables Proxy to forward SMS and channel messages to this chat instance. This is a one-to-one relationship.

Returns:



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 296

def update(unique_name: :unset, default_ttl: :unset, callback_url: :unset, geo_match_level: :unset, number_selection_behavior: :unset, intercept_callback_url: :unset, out_of_session_callback_url: :unset, chat_instance_sid: :unset)
  data = Twilio::Values.of({
      'UniqueName' => unique_name,
      'DefaultTtl' => default_ttl,
      'CallbackUrl' => callback_url,
      'GeoMatchLevel' => geo_match_level,
      'NumberSelectionBehavior' => number_selection_behavior,
      'InterceptCallbackUrl' => intercept_callback_url,
      'OutOfSessionCallbackUrl' => out_of_session_callback_url,
      'ChatInstanceSid' => chat_instance_sid,
  })

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

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