Class: Whatsapp::MessageTemplates::Component::Carousel::Card
- Inherits:
-
Object
- Object
- Whatsapp::MessageTemplates::Component::Carousel::Card
- Includes:
- ValueObject
- Defined in:
- lib/ruby/whatsapp/message_templates/component/carousel/card.rb
Overview
One card in a carousel: a required media header, an optional body, and up to two buttons.
Composes Header and Buttons rather than restating their rules — the only extra constraint is that a card's header must be image or video, since a carousel card cannot be text or a location.
Note there is no card_index here. Cards are positional at creation time;
the zero-based card_index only appears when sending a message.
Source: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/carousel-templates
Defined Under Namespace
Modules: Defaults
Constant Summary collapse
- ALLOWED_HEADER_FORMATS =
A carousel card's header is restricted to these formats.
[Header::Formats::IMAGE, Header::Formats::VIDEO].freeze
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(header:, body: nil, buttons: nil, parameter_format: ParameterFormats::POSITIONAL) ⇒ Card
constructor
@raise [ActiveModel::ValidationError] if validation fails.
-
#serialize ⇒ Hash
The serialized card.
-
#signature ⇒ Array
A comparable description of the card's shape, used by Whatsapp::MessageTemplates::Component::Carousel to enforce Meta's "all cards must have the same components" rule.
Methods included from ValueObject
Constructor Details
#initialize(header:, body: nil, buttons: nil, parameter_format: ParameterFormats::POSITIONAL) ⇒ Card
@raise [ActiveModel::ValidationError] if validation fails.
49 50 51 52 53 54 55 56 |
# File 'lib/ruby/whatsapp/message_templates/component/carousel/card.rb', line 49 def initialize(header:, body: nil, buttons: nil, parameter_format: ParameterFormats::POSITIONAL) @parameter_format = ParameterFormats.normalize(parameter_format) @header = build(Header, header) @body = build(Body, body) @buttons = blank_value?() ? nil : Buttons.new(buttons:, parameter_format: @parameter_format) validate! end |
Instance Attribute Details
#body ⇒ Component::Body?
33 34 35 |
# File 'lib/ruby/whatsapp/message_templates/component/carousel/card.rb', line 33 def body @body end |
#buttons ⇒ Component::Buttons?
37 38 39 |
# File 'lib/ruby/whatsapp/message_templates/component/carousel/card.rb', line 37 def @buttons end |
#header ⇒ Component::Header
29 30 31 |
# File 'lib/ruby/whatsapp/message_templates/component/carousel/card.rb', line 29 def header @header end |
Instance Method Details
#serialize ⇒ Hash
Returns The serialized card.
67 68 69 |
# File 'lib/ruby/whatsapp/message_templates/component/carousel/card.rb', line 67 def serialize { components: [header, body, ].compact.map(&:serialize) } end |
#signature ⇒ Array
A comparable description of the card's shape, used by Whatsapp::MessageTemplates::Component::Carousel to enforce Meta's "all cards must have the same components" rule. Content is deliberately excluded — only structure matters.
62 63 64 |
# File 'lib/ruby/whatsapp/message_templates/component/carousel/card.rb', line 62 def signature [header&.format, !body.nil?, &.api_types] end |