Class: Sendly::WhatsAppMessage
- Inherits:
-
Object
- Object
- Sendly::WhatsAppMessage
- Defined in:
- lib/sendly/whatsapp_resource.rb
Overview
A sent WhatsApp message. Unlike Message, segments is always 1
(WhatsApp has no segment concept), text is nil for template and media
sends, and whatsapp carries the channel-specific details.
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#credits_used ⇒ Object
readonly
Returns the value of attribute credits_used.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#message_format ⇒ Object
readonly
Returns the value of attribute message_format.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#whatsapp ⇒ Object
readonly
Returns the value of attribute whatsapp.
Instance Method Summary collapse
- #delivered? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(data) ⇒ WhatsAppMessage
constructor
A new instance of WhatsAppMessage.
- #to_h ⇒ Object
Constructor Details
#initialize(data) ⇒ WhatsAppMessage
Returns a new instance of WhatsAppMessage.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/sendly/whatsapp_resource.rb', line 258 def initialize(data) @id = data["id"] @channel = data["channel"] || "whatsapp" @message_format = data["message_format"] || data["messageFormat"] || "whatsapp" @to = data["to"] @from = data["from"] @text = data["text"] @status = data["status"] @segments = data["segments"] || 1 @credits_used = data["creditsUsed"] || data["credits_used"] || 0 @whatsapp = data["whatsapp"] ? WhatsAppMessageDetails.new(data["whatsapp"]) : nil @created_at = data["createdAt"] || data["created_at"] @metadata = data["metadata"] end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def channel @channel end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def created_at @created_at end |
#credits_used ⇒ Object (readonly)
Returns the value of attribute credits_used.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def credits_used @credits_used end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def from @from end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def id @id end |
#message_format ⇒ Object (readonly)
Returns the value of attribute message_format.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def @message_format end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def @metadata end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def segments @segments end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def status @status end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def text @text end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def to @to end |
#whatsapp ⇒ Object (readonly)
Returns the value of attribute whatsapp.
255 256 257 |
# File 'lib/sendly/whatsapp_resource.rb', line 255 def whatsapp @whatsapp end |
Instance Method Details
#delivered? ⇒ Boolean
273 274 275 |
# File 'lib/sendly/whatsapp_resource.rb', line 273 def delivered? status == "delivered" end |
#failed? ⇒ Boolean
277 278 279 |
# File 'lib/sendly/whatsapp_resource.rb', line 277 def failed? status == "failed" end |
#to_h ⇒ Object
281 282 283 284 285 286 287 288 |
# File 'lib/sendly/whatsapp_resource.rb', line 281 def to_h { id: id, channel: channel, message_format: , to: to, from: from, text: text, status: status, segments: segments, credits_used: credits_used, whatsapp: whatsapp&.to_h, created_at: created_at, metadata: }.compact end |