Class: Whatsapp::MessageTemplates::LibraryTemplate::ButtonInputs
- Inherits:
-
Object
- Object
- Whatsapp::MessageTemplates::LibraryTemplate::ButtonInputs
- Includes:
- ValueObject
- Defined in:
- lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb
Overview
One button's customisable values when cloning a library template.
Deliberately not the same as Button: a library template already declares
which buttons it has and what they say, so these inputs only fill in the parts
Meta cannot know — a destination URL, a phone number, an app signature. There is
no text, and the shapes differ from the create-a-button-from-scratch ones (a
URL arrives as a {base_url:, url_suffix_example:} pair rather than a single
string with a placeholder).
Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/template-library
Defined Under Namespace
Modules: Types
Instance Attribute Summary collapse
- #otp_type ⇒ String?
- #phone_number ⇒ String?
- #supported_apps ⇒ Array<Button::Otp::SupportedApp>?
-
#type ⇒ String
One of Types::ALL.
-
#url ⇒ Hash?
{ base_url:, url_suffix_example: }. - #zero_tap_terms_accepted ⇒ Boolean?
Instance Method Summary collapse
-
#initialize(type:, url: nil, phone_number: nil, otp_type: nil, zero_tap_terms_accepted: nil, supported_apps: nil) ⇒ ButtonInputs
constructor
@raise [ActiveModel::ValidationError] if validation fails.
-
#serialize ⇒ Hash
The serialized button input.
Methods included from ValueObject
Constructor Details
#initialize(type:, url: nil, phone_number: nil, otp_type: nil, zero_tap_terms_accepted: nil, supported_apps: nil) ⇒ ButtonInputs
@raise [ActiveModel::ValidationError] if validation fails.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 72 def initialize(type:, url: nil, phone_number: nil, otp_type: nil, zero_tap_terms_accepted: nil, supported_apps: nil) @type = normalize_type(type) @url = url&.then { |value| symbolize(value) } @phone_number = phone_number @otp_type = otp_type&.to_s&.upcase @zero_tap_terms_accepted = zero_tap_terms_accepted @supported_apps = build_supported_apps(supported_apps) validate! end |
Instance Attribute Details
#otp_type ⇒ String?
49 50 51 |
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 49 def otp_type @otp_type end |
#phone_number ⇒ String?
45 46 47 |
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 45 def phone_number @phone_number end |
#supported_apps ⇒ Array<Button::Otp::SupportedApp>?
57 58 59 |
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 57 def supported_apps @supported_apps end |
#type ⇒ String
37 38 39 |
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 37 def type @type end |
#url ⇒ Hash?
Returns { base_url:, url_suffix_example: }.
41 42 43 |
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 41 def url @url end |
#zero_tap_terms_accepted ⇒ Boolean?
53 54 55 |
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 53 def zero_tap_terms_accepted @zero_tap_terms_accepted end |
Instance Method Details
#serialize ⇒ Hash
Returns The serialized button input.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 85 def serialize { type:, url:, phone_number:, otp_type:, zero_tap_terms_accepted:, supported_apps: supported_apps&.map(&:serialize), }.compact end |