Class: Whatsapp::MessageTemplates::LibraryTemplate
- Inherits:
-
Object
- Object
- Whatsapp::MessageTemplates::LibraryTemplate
- Includes:
- ValueObject
- Defined in:
- lib/ruby/whatsapp/message_templates/library_template.rb,
lib/ruby/whatsapp/message_templates/library_template/body_inputs.rb,
lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb
Overview
The payload for cloning one of Meta's pre-written library templates.
A separate class from Template rather than another mode on it, because this payload carries no components at all — the library template already defines them, and only the parts Meta cannot know (a URL, a phone number, whether to append an optional line) are supplied as inputs. Folding that into Template would mean defeating its central "exactly one BODY" invariant.
The payoff is instant approval: library templates are already categorised and reviewed, so the create response usually comes back APPROVED rather than PENDING. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/template-library
Defined Under Namespace
Classes: BodyInputs, ButtonInputs
Instance Attribute Summary collapse
- #category ⇒ String
- #language ⇒ String
- #library_template_body_inputs ⇒ LibraryTemplate::BodyInputs?
- #library_template_button_inputs ⇒ Array<LibraryTemplate::ButtonInputs>?
-
#library_template_name ⇒ String
The library template being cloned.
-
#name ⇒ String
The name to give your copy of the template.
Instance Method Summary collapse
-
#initialize(name:, language:, category:, library_template_name:, library_template_body_inputs: nil, library_template_button_inputs: nil) ⇒ LibraryTemplate
constructor
@raise [ActiveModel::ValidationError] if validation fails.
-
#serialize ⇒ Hash
Note: Meta's docs show
library_template_button_inputsas a JSON-stringified array while the Graph API reference types itarray<JSON object>.
Methods included from ValueObject
Constructor Details
#initialize(name:, language:, category:, library_template_name:, library_template_body_inputs: nil, library_template_button_inputs: nil) ⇒ LibraryTemplate
@raise [ActiveModel::ValidationError] if validation fails.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby/whatsapp/message_templates/library_template.rb', line 60 def initialize(name:, language:, category:, library_template_name:, library_template_body_inputs: nil, library_template_button_inputs: nil) @name = name @language = language @category = Categories.normalize(category) @library_template_name = library_template_name @library_template_body_inputs = build_body_inputs(library_template_body_inputs) @library_template_button_inputs = () validate! end |
Instance Attribute Details
#category ⇒ String
29 30 31 |
# File 'lib/ruby/whatsapp/message_templates/library_template.rb', line 29 def category @category end |
#language ⇒ String
25 26 27 |
# File 'lib/ruby/whatsapp/message_templates/library_template.rb', line 25 def language @language end |
#library_template_body_inputs ⇒ LibraryTemplate::BodyInputs?
37 38 39 |
# File 'lib/ruby/whatsapp/message_templates/library_template.rb', line 37 def library_template_body_inputs @library_template_body_inputs end |
#library_template_button_inputs ⇒ Array<LibraryTemplate::ButtonInputs>?
41 42 43 |
# File 'lib/ruby/whatsapp/message_templates/library_template.rb', line 41 def @library_template_button_inputs end |
#library_template_name ⇒ String
Returns The library template being cloned.
33 34 35 |
# File 'lib/ruby/whatsapp/message_templates/library_template.rb', line 33 def library_template_name @library_template_name end |
#name ⇒ String
Returns The name to give your copy of the template.
21 22 23 |
# File 'lib/ruby/whatsapp/message_templates/library_template.rb', line 21 def name @name end |
Instance Method Details
#serialize ⇒ Hash
Note: Meta's docs show library_template_button_inputs as a JSON-stringified
array while the Graph API reference types it array<JSON object>. A real array
is emitted here, which matches the reference and how every other field on this
edge behaves. If the API rejects it, this method is the single place to change.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ruby/whatsapp/message_templates/library_template.rb', line 78 def serialize { name:, language:, category:, library_template_name:, library_template_body_inputs: library_template_body_inputs&.serialize, library_template_button_inputs: &.map(&:serialize), }.compact end |