Class: Twilio::REST::Preview::Proxy::ServiceContext::SessionContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/preview/proxy/service/session.rb,
lib/twilio-ruby/rest/preview/proxy/service/session/interaction.rb,
lib/twilio-ruby/rest/preview/proxy/service/session/participant.rb,
lib/twilio-ruby/rest/preview/proxy/service/session/participant/message_interaction.rb

Overview

PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact [email protected].

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 unique SID identifier of the Service.

  • sid (String)

    A 34 character string that uniquely identifies this Session.



224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/twilio-ruby/rest/preview/proxy/service/session.rb', line 224

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

Deletes the SessionInstance

Returns:

  • (Boolean)

    true if delete succeeds, true otherwise



262
263
264
# File 'lib/twilio-ruby/rest/preview/proxy/service/session.rb', line 262

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

#fetchSessionInstance

Fetch a SessionInstance

Returns:



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/twilio-ruby/rest/preview/proxy/service/session.rb', line 242

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

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

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

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

Access the interactions

Returns:

Raises:

  • (ArgumentError)


303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/twilio-ruby/rest/preview/proxy/service/session.rb', line 303

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)


330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/twilio-ruby/rest/preview/proxy/service/session.rb', line 330

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



355
356
357
358
# File 'lib/twilio-ruby/rest/preview/proxy/service/session.rb', line 355

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

#update(unique_name: :unset, ttl: :unset, status: :unset, participants: :unset) ⇒ SessionInstance

Update the SessionInstance

Parameters:

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

    Provides a unique and addressable name to be assigned to this Session, assigned by the developer, to be optionally used in addition to SID.

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

    How long will this session stay open, in seconds. Each new interaction resets this timer.

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

    The Status of this Session. One of ‘in-progess` or `completed`.

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

    The participants

Returns:



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/twilio-ruby/rest/preview/proxy/service/session.rb', line 277

def update(unique_name: :unset, ttl: :unset, status: :unset, participants: :unset)
  data = Twilio::Values.of({
      'UniqueName' => unique_name,
      'Ttl' => ttl,
      'Status' => status,
      'Participants' => participants,
  })

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

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