Class: Whatsapp::Messages::Interactive::ListButtons

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/whatsapp/messages/interactive/list_buttons.rb,
lib/ruby/whatsapp/messages/interactive/list_buttons/section.rb,
lib/ruby/whatsapp/messages/interactive/list_buttons/section/row.rb

Overview

Interactive list messages allow you to present WhatsApp users with a list of options to choose from Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/messages/interactive-list-messages

Defined Under Namespace

Modules: Defaults Classes: Section

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(button:, sections:) ⇒ ListButtons

Returns a new instance of ListButtons.

Parameters:

  • button (String)

    The text for the list button.

  • sections (Array<Hash>)

    The sections of the list button. @raise [ActiveModel::ValidationError] if validation fails.



30
31
32
33
34
35
# File 'lib/ruby/whatsapp/messages/interactive/list_buttons.rb', line 30

def initialize(button:, sections:)
  @button = button
  @sections = sections

  validate!
end

Instance Attribute Details

#buttonString

Returns:

  • (String)


17
18
19
# File 'lib/ruby/whatsapp/messages/interactive/list_buttons.rb', line 17

def button
  @button
end

#sectionsArray<Hash>

Returns:

  • (Array<Hash>)


21
22
23
# File 'lib/ruby/whatsapp/messages/interactive/list_buttons.rb', line 21

def sections
  @sections
end

Class Method Details

.serialize(**list_buttons) ⇒ Hash

Returns Serialized representation of the ListButtons. @raise [ActiveModel::ValidationError] if validation fails.

Returns:

  • (Hash)

    Serialized representation of the ListButtons. @raise [ActiveModel::ValidationError] if validation fails.



40
41
42
# File 'lib/ruby/whatsapp/messages/interactive/list_buttons.rb', line 40

def serialize(**list_buttons)
  new(**list_buttons).serialize
end

Instance Method Details

#serializeHash

Returns Serialized representation of the ListButtons.

Returns:

  • (Hash)

    Serialized representation of the ListButtons.



46
47
48
49
50
51
# File 'lib/ruby/whatsapp/messages/interactive/list_buttons.rb', line 46

def serialize
  {
    button:,
    sections: serialized_sections,
  }
end