Class: Sendly::WhatsAppMessageDetails

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/whatsapp_resource.rb

Overview

WhatsApp-specific details on a sent message. kind is what was sent ("text", "media", or "template"); template carries the sent template's name, language, and billed category on template sends; message_id is the WhatsApp message id, nil until the first delivery report lands.

Constant Summary collapse

KINDS =
%w[text media template].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ WhatsAppMessageDetails

Returns a new instance of WhatsAppMessageDetails.



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/sendly/whatsapp_resource.rb', line 234

def initialize(data)
  @kind = data["kind"]
  if data["template"]
    @template = {
      name: data.dig("template", "name"),
      language: data.dig("template", "language"),
      category: data.dig("template", "category")
    }
  end
  @message_id = data["messageId"] || data["message_id"]
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



230
231
232
# File 'lib/sendly/whatsapp_resource.rb', line 230

def kind
  @kind
end

#message_idObject (readonly)

Returns the value of attribute message_id.



230
231
232
# File 'lib/sendly/whatsapp_resource.rb', line 230

def message_id
  @message_id
end

#templateObject (readonly)

Returns the value of attribute template.



230
231
232
# File 'lib/sendly/whatsapp_resource.rb', line 230

def template
  @template
end

Instance Method Details

#to_hObject



246
247
248
# File 'lib/sendly/whatsapp_resource.rb', line 246

def to_h
  { kind: kind, template: template, message_id: message_id }.compact
end