Class: Whatsapp::Webhook::Message::Interactive

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/whatsapp/webhook/message/interactive.rb

Overview

An inbound reply to an interactive message — a button tap (button_reply) or a list row selection (list_reply).

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #from, #id, #referral, #timestamp, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

common_attributes

Constructor Details

#initialize(interactive_type:, reply_id:, title:, description: nil, **base_attributes) ⇒ Interactive

Returns a new instance of Interactive.



25
26
27
28
29
30
31
32
# File 'lib/ruby/whatsapp/webhook/message/interactive.rb', line 25

def initialize(interactive_type:, reply_id:, title:, description: nil, **base_attributes)
  super(**base_attributes)

  @interactive_type = interactive_type
  @reply_id = reply_id
  @title = title
  @description = description
end

Instance Attribute Details

#descriptionString?

Returns Only present for list_reply.

Returns:

  • (String, nil)

    Only present for list_reply.



23
24
25
# File 'lib/ruby/whatsapp/webhook/message/interactive.rb', line 23

def description
  @description
end

#interactive_typeString?

Returns Either "button_reply" or "list_reply".

Returns:

  • (String, nil)

    Either "button_reply" or "list_reply".



11
12
13
# File 'lib/ruby/whatsapp/webhook/message/interactive.rb', line 11

def interactive_type
  @interactive_type
end

#reply_idString?

Returns The id of the tapped button/row.

Returns:

  • (String, nil)

    The id of the tapped button/row.



15
16
17
# File 'lib/ruby/whatsapp/webhook/message/interactive.rb', line 15

def reply_id
  @reply_id
end

#titleString?

Returns:

  • (String, nil)


19
20
21
# File 'lib/ruby/whatsapp/webhook/message/interactive.rb', line 19

def title
  @title
end

Class Method Details

.deserialize(data) ⇒ Interactive

Parameters:

  • data (Hash)

    The raw message hash.

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby/whatsapp/webhook/message/interactive.rb', line 37

def deserialize(data)
  interactive_type = data.dig("interactive", "type")
  reply = data.dig("interactive", interactive_type) || {}

  new(
    interactive_type:,
    reply_id: reply["id"],
    title: reply["title"],
    description: reply["description"],
    **common_attributes(data)
  )
end