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

Inherits:
InstanceResource
  • Object
show all
Defined in:
lib/twilio-ruby/rest/conversations/v1/conversation/message.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].

Instance Method Summary collapse

Constructor Details

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

Initialize the MessageInstance

Parameters:

  • version (Version)

    Version that contains the resource

  • payload (Hash)

    payload that contains response from Twilio

  • conversation_sid (String) (defaults to: nil)

    The unique id of the [Conversation](www.twilio.com/docs/conversations/api/conversation-resource) for this message.

  • sid (String) (defaults to: nil)

    A 34 character string that uniquely identifies this resource.



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 292

def initialize(version, payload, conversation_sid: nil, sid: nil)
  super(version)

  # Marshaled Properties
  @properties = {
      'account_sid' => payload['account_sid'],
      'conversation_sid' => payload['conversation_sid'],
      'sid' => payload['sid'],
      'index' => payload['index'].to_i,
      'author' => payload['author'],
      'body' => payload['body'],
      'attributes' => payload['attributes'],
      'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
      'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
      'url' => payload['url'],
  }

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

Instance Method Details

#account_sidString

Returns The unique id of the Account responsible for this message.

Returns:

  • (String)

    The unique id of the Account responsible for this message.



327
328
329
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 327

def 
  @properties['account_sid']
end

#attributesString

Returns A string metadata field you can use to store any data you wish.

Returns:

  • (String)

    A string metadata field you can use to store any data you wish.



363
364
365
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 363

def attributes
  @properties['attributes']
end

#authorString

Returns The channel specific identifier of the message’s author.

Returns:

  • (String)

    The channel specific identifier of the message’s author.



351
352
353
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 351

def author
  @properties['author']
end

#bodyString

Returns The content of the message.

Returns:

  • (String)

    The content of the message.



357
358
359
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 357

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



318
319
320
321
322
323
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 318

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

#conversation_sidString

Returns The unique id of the Conversation for this message.

Returns:

  • (String)

    The unique id of the Conversation for this message.



333
334
335
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 333

def conversation_sid
  @properties['conversation_sid']
end

#date_createdTime

Returns The date that this resource was created.

Returns:

  • (Time)

    The date that this resource was created.



369
370
371
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 369

def date_created
  @properties['date_created']
end

#date_updatedTime

Returns The date that this resource was last updated.

Returns:

  • (Time)

    The date that this resource was last updated.



375
376
377
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 375

def date_updated
  @properties['date_updated']
end

#deleteBoolean

Deletes the MessageInstance

Returns:

  • (Boolean)

    true if delete succeeds, false otherwise



411
412
413
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 411

def delete
  context.delete
end

#fetchMessageInstance

Fetch a MessageInstance

Returns:



418
419
420
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 418

def fetch
  context.fetch
end

#indexString

Returns The index of the message within the Conversation.

Returns:

  • (String)

    The index of the message within the Conversation.



345
346
347
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 345

def index
  @properties['index']
end

#inspectObject

Provide a detailed, user friendly representation



431
432
433
434
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 431

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

#sidString

Returns A 34 character string that uniquely identifies this resource.

Returns:

  • (String)

    A 34 character string that uniquely identifies this resource.



339
340
341
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 339

def sid
  @properties['sid']
end

#to_sObject

Provide a user friendly representation



424
425
426
427
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 424

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

#update(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :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.

Returns:



398
399
400
401
402
403
404
405
406
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 398

def update(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset)
  context.update(
      author: author,
      body: body,
      date_created: date_created,
      date_updated: date_updated,
      attributes: attributes,
  )
end

#urlString

Returns An absolute URL for this message.

Returns:

  • (String)

    An absolute URL for this message.



381
382
383
# File 'lib/twilio-ruby/rest/conversations/v1/conversation/message.rb', line 381

def url
  @properties['url']
end