Class: Twilio::REST::Messaging::V1::SessionContext::MessageInstance

Inherits:
InstanceResource
  • Object
show all
Defined in:
lib/twilio-ruby/rest/messaging/v1/session/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, session_sid: nil, sid: nil) ⇒ MessageInstance

Initialize the MessageInstance

Parameters:

  • version (Version)

    Version that contains the resource

  • payload (Hash)

    payload that contains response from Twilio

  • session_sid (String) (defaults to: nil)

    The unique id of the [Session](www.twilio.com/docs/sessions/api/session) for this message.

  • sid (String) (defaults to: nil)

    A 34 character string that uniquely identifies this resource.



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 280

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

  # Marshaled Properties
  @properties = {
      'account_sid' => payload['account_sid'],
      'service_sid' => payload['service_sid'],
      'messaging_service_sid' => payload['messaging_service_sid'],
      'session_sid' => payload['session_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 = {'session_sid' => session_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.



317
318
319
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 317

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.



365
366
367
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 365

def attributes
  @properties['attributes']
end

#authorString

Returns The identity or the address of the device of the message’s author.

Returns:

  • (String)

    The identity or the address of the device of the message’s author.



353
354
355
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 353

def author
  @properties['author']
end

#bodyString

Returns The contents of the message.

Returns:

  • (String)

    The contents of the message.



359
360
361
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 359

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:



308
309
310
311
312
313
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 308

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

#date_createdTime

Returns The date that this resource was created.

Returns:

  • (Time)

    The date that this resource was created.



371
372
373
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 371

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.



377
378
379
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 377

def date_updated
  @properties['date_updated']
end

#deleteBoolean

Deletes the MessageInstance

Returns:

  • (Boolean)

    true if delete succeeds, true otherwise



419
420
421
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 419

def delete
  context.delete
end

#fetchMessageInstance

Fetch a MessageInstance

Returns:



390
391
392
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 390

def fetch
  context.fetch
end

#indexString

Returns The index of the message within the Session.

Returns:

  • (String)

    The index of the message within the Session



347
348
349
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 347

def index
  @properties['index']
end

#inspectObject

Provide a detailed, user friendly representation



432
433
434
435
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 432

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

#messaging_service_sidString

Returns The unique id of the SMS Service this message belongs to.

Returns:

  • (String)

    The unique id of the SMS Service this message belongs to.



329
330
331
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 329

def messaging_service_sid
  @properties['messaging_service_sid']
end

#service_sidString

Returns The unique id of the Chat Service this message belongs to.

Returns:

  • (String)

    The unique id of the Chat Service this message belongs to.



323
324
325
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 323

def service_sid
  @properties['service_sid']
end

#session_sidString

Returns The unique id of the Session for this message.

Returns:

  • (String)

    The unique id of the Session for this message.



335
336
337
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 335

def session_sid
  @properties['session_sid']
end

#sidString

Returns A 34 character string that uniquely identifies this resource.

Returns:

  • (String)

    A 34 character string that uniquely identifies this resource.



341
342
343
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 341

def sid
  @properties['sid']
end

#to_sObject

Provide a user friendly representation



425
426
427
428
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 425

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

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

Update the MessageInstance

Parameters:

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

    The [identity](www.twilio.com/docs/api/chat/guides/identity) of the message’s author. Defaults to ‘system`.

  • 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.

  • 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.

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

    The contents of the message.

Returns:



406
407
408
409
410
411
412
413
414
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 406

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

#urlString

Returns An absolute URL for this message.

Returns:

  • (String)

    An absolute URL for this message.



383
384
385
# File 'lib/twilio-ruby/rest/messaging/v1/session/message.rb', line 383

def url
  @properties['url']
end