Class: Whatsapp::MessageTemplates::Template
- Inherits:
-
Object
- Object
- Whatsapp::MessageTemplates::Template
- Includes:
- ValueObject
- Defined in:
- lib/ruby/whatsapp/message_templates/template.rb
Overview
The payload for creating a template, and for the multi-language upsert form.
Owns the template's identity — name, language, category and the flags that apply to the whole template. Everything about the components, including the rules that span several of them, is delegated to ComponentSet; this class only passes the category and parameter format down so those rules can be applied.
Supports two language forms, which is why they are validated as an exclusive
choice: a single language for #create, or a languages array
for #upsert, which creates or updates the same template across
several locales in one call.
Cloning a pre-written template from Meta's library is a different payload with no components at all — see LibraryTemplate. Source: https://developers.facebook.com/docs/graph-api/reference/whats-app-business-account/message_templates/
Defined Under Namespace
Modules: Defaults, SubCategories
Instance Attribute Summary collapse
-
#allow_category_change ⇒ Boolean?
Effectively a no-op since 2025-04-09, when Meta made automatic recategorisation the default regardless of this flag.
- #category ⇒ String
- #component_set ⇒ ComponentSet
- #cta_url_link_tracking_opted_out ⇒ Boolean?
-
#language ⇒ String?
A single locale code, for create.
-
#languages ⇒ Array<String>?
Several locale codes, for upsert.
- #message_send_ttl_seconds ⇒ Integer?
- #name ⇒ String
- #parameter_format ⇒ String
- #sub_category ⇒ String?
Instance Method Summary collapse
- #components ⇒ Array<Component::Base>
-
#initialize(name:, category:, components:, language: nil, languages: nil, parameter_format: ParameterFormats::POSITIONAL, sub_category: nil, message_send_ttl_seconds: nil, allow_category_change: nil, cta_url_link_tracking_opted_out: nil) ⇒ Template
constructor
A new instance of Template.
-
#serialize ⇒ Hash
The create/upsert payload.
Methods included from ValueObject
Constructor Details
#initialize(name:, category:, components:, language: nil, languages: nil, parameter_format: ParameterFormats::POSITIONAL, sub_category: nil, message_send_ttl_seconds: nil, allow_category_change: nil, cta_url_link_tracking_opted_out: nil) ⇒ Template
Returns a new instance of Template.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 105 def initialize(name:, category:, components:, language: nil, languages: nil, parameter_format: ParameterFormats::POSITIONAL, sub_category: nil, message_send_ttl_seconds: nil, allow_category_change: nil, cta_url_link_tracking_opted_out: nil) @name = name @language = language @languages = languages @category = Categories.normalize(category) @parameter_format = ParameterFormats.normalize(parameter_format) @sub_category = sub_category @message_send_ttl_seconds = @allow_category_change = allow_category_change @cta_url_link_tracking_opted_out = cta_url_link_tracking_opted_out @component_set = ComponentSet.new(components:, category: @category, parameter_format: @parameter_format) validate! end |
Instance Attribute Details
#allow_category_change ⇒ Boolean?
Effectively a no-op since 2025-04-09, when Meta made automatic recategorisation the default regardless of this flag. Kept because it is still a documented parameter.
75 76 77 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 75 def allow_category_change @allow_category_change end |
#category ⇒ String
52 53 54 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 52 def category @category end |
#component_set ⇒ ComponentSet
60 61 62 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 60 def component_set @component_set end |
#cta_url_link_tracking_opted_out ⇒ Boolean?
79 80 81 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 79 def cta_url_link_tracking_opted_out @cta_url_link_tracking_opted_out end |
#language ⇒ String?
Returns A single locale code, for create.
44 45 46 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 44 def language @language end |
#languages ⇒ Array<String>?
Returns Several locale codes, for upsert.
48 49 50 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 48 def languages @languages end |
#message_send_ttl_seconds ⇒ Integer?
68 69 70 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 68 def @message_send_ttl_seconds end |
#name ⇒ String
40 41 42 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 40 def name @name end |
#parameter_format ⇒ String
56 57 58 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 56 def parameter_format @parameter_format end |
#sub_category ⇒ String?
64 65 66 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 64 def sub_category @sub_category end |
Instance Method Details
#components ⇒ Array<Component::Base>
124 125 126 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 124 def components component_set.components end |
#serialize ⇒ Hash
Returns The create/upsert payload.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ruby/whatsapp/message_templates/template.rb', line 129 def serialize { name:, **language_payload, category:, parameter_format:, components: component_set.serialize, sub_category:, message_send_ttl_seconds:, allow_category_change:, cta_url_link_tracking_opted_out:, }.compact end |