Class: Twilio::REST::Chat::V2::ServiceContext::ChannelContext::MessageContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/chat/v2/service/channel/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, channel_sid, sid) ⇒ MessageContext

Initialize the MessageContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The SID of the [Service](www.twilio.com/docs/chat/rest/service-resource) to update the Message resource in.

  • channel_sid (String)

    The SID of the [Channel](www.twilio.com/docs/chat/channels) the Message resource to update belongs to. This value can be the Channel resource’s sid or unique_name.

  • sid (String)

    The SID of the Message resource to update.



272
273
274
275
276
277
278
279
280
281
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 272

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

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

    
end

Instance Method Details

#delete(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the MessageInstance

Parameters:

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

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



286
287
288
289
290
291
292
293
294
295
296
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 286

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 (MessageEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 302

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],
      )
      MessageInstanceMetadata.new(@version, message_instance, response.headers, response.status_code)
end

#fetchMessageInstance

Fetch the MessageInstance

Returns:



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 323

def fetch

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

#fetch_with_metadataMessageInstance

Fetch the MessageInstanceMetadata

Returns:



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 344

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,
        service_sid: @solution[:service_sid],
        channel_sid: @solution[:channel_sid],
        sid: @solution[:sid],
    )
    MessageInstanceMetadata.new(
        @version,
        message_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



474
475
476
477
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 474

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

#to_sObject

Provide a user friendly representation



467
468
469
470
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 467

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

#update(body: :unset, attributes: :unset, date_created: :unset, date_updated: :unset, last_updated_by: :unset, from: :unset, x_twilio_webhook_enabled: :unset) ⇒ MessageInstance

Update the MessageInstance

Parameters:

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

    The message to send to the channel. Can be an empty string or null, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.

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

    A valid JSON string that contains application-specific data.

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

    The date, specified in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat’s history is being recreated from a backup/separate source.

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

    The date, specified in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.

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

    The [Identity](www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.

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

    The [Identity](www.twilio.com/docs/chat/identity) of the message’s author.

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

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 378

def update(
    body: :unset, 
    attributes: :unset, 
    date_created: :unset, 
    date_updated: :unset, 
    last_updated_by: :unset, 
    from: :unset, 
    x_twilio_webhook_enabled: :unset
)

    data = Twilio::Values.of({
        'Body' => body,
        'Attributes' => attributes,
        'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
        'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
        'LastUpdatedBy' => last_updated_by,
        'From' => from,
    })

    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,
        service_sid: @solution[:service_sid],
        channel_sid: @solution[:channel_sid],
        sid: @solution[:sid],
    )
end

#update_with_metadata(body: :unset, attributes: :unset, date_created: :unset, date_updated: :unset, last_updated_by: :unset, from: :unset, x_twilio_webhook_enabled: :unset) ⇒ MessageInstance

Update the MessageInstanceMetadata

Parameters:

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

    The message to send to the channel. Can be an empty string or null, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.

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

    A valid JSON string that contains application-specific data.

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

    The date, specified in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat’s history is being recreated from a backup/separate source.

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

    The date, specified in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.

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

    The [Identity](www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.

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

    The [Identity](www.twilio.com/docs/chat/identity) of the message’s author.

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

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



423
424
425
426
427
428
429
430
431
432
433
434
435
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
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 423

def (
  body: :unset, 
  attributes: :unset, 
  date_created: :unset, 
  date_updated: :unset, 
  last_updated_by: :unset, 
  from: :unset, 
  x_twilio_webhook_enabled: :unset
)

    data = Twilio::Values.of({
        'Body' => body,
        'Attributes' => attributes,
        'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
        'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
        'LastUpdatedBy' => last_updated_by,
        'From' => from,
    })

    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,
        service_sid: @solution[:service_sid],
        channel_sid: @solution[:channel_sid],
        sid: @solution[:sid],
    )
    MessageInstanceMetadata.new(
        @version,
        message_instance,
        response.headers,
        response.status_code
    )
end