Class: Sendly::Message
- Inherits:
-
Object
- Object
- Sendly::Message
- Defined in:
- lib/sendly/types.rb
Overview
Represents an SMS message
Constant Summary collapse
- STATUSES =
Message status constants (sending removed - doesn’t exist in database)
%w[queued sent delivered failed bounced retrying].freeze
- SENDER_TYPES =
Sender type constants
%w[number_pool alphanumeric sandbox].freeze
Instance Attribute Summary collapse
-
#ai_metadata ⇒ Hash?
readonly
AI classification metadata for inbound messages.
-
#created_at ⇒ Time?
readonly
Creation timestamp.
-
#credits_used ⇒ Integer
readonly
Credits used.
-
#delivered_at ⇒ Time?
readonly
Delivery timestamp.
-
#direction ⇒ String
readonly
Message direction (outbound or inbound).
-
#error ⇒ String?
readonly
Error message if failed.
-
#error_code ⇒ String?
readonly
Error code if delivery failed.
-
#from ⇒ String?
readonly
Sender ID or phone number.
-
#id ⇒ String
readonly
Unique message identifier.
-
#is_sandbox ⇒ Boolean
readonly
Whether sent in sandbox mode.
-
#metadata ⇒ Hash?
readonly
Custom metadata attached to the message.
-
#retry_count ⇒ Integer
readonly
Number of delivery retry attempts.
-
#segments ⇒ Integer
readonly
Number of SMS segments.
-
#sender_note ⇒ String?
readonly
Note about sender behavior.
-
#sender_type ⇒ String?
readonly
How the message was sent (number_pool, alphanumeric, sandbox).
-
#status ⇒ String
readonly
Delivery status.
-
#telnyx_message_id ⇒ String?
readonly
Carrier message ID for tracking.
-
#text ⇒ String
readonly
Message content.
-
#to ⇒ String
readonly
Recipient phone number.
-
#warning ⇒ String?
readonly
Warning message.
Instance Method Summary collapse
-
#delivered? ⇒ Boolean
Check if message was delivered.
-
#failed? ⇒ Boolean
Check if message failed.
-
#initialize(data) ⇒ Message
constructor
A new instance of Message.
-
#pending? ⇒ Boolean
Check if message is pending.
-
#to_h ⇒ Hash
Convert to hash.
Constructor Details
#initialize(data) ⇒ Message
Returns a new instance of Message.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sendly/types.rb', line 72 def initialize(data) @id = data["id"] @to = data["to"] @from = data["from"] @text = data["text"] @status = data["status"] @direction = data["direction"] || "outbound" @error = data["error"] @segments = data["segments"] || 1 @credits_used = data["creditsUsed"] || 0 @is_sandbox = data["isSandbox"] || false @sender_type = data["senderType"] @telnyx_message_id = data["telnyxMessageId"] @warning = data["warning"] @sender_note = data["senderNote"] @created_at = parse_time(data["createdAt"]) @delivered_at = parse_time(data["deliveredAt"]) @error_code = data["errorCode"] @retry_count = data["retryCount"] || 0 @metadata = data["metadata"] @ai_metadata = data["aiMetadata"] end |
Instance Attribute Details
#ai_metadata ⇒ Hash? (readonly)
Returns AI classification metadata for inbound messages.
64 65 66 |
# File 'lib/sendly/types.rb', line 64 def @ai_metadata end |
#created_at ⇒ Time? (readonly)
Returns Creation timestamp.
49 50 51 |
# File 'lib/sendly/types.rb', line 49 def created_at @created_at end |
#credits_used ⇒ Integer (readonly)
Returns Credits used.
31 32 33 |
# File 'lib/sendly/types.rb', line 31 def credits_used @credits_used end |
#delivered_at ⇒ Time? (readonly)
Returns Delivery timestamp.
52 53 54 |
# File 'lib/sendly/types.rb', line 52 def delivered_at @delivered_at end |
#direction ⇒ String (readonly)
Returns Message direction (outbound or inbound).
22 23 24 |
# File 'lib/sendly/types.rb', line 22 def direction @direction end |
#error ⇒ String? (readonly)
Returns Error message if failed.
25 26 27 |
# File 'lib/sendly/types.rb', line 25 def error @error end |
#error_code ⇒ String? (readonly)
Returns Error code if delivery failed.
55 56 57 |
# File 'lib/sendly/types.rb', line 55 def error_code @error_code end |
#from ⇒ String? (readonly)
Returns Sender ID or phone number.
13 14 15 |
# File 'lib/sendly/types.rb', line 13 def from @from end |
#id ⇒ String (readonly)
Returns Unique message identifier.
7 8 9 |
# File 'lib/sendly/types.rb', line 7 def id @id end |
#is_sandbox ⇒ Boolean (readonly)
Returns Whether sent in sandbox mode.
34 35 36 |
# File 'lib/sendly/types.rb', line 34 def is_sandbox @is_sandbox end |
#metadata ⇒ Hash? (readonly)
Returns Custom metadata attached to the message.
61 62 63 |
# File 'lib/sendly/types.rb', line 61 def @metadata end |
#retry_count ⇒ Integer (readonly)
Returns Number of delivery retry attempts.
58 59 60 |
# File 'lib/sendly/types.rb', line 58 def retry_count @retry_count end |
#segments ⇒ Integer (readonly)
Returns Number of SMS segments.
28 29 30 |
# File 'lib/sendly/types.rb', line 28 def segments @segments end |
#sender_note ⇒ String? (readonly)
Returns Note about sender behavior.
46 47 48 |
# File 'lib/sendly/types.rb', line 46 def sender_note @sender_note end |
#sender_type ⇒ String? (readonly)
Returns How the message was sent (number_pool, alphanumeric, sandbox).
37 38 39 |
# File 'lib/sendly/types.rb', line 37 def sender_type @sender_type end |
#status ⇒ String (readonly)
Returns Delivery status.
19 20 21 |
# File 'lib/sendly/types.rb', line 19 def status @status end |
#telnyx_message_id ⇒ String? (readonly)
Returns Carrier message ID for tracking.
40 41 42 |
# File 'lib/sendly/types.rb', line 40 def @telnyx_message_id end |
#text ⇒ String (readonly)
Returns Message content.
16 17 18 |
# File 'lib/sendly/types.rb', line 16 def text @text end |
#to ⇒ String (readonly)
Returns Recipient phone number.
10 11 12 |
# File 'lib/sendly/types.rb', line 10 def to @to end |
#warning ⇒ String? (readonly)
Returns Warning message.
43 44 45 |
# File 'lib/sendly/types.rb', line 43 def warning @warning end |
Instance Method Details
#delivered? ⇒ Boolean
Check if message was delivered
97 98 99 |
# File 'lib/sendly/types.rb', line 97 def delivered? status == "delivered" end |
#failed? ⇒ Boolean
Check if message failed
103 104 105 |
# File 'lib/sendly/types.rb', line 103 def failed? status == "failed" end |
#pending? ⇒ Boolean
Check if message is pending
109 110 111 |
# File 'lib/sendly/types.rb', line 109 def pending? %w[queued sending sent].include?(status) end |
#to_h ⇒ Hash
Convert to hash
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/sendly/types.rb', line 115 def to_h { id: id, to: to, from: from, text: text, status: status, direction: direction, error: error, segments: segments, credits_used: credits_used, is_sandbox: is_sandbox, sender_type: sender_type, telnyx_message_id: , warning: warning, sender_note: sender_note, created_at: created_at&.iso8601, delivered_at: delivered_at&.iso8601, error_code: error_code, retry_count: retry_count, metadata: , ai_metadata: }.compact end |