Class: Whatsapp::MessageTemplates::Component::Carousel

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/whatsapp/message_templates/component/carousel.rb,
lib/ruby/whatsapp/message_templates/component/carousel/card.rb

Overview

A horizontally scrollable set of 2 to 10 cards, each with its own media header and buttons. Marketing templates only, which Template enforces.

The card count is fixed at creation: an approved carousel template must be sent with exactly the number of cards it was created with.

Every card must share the same structure — same header format, same button types, and body text either on all of them or none. Meta's stated reason for the body rule is keeping card heights consistent. Card#signature is what makes this checkable. Source: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/carousel-templates

Defined Under Namespace

Modules: Defaults Classes: Card

Instance Attribute Summary collapse

Attributes inherited from Base

#example_error, #parameter_format

Instance Method Summary collapse

Methods inherited from Base

#api_type

Methods included from ValueObject

included

Constructor Details

#initialize(cards: []) ⇒ Carousel

Returns a new instance of Carousel.

Parameters:

  • cards (Array<Hash, Carousel::Card>) (defaults to: [])

    Between 2 and 10 cards.

  • kwargs (Hash)

    Forwarded to Base (parameter_format). @raise [ActiveModel::ValidationError] if validation fails.



35
36
37
38
39
40
41
# File 'lib/ruby/whatsapp/message_templates/component/carousel.rb', line 35

def initialize(cards: [], **)
  super(**)

  @cards = build_cards(cards)

  validate!
end

Instance Attribute Details

#cardsArray<Carousel::Card>

Returns:



26
27
28
# File 'lib/ruby/whatsapp/message_templates/component/carousel.rb', line 26

def cards
  @cards
end

Instance Method Details

#serializeHash

Returns The serialized component.

Returns:

  • (Hash)

    The serialized component.



44
45
46
# File 'lib/ruby/whatsapp/message_templates/component/carousel.rb', line 44

def serialize
  { type: Defaults::TYPE, cards: cards.map(&:serialize) }
end