Class: Twilio::REST::Api::V2010::AccountContext::MessageInstance

Inherits:
InstanceResource
  • Object
show all
Defined in:
lib/twilio-ruby/rest/api/v2010/account/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(version, payload, account_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) (defaults to: nil)

    The SID of the Account that created this Message resource.

  • sid (String) (defaults to: nil)

    The SID of the Call resource to fetch.



418
419
420
421
422
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
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 418

def initialize(version, payload , account_sid: nil, sid: nil)
    super(version)
    
    # Marshaled Properties
    @properties = { 
        'body' => payload['body'],
        'num_segments' => payload['num_segments'],
        'direction' => payload['direction'],
        'from' => payload['from'],
        'to' => payload['to'],
        'date_updated' => Twilio.deserialize_rfc2822(payload['date_updated']),
        'price' => payload['price'],
        'error_message' => payload['error_message'],
        'uri' => payload['uri'],
        'account_sid' => payload['account_sid'],
        'num_media' => payload['num_media'],
        'status' => payload['status'],
        'messaging_service_sid' => payload['messaging_service_sid'],
        'sid' => payload['sid'],
        'date_sent' => Twilio.deserialize_rfc2822(payload['date_sent']),
        'date_created' => Twilio.deserialize_rfc2822(payload['date_created']),
        'error_code' => payload['error_code'] == nil ? payload['error_code'] : payload['error_code'].to_i,
        'price_unit' => payload['price_unit'],
        'api_version' => payload['api_version'],
        'subresource_uris' => payload['subresource_uris'],
    }

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

Instance Method Details

#account_sidString

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

Returns:



517
518
519
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 517

def 
    @properties['account_sid']
end

#api_versionString

Returns The API version used to process the Message.

Returns:

  • (String)

    The API version used to process the Message



571
572
573
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 571

def api_version
    @properties['api_version']
end

#bodyString

Returns The text content of the message.

Returns:

  • (String)

    The text content of the message



463
464
465
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 463

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:



454
455
456
457
458
459
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 454

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

#date_createdTime

Returns The [RFC 2822](datatracker.ietf.org/doc/html/rfc2822#section-3.3) timestamp (in GMT) of when the Message resource was created.

Returns:



553
554
555
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 553

def date_created
    @properties['date_created']
end

#date_sentTime

Returns The [RFC 2822](datatracker.ietf.org/doc/html/rfc2822#section-3.3) timestamp (in GMT) of when the Message was sent. For an outgoing message, this is when Twilio sent the message. For an incoming message, this is when Twilio sent the HTTP request to your incoming message webhook URL.

Returns:

  • (Time)

    The [RFC 2822](datatracker.ietf.org/doc/html/rfc2822#section-3.3) timestamp (in GMT) of when the Message was sent. For an outgoing message, this is when Twilio sent the message. For an incoming message, this is when Twilio sent the HTTP request to your incoming message webhook URL.



547
548
549
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 547

def date_sent
    @properties['date_sent']
end

#date_updatedTime

Returns The [RFC 2822](datatracker.ietf.org/doc/html/rfc2822#section-3.3) timestamp (in GMT) of when the Message resource was last updated.

Returns:



493
494
495
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 493

def date_updated
    @properties['date_updated']
end

#deleteBoolean

Delete the MessageInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



584
585
586
587
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 584

def delete

    context.delete
end

#directionDirection

Returns:

  • (Direction)


475
476
477
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 475

def direction
    @properties['direction']
end

#error_codeString

Returns The [error code](www.twilio.com/docs/api/errors) returned if the Message ‘status` is `failed` or `undelivered`. If no error was encountered, the value is `null`. The value returned in this field for a specific error cause is subject to change as Twilio improves errors. Users should not use the `error_code` and `error_message` fields programmatically.

Returns:

  • (String)

    The [error code](www.twilio.com/docs/api/errors) returned if the Message ‘status` is `failed` or `undelivered`. If no error was encountered, the value is `null`. The value returned in this field for a specific error cause is subject to change as Twilio improves errors. Users should not use the `error_code` and `error_message` fields programmatically.



559
560
561
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 559

def error_code
    @properties['error_code']
end

#error_messageString

Returns The description of the ‘error_code` if the Message `status` is `failed` or `undelivered`. If no error was encountered, the value is `null`. The value returned in this field for a specific error cause is subject to change as Twilio improves errors. Users should not use the `error_code` and `error_message` fields programmatically.

Returns:

  • (String)

    The description of the ‘error_code` if the Message `status` is `failed` or `undelivered`. If no error was encountered, the value is `null`. The value returned in this field for a specific error cause is subject to change as Twilio improves errors. Users should not use the `error_code` and `error_message` fields programmatically.



505
506
507
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 505

def error_message
    @properties['error_message']
end

#feedbackfeedback

Access the feedback

Returns:



616
617
618
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 616

def feedback
    context.feedback
end

#fetchMessageInstance

Fetch the MessageInstance

Returns:



592
593
594
595
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 592

def fetch

    context.fetch
end

#fromString

Returns The sender’s phone number (in [E.164](en.wikipedia.org/wiki/E.164) format), [alphanumeric sender ID](www.twilio.com/docs/sms/quickstart), [Wireless SIM](www.twilio.com/docs/iot/wireless/programmable-wireless-send-machine-machine-sms-commands), [short code](www.twilio.com/en-us/messaging/channels/sms/short-codes), or [channel address](www.twilio.com/docs/messaging/channels) (e.g., ‘whatsapp:+15554449999`). For incoming messages, this is the number or channel address of the sender. For outgoing messages, this value is a Twilio phone number, alphanumeric sender ID, short code, or channel address from which the message is sent.

Returns:



481
482
483
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 481

def from
    @properties['from']
end

#inspectObject

Provide a detailed, user friendly representation



636
637
638
639
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 636

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

#mediamedia

Access the media

Returns:



623
624
625
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 623

def media
    context.media
end

#messaging_service_sidString

Returns The SID of the [Messaging Service](www.twilio.com/docs/messaging/api/service-resource) associated with the Message resource. A unique default value is assigned if a Messaging Service is not used.

Returns:



535
536
537
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 535

def messaging_service_sid
    @properties['messaging_service_sid']
end

#num_mediaString

Returns The number of media files associated with the Message resource.

Returns:

  • (String)

    The number of media files associated with the Message resource.



523
524
525
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 523

def num_media
    @properties['num_media']
end

#num_segmentsString

Returns The number of segments that make up the complete message. SMS message bodies that exceed the [character limit](www.twilio.com/docs/glossary/what-sms-character-limit) are segmented and charged as multiple messages. Note: For messages sent via a Messaging Service, ‘num_segments` is initially `0`, since a sender hasn’t yet been assigned.

Returns:

  • (String)

    The number of segments that make up the complete message. SMS message bodies that exceed the [character limit](www.twilio.com/docs/glossary/what-sms-character-limit) are segmented and charged as multiple messages. Note: For messages sent via a Messaging Service, ‘num_segments` is initially `0`, since a sender hasn’t yet been assigned.



469
470
471
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 469

def num_segments
    @properties['num_segments']
end

#priceString

Returns The amount billed for the message in the currency specified by ‘price_unit`. The `price` is populated after the message has been sent/received, and may not be immediately availalble. View the [Pricing page](www.twilio.com/en-us/pricing) for more details.

Returns:

  • (String)

    The amount billed for the message in the currency specified by ‘price_unit`. The `price` is populated after the message has been sent/received, and may not be immediately availalble. View the [Pricing page](www.twilio.com/en-us/pricing) for more details.



499
500
501
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 499

def price
    @properties['price']
end

#price_unitString

Returns The currency in which ‘price` is measured, in [ISO 4127](www.iso.org/iso/home/standards/currency_codes.htm) format (e.g. `usd`, `eur`, `jpy`).

Returns:



565
566
567
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 565

def price_unit
    @properties['price_unit']
end

#sidString

Returns The unique, Twilio-provided string that identifies the Message resource.

Returns:

  • (String)

    The unique, Twilio-provided string that identifies the Message resource.



541
542
543
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 541

def sid
    @properties['sid']
end

#statusStatus

Returns:

  • (Status)


529
530
531
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 529

def status
    @properties['status']
end

#subresource_urisHash

Returns A list of related resources identified by their URIs relative to ‘api.twilio.com`.

Returns:

  • (Hash)

    A list of related resources identified by their URIs relative to ‘api.twilio.com`



577
578
579
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 577

def subresource_uris
    @properties['subresource_uris']
end

#toString

Returns The recipient’s phone number (in [E.164](en.wikipedia.org/wiki/E.164) format) or [channel address](www.twilio.com/docs/messaging/channels) (e.g. ‘whatsapp:+15552229999`).

Returns:



487
488
489
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 487

def to
    @properties['to']
end

#to_sObject

Provide a user friendly representation



629
630
631
632
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 629

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

#update(body: :unset, status: :unset) ⇒ MessageInstance

Update the MessageInstance

Parameters:

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

    The new ‘body` of the Message resource. To redact the text content of a Message, this parameter’s value must be an empty string

  • status (UpdateStatus) (defaults to: :unset)

Returns:



602
603
604
605
606
607
608
609
610
611
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 602

def update(
    body: :unset, 
    status: :unset
)

    context.update(
        body: body, 
        status: status, 
    )
end

#uriString

Returns The URI of the Message resource, relative to ‘api.twilio.com`.

Returns:

  • (String)

    The URI of the Message resource, relative to ‘api.twilio.com`.



511
512
513
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 511

def uri
    @properties['uri']
end