Class: Whatsapp::MessageTemplates::Component::Header
- Defined in:
- lib/ruby/whatsapp/message_templates/component/header.rb
Overview
The optional component above the body: a line of text, a media attachment, or a location pin. At most one per template.
Three shapes share one class because they all serialize to the same
{type:, format:, ...} envelope and differ only in which fields are legal.
The format decides:
TEXT — `text` (60 chars, at most ONE placeholder) plus an `example`
media — `header_handle` from the Resumable Upload API; no text
LOCATION — nothing else; coordinates are supplied when the message is sent
This mirrors the conditional-validation approach already used by Whatsapp::Messages::Video for its id-or-link choice. Source: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components/
Defined Under Namespace
Constant Summary collapse
- MARKDOWN_CHARACTERS =
Characters Meta rejects in a header, which does not support Markdown.
["*", "_", "~", "`"].freeze
Instance Attribute Summary collapse
-
#example ⇒ Hash?
The serialized example payload.
-
#format ⇒ String
One of Formats::ALL.
-
#header_handle ⇒ String, ...
Media headers only.
-
#text ⇒ String?
TEXT headers only.
Attributes inherited from Base
#example_error, #parameter_format
Instance Method Summary collapse
-
#initialize(format:, text: nil, example: nil, header_handle: nil) ⇒ Header
constructor
A new instance of Header.
-
#media? ⇒ Boolean
Whether this header carries an uploaded asset.
-
#serialize ⇒ Hash
The serialized component.
Methods inherited from Base
Methods included from ValueObject
Constructor Details
#initialize(format:, text: nil, example: nil, header_handle: nil) ⇒ Header
Returns a new instance of Header.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ruby/whatsapp/message_templates/component/header.rb', line 73 def initialize(format:, text: nil, example: nil, header_handle: nil, **) super(**) @format = normalize_format(format) @text = text @header_handle = header_handle @example = build_example(example) validate! end |
Instance Attribute Details
#example ⇒ Hash?
Returns The serialized example payload.
53 54 55 |
# File 'lib/ruby/whatsapp/message_templates/component/header.rb', line 53 def example @example end |
#format ⇒ String
Returns one of Whatsapp::MessageTemplates::Component::Header::Formats::ALL.
45 46 47 |
# File 'lib/ruby/whatsapp/message_templates/component/header.rb', line 45 def format @format end |
#header_handle ⇒ String, ...
Returns Media headers only.
57 58 59 |
# File 'lib/ruby/whatsapp/message_templates/component/header.rb', line 57 def header_handle @header_handle end |
#text ⇒ String?
Returns TEXT headers only.
49 50 51 |
# File 'lib/ruby/whatsapp/message_templates/component/header.rb', line 49 def text @text end |