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

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

Instance Method Summary collapse

Constructor Details

#initialize(version, payload, service_sid: nil, channel_sid: nil, sid: nil) ⇒ MessageInstance

Initialize the MessageInstance

Parameters:

  • version (Version)

    Version that contains the resource

  • payload (Hash)

    payload that contains response from Twilio

  • account_sid (String)

    The SID of the Account that created this Message resource.

  • sid (String) (defaults to: nil)

    The SID of the Call resource to fetch.



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 321

def initialize(version, payload , service_sid: nil, channel_sid: nil, sid: nil)
    super(version)
    
    # Marshaled Properties
    @properties = { 
        'sid' => payload['sid'],
        'account_sid' => payload['account_sid'],
        'attributes' => payload['attributes'],
        'service_sid' => payload['service_sid'],
        'to' => payload['to'],
        'channel_sid' => payload['channel_sid'],
        'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
        'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
        'last_updated_by' => payload['last_updated_by'],
        'was_edited' => payload['was_edited'],
        'from' => payload['from'],
        'body' => payload['body'],
        'index' => payload['index'] == nil ? payload['index'] : payload['index'].to_i,
        'type' => payload['type'],
        'media' => payload['media'],
        'url' => payload['url'],
    }

    # Context
    @instance_context = nil
    @params = { 'service_sid' => service_sid  || @properties['service_sid']  ,'channel_sid' => channel_sid  || @properties['channel_sid']  ,'sid' => sid  || @properties['sid']  , }
end

Instance Method Details

#account_sidString

Returns The SID of the [Account](www.twilio.com/docs/iam/api/account) that created the Message resource.

Returns:



368
369
370
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 368

def 
    @properties['account_sid']
end

#attributesString

Returns The JSON string that stores application-specific data. If attributes have not been set, ‘{}` is returned.

Returns:

  • (String)

    The JSON string that stores application-specific data. If attributes have not been set, ‘{}` is returned.



374
375
376
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 374

def attributes
    @properties['attributes']
end

#bodyString

Returns The content of the message.

Returns:

  • (String)

    The content of the message.



428
429
430
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 428

def body
    @properties['body']
end

#channel_sidString

Returns The SID of the [Channel](www.twilio.com/docs/chat/channels) the Message resource belongs to.

Returns:



392
393
394
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 392

def channel_sid
    @properties['channel_sid']
end

#contextMessageContext

Generate an instance context for the instance, the context is capable of performing various actions. All instance actions are proxied to the context

Returns:



353
354
355
356
357
358
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 353

def context
    unless @instance_context
        @instance_context = MessageContext.new(@version , @params['service_sid'], @params['channel_sid'], @params['sid'])
    end
    @instance_context
end

#date_createdTime

Returns The date and time in GMT when the resource was created specified in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format.

Returns:



398
399
400
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 398

def date_created
    @properties['date_created']
end

#date_updatedTime

Returns The date and time in GMT when the resource was last updated specified in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format.

Returns:



404
405
406
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 404

def date_updated
    @properties['date_updated']
end

#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



460
461
462
463
464
465
466
467
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 460

def delete(
    x_twilio_webhook_enabled: :unset
)

    context.delete(
        x_twilio_webhook_enabled: x_twilio_webhook_enabled, 
    )
end

#fetchMessageInstance

Fetch the MessageInstance

Returns:



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

def fetch

    context.fetch
end

#fromString

Returns The [Identity](www.twilio.com/docs/chat/identity) of the message’s author. The default value is ‘system`.

Returns:



422
423
424
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 422

def from
    @properties['from']
end

#indexString

Returns The index of the message within the [Channel](www.twilio.com/docs/chat/channels). Indices may skip numbers, but will always be in order of when the message was received.

Returns:

  • (String)

    The index of the message within the [Channel](www.twilio.com/docs/chat/channels). Indices may skip numbers, but will always be in order of when the message was received.



434
435
436
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 434

def index
    @properties['index']
end

#inspectObject

Provide a detailed, user friendly representation



517
518
519
520
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 517

def inspect
    values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
    "<Twilio.Chat.V2.MessageInstance #{values}>"
end

#last_updated_byString

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

Returns:



410
411
412
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 410

def last_updated_by
    @properties['last_updated_by']
end

#mediaHash

Returns An object that describes the Message’s media, if the message contains media. The object contains these fields: ‘content_type` with the MIME type of the media, `filename` with the name of the media, `sid` with the SID of the Media resource, and `size` with the media object’s file size in bytes. If the Message has no media, this value is ‘null`.

Returns:

  • (Hash)

    An object that describes the Message’s media, if the message contains media. The object contains these fields: ‘content_type` with the MIME type of the media, `filename` with the name of the media, `sid` with the SID of the Media resource, and `size` with the media object’s file size in bytes. If the Message has no media, this value is ‘null`.



446
447
448
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 446

def media
    @properties['media']
end

#service_sidString

Returns The SID of the [Service](www.twilio.com/docs/chat/rest/service-resource) the Message resource is associated with.

Returns:



380
381
382
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 380

def service_sid
    @properties['service_sid']
end

#sidString

Returns The unique string that we created to identify the Message resource.

Returns:

  • (String)

    The unique string that we created to identify the Message resource.



362
363
364
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 362

def sid
    @properties['sid']
end

#toString

Returns The SID of the [Channel](www.twilio.com/docs/chat/channels) that the message was sent to.

Returns:



386
387
388
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 386

def to
    @properties['to']
end

#to_sObject

Provide a user friendly representation



510
511
512
513
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 510

def to_s
    values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
    "<Twilio.Chat.V2.MessageInstance #{values}>"
end

#typeString

Returns The Message type. Can be: ‘text` or `media`.

Returns:

  • (String)

    The Message type. Can be: ‘text` or `media`.



440
441
442
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 440

def type
    @properties['type']
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:



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 487

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

    context.update(
        body: body, 
        attributes: attributes, 
        date_created: date_created, 
        date_updated: date_updated, 
        last_updated_by: last_updated_by, 
        from: from, 
        x_twilio_webhook_enabled: x_twilio_webhook_enabled, 
    )
end

#urlString

Returns The absolute URL of the Message resource.

Returns:

  • (String)

    The absolute URL of the Message resource.



452
453
454
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 452

def url
    @properties['url']
end

#was_editedBoolean

Returns Whether the message has been edited since it was created.

Returns:

  • (Boolean)

    Whether the message has been edited since it was created.



416
417
418
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/message.rb', line 416

def was_edited
    @properties['was_edited']
end