Class: Sendly::WhatsAppMessage

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#channelObject (readonly)

Returns the value of attribute channel.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def channel
  @channel
end

#created_atObject (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_usedObject (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

#fromObject (readonly)

Returns the value of attribute from.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def from
  @from
end

#idObject (readonly)

Returns the value of attribute id.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def id
  @id
end

#message_formatObject (readonly)

Returns the value of attribute message_format.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def message_format
  @message_format
end

#metadataObject (readonly)

Returns the value of attribute metadata.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def 
  @metadata
end

#segmentsObject (readonly)

Returns the value of attribute segments.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def segments
  @segments
end

#statusObject (readonly)

Returns the value of attribute status.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def status
  @status
end

#textObject (readonly)

Returns the value of attribute text.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def text
  @text
end

#toObject (readonly)

Returns the value of attribute to.



255
256
257
# File 'lib/sendly/whatsapp_resource.rb', line 255

def to
  @to
end

#whatsappObject (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

Returns:

  • (Boolean)


273
274
275
# File 'lib/sendly/whatsapp_resource.rb', line 273

def delivered?
  status == "delivered"
end

#failed?Boolean

Returns:

  • (Boolean)


277
278
279
# File 'lib/sendly/whatsapp_resource.rb', line 277

def failed?
  status == "failed"
end

#to_hObject



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: 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