Class: Twilio::REST::Conversations::V1::ServiceContext::ConversationContext::MessageContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb,
lib/twilio-ruby/rest/conversations/v1/service/conversation/message/delivery_receipt.rb

Defined Under Namespace

Classes: DeliveryReceiptContext, DeliveryReceiptInstance, DeliveryReceiptInstanceMetadata, DeliveryReceiptList, DeliveryReceiptListResponse, DeliveryReceiptPage, DeliveryReceiptPageMetadata

Instance Method Summary collapse

Constructor Details

#initialize(version, chat_service_sid, conversation_sid, sid) ⇒ MessageContext

Initialize the MessageContext

Parameters:



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

def initialize(version, chat_service_sid, conversation_sid, sid)
    super(version)
    

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

    # Dependents
    @delivery_receipts = nil
end

Instance Method Details

#delete(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the MessageInstance

Parameters:

  • x_twilio_webhook_enabled (ServiceConversationMessageEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 299

def delete(
    x_twilio_webhook_enabled: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    

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

#delete_with_metadata(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the MessageInstanceMetadata

Parameters:

  • x_twilio_webhook_enabled (ServiceConversationMessageEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 315

def (
  x_twilio_webhook_enabled: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    
      response = @version.('DELETE', @uri, headers: headers)
      message_instance = MessageInstance.new(
          @version,
          response.body,
          account_sid: @solution[:account_sid],
          sid: @solution[:sid],
      )
      .new(@version, message_instance, response.headers, response.status_code)
end

#delivery_receipts(sid = :unset) ⇒ DeliveryReceiptList, DeliveryReceiptContext

Access the delivery_receipts

Returns:

Raises:

  • (ArgumentError)


481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 481

def delivery_receipts(sid=:unset)

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

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

    unless @delivery_receipts
        @delivery_receipts = DeliveryReceiptList.new(
            @version, chat_service_sid: @solution[:chat_service_sid], conversation_sid: @solution[:conversation_sid], message_sid: @solution[:sid], )
    end

 @delivery_receipts
end

#fetchMessageInstance

Fetch the MessageInstance

Returns:



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 336

def fetch

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.fetch('GET', @uri, headers: headers)
    MessageInstance.new(
        @version,
        payload,
        chat_service_sid: @solution[:chat_service_sid],
        conversation_sid: @solution[:conversation_sid],
        sid: @solution[:sid],
    )
end

#fetch_with_metadataMessageInstance

Fetch the MessageInstanceMetadata

Returns:



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 357

def 

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('GET', @uri, headers: headers)
    message_instance = MessageInstance.new(
        @version,
        response.body,
        chat_service_sid: @solution[:chat_service_sid],
        conversation_sid: @solution[:conversation_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        message_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



506
507
508
509
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 506

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

#to_sObject

Provide a user friendly representation



499
500
501
502
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 499

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

#update(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, subject: :unset, x_twilio_webhook_enabled: :unset) ⇒ MessageInstance

Update the MessageInstance

Parameters:

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

    The channel specific identifier of the message’s author. Defaults to system.

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

    The content of the message, can be up to 1,600 characters long.

  • 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. null if the message has not been edited.

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

    A string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that if the attributes are not set \"{}\" will be returned.

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

    The subject of the message, can be up to 256 characters long.

  • x_twilio_webhook_enabled (ServiceConversationMessageEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 391

def update(
    author: :unset, 
    body: :unset, 
    date_created: :unset, 
    date_updated: :unset, 
    attributes: :unset, 
    subject: :unset, 
    x_twilio_webhook_enabled: :unset
)

    data = Twilio::Values.of({
        'Author' => author,
        'Body' => body,
        'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
        'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
        'Attributes' => attributes,
        'Subject' => subject,
    })

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    
    
    
    payload = @version.update('POST', @uri, data: data, headers: headers)
    MessageInstance.new(
        @version,
        payload,
        chat_service_sid: @solution[:chat_service_sid],
        conversation_sid: @solution[:conversation_sid],
        sid: @solution[:sid],
    )
end

#update_with_metadata(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, subject: :unset, x_twilio_webhook_enabled: :unset) ⇒ MessageInstance

Update the MessageInstanceMetadata

Parameters:

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

    The channel specific identifier of the message’s author. Defaults to system.

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

    The content of the message, can be up to 1,600 characters long.

  • 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. null if the message has not been edited.

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

    A string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that if the attributes are not set \"{}\" will be returned.

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

    The subject of the message, can be up to 256 characters long.

  • x_twilio_webhook_enabled (ServiceConversationMessageEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 436

def (
  author: :unset, 
  body: :unset, 
  date_created: :unset, 
  date_updated: :unset, 
  attributes: :unset, 
  subject: :unset, 
  x_twilio_webhook_enabled: :unset
)

    data = Twilio::Values.of({
        'Author' => author,
        'Body' => body,
        'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
        'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
        'Attributes' => attributes,
        'Subject' => subject,
    })

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    
    
    
    response = @version.('POST', @uri, data: data, headers: headers)
    message_instance = MessageInstance.new(
        @version,
        response.body,
        chat_service_sid: @solution[:chat_service_sid],
        conversation_sid: @solution[:conversation_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        message_instance,
        response.headers,
        response.status_code
    )
end