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

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/proxy/v1/service/session.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: InteractionContext, InteractionInstance, InteractionList, InteractionPage, ParticipantContext, ParticipantInstance, ParticipantList, ParticipantPage

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, sid) ⇒ SessionContext

Initialize the SessionContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The SID of the parent [Service](www.twilio.com/docs/proxy/api/service) of the resource to fetch.

  • sid (String)

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



208
209
210
211
212
213
214
215
216
217
218
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 208

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

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

  # Dependents
  @interactions = nil
  @participants = nil
end

Instance Method Details

#deleteBoolean

Delete the SessionInstance

Returns:

  • (Boolean)

    true if delete succeeds, false otherwise



232
233
234
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 232

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

#fetchSessionInstance

Fetch the SessionInstance

Returns:



223
224
225
226
227
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 223

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

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

#inspectObject

Provide a detailed, user friendly representation



322
323
324
325
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 322

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

#interactions(sid = :unset) ⇒ InteractionList, InteractionContext

Access the interactions

Returns:

Raises:

  • (ArgumentError)


273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 273

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

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

  unless @interactions
    @interactions = InteractionList.new(
        @version,
        service_sid: @solution[:service_sid],
        session_sid: @solution[:sid],
    )
  end

  @interactions
end

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

Access the participants

Returns:

Raises:

  • (ArgumentError)


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

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

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

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

  @participants
end

#to_sObject

Provide a user friendly representation



315
316
317
318
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 315

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

#update(date_expiry: :unset, ttl: :unset, status: :unset, fail_on_participant_conflict: :unset) ⇒ SessionInstance

Update the SessionInstance

Parameters:

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

    The [ISO 8601](en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the ‘ttl` value.

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

    The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session’s last Interaction.

  • status (session.Status) (defaults to: :unset)

    The new status of the resource. Can be: ‘in-progress` to re-open a session or `closed` to close a session.

  • fail_on_participant_conflict (Boolean) (defaults to: :unset)
    Experimental

    Setting to true

    enables early opt-in to allowing Proxy to return a 400 error (Twilio error code 80604) when a request to set a Session to in-progress would cause Participants with the same Identifier/ProxyIdentifier pair to be active in multiple Sessions. If not provided, or if set to false, requests will be allowed to succeed, and a Debugger notification (80801) will be emitted. Having multiple, active Participants with the same Identifier/ProxyIdentifier pair causes calls and messages from affected Participants to be routed incorrectly. Please note, in a future release, the default behavior will be to reject the request with a 400 error unless an exception has been requested.

Returns:



256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 256

def update(date_expiry: :unset, ttl: :unset, status: :unset, fail_on_participant_conflict: :unset)
  data = Twilio::Values.of({
      'DateExpiry' => Twilio.serialize_iso8601_datetime(date_expiry),
      'Ttl' => ttl,
      'Status' => status,
      'FailOnParticipantConflict' => fail_on_participant_conflict,
  })

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

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