Class: Whatsapp::MessageTemplates::Component::Body
- Defined in:
- lib/ruby/whatsapp/message_templates/component/body.rb
Overview
The template's message text. The only component Meta requires.
Two mutually exclusive shapes, hence the XOR validation:
standard — `text` (1024 chars) with any number of placeholders, plus a
matching `example`
authentication — no text at all. Meta supplies the fixed, localised string
"<VERIFICATION_CODE> is your verification code." and
`add_security_recommendation` only decides whether the
"do not share this code" line is appended.
The tighter 600-character limit that applies inside a limited-time-offer template is enforced by Template, which is the only object that can see whether such a component is present. Source: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components/
Defined Under Namespace
Modules: Defaults
Instance Attribute Summary collapse
-
#add_security_recommendation ⇒ Boolean?
Authentication templates only.
-
#example ⇒ Hash?
The serialized example payload.
-
#example_values ⇒ Array, ...
The raw example input, kept so the placeholder/example counts can be compared without re-parsing the serialized payload.
- #text ⇒ String?
Attributes inherited from Base
#example_error, #parameter_format
Instance Method Summary collapse
-
#authentication? ⇒ Boolean
Whether this is the flag-based authentication shape.
-
#initialize(text: nil, example: nil, add_security_recommendation: nil) ⇒ Body
constructor
A new instance of Body.
-
#serialize ⇒ Hash
The serialized component.
Methods inherited from Base
Methods included from ValueObject
Constructor Details
#initialize(text: nil, example: nil, add_security_recommendation: nil) ⇒ Body
Returns a new instance of Body.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby/whatsapp/message_templates/component/body.rb', line 56 def initialize(text: nil, example: nil, add_security_recommendation: nil, **) super(**) @text = text @add_security_recommendation = add_security_recommendation @example_values = example @example = build_example_payload(role: :body, values: example) validate! end |
Instance Attribute Details
#add_security_recommendation ⇒ Boolean?
Returns Authentication templates only.
37 38 39 |
# File 'lib/ruby/whatsapp/message_templates/component/body.rb', line 37 def add_security_recommendation @add_security_recommendation end |
#example ⇒ Hash?
Returns The serialized example payload.
33 34 35 |
# File 'lib/ruby/whatsapp/message_templates/component/body.rb', line 33 def example @example end |
#example_values ⇒ Array, ...
The raw example input, kept so the placeholder/example counts can be compared without re-parsing the serialized payload.
43 44 45 |
# File 'lib/ruby/whatsapp/message_templates/component/body.rb', line 43 def example_values @example_values end |
#text ⇒ String?
29 30 31 |
# File 'lib/ruby/whatsapp/message_templates/component/body.rb', line 29 def text @text end |
Instance Method Details
#authentication? ⇒ Boolean
Returns Whether this is the flag-based authentication shape.
68 69 70 |
# File 'lib/ruby/whatsapp/message_templates/component/body.rb', line 68 def authentication? !add_security_recommendation.nil? end |
#serialize ⇒ Hash
Returns The serialized component.
73 74 75 76 77 78 79 80 81 |
# File 'lib/ruby/whatsapp/message_templates/component/body.rb', line 73 def serialize return { type: Defaults::TYPE, add_security_recommendation: } if authentication? { type: Defaults::TYPE, text:, example:, }.compact end |