Class: Twilio::REST::Conversations::V1::ConversationContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/conversations/v1/conversation.rb,
lib/twilio-ruby/rest/conversations/v1/conversation/message.rb,
lib/twilio-ruby/rest/conversations/v1/conversation/webhook.rb,
lib/twilio-ruby/rest/conversations/v1/conversation/participant.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: MessageContext, MessageInstance, MessageList, MessagePage, ParticipantContext, ParticipantInstance, ParticipantList, ParticipantPage, WebhookContext, WebhookInstance, WebhookList, WebhookPage

Instance Method Summary collapse

Constructor Details

#initialize(version, sid) ⇒ ConversationContext

Initialize the ConversationContext

Parameters:

  • version (Version)

    Version that contains the resource

  • sid (String)

    A 34 character string that uniquely identifies this resource.



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 185

def initialize(version, sid)
  super(version)

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

  # Dependents
  @participants = nil
  @messages = nil
  @webhooks = nil
end

Instance Method Details

#deleteBoolean

Deletes the ConversationInstance

Returns:

  • (Boolean)

    true if delete succeeds, true otherwise



224
225
226
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 224

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

#fetchConversationInstance

Fetch a ConversationInstance

Returns:



231
232
233
234
235
236
237
238
239
240
241
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 231

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

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

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

#inspectObject

Provide a detailed, user friendly representation



306
307
308
309
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 306

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

#messages(sid = :unset) ⇒ MessageList, MessageContext

Access the messages

Returns:

Raises:

  • (ArgumentError)


265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 265

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

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

  unless @messages
    @messages = MessageList.new(@version, conversation_sid: @solution[:sid], )
  end

  @messages
end

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

Access the participants

Returns:

Raises:

  • (ArgumentError)


247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 247

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

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

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

  @participants
end

#to_sObject

Provide a user friendly representation



299
300
301
302
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 299

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

#update(friendly_name: :unset, date_created: :unset, date_updated: :unset) ⇒ ConversationInstance

Update the ConversationInstance

Parameters:

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

    The human-readable name of this conversation, limited to 256 characters. Optional.

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

    The date that this resource was created.

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

    The date that this resource was last updated.

Returns:



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 205

def update(friendly_name: :unset, date_created: :unset, date_updated: :unset)
  data = Twilio::Values.of({
      'FriendlyName' => friendly_name,
      'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
      'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
  })

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

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

#webhooks(sid = :unset) ⇒ WebhookList, WebhookContext

Access the webhooks

Returns:

Raises:

  • (ArgumentError)


283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/twilio-ruby/rest/conversations/v1/conversation.rb', line 283

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

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

  unless @webhooks
    @webhooks = WebhookList.new(@version, conversation_sid: @solution[:sid], )
  end

  @webhooks
end