Class: Whatsapp::MessageTemplates::LibraryTemplate::ButtonInputs

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from ValueObject

included

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.

Parameters:

  • type (String, Symbol)
  • url (Hash, nil) (defaults to: nil)

    Required for URL: { base_url:, url_suffix_example: }.

  • phone_number (String, nil) (defaults to: nil)

    Required for PHONE_NUMBER.

  • otp_type (String, Symbol, nil) (defaults to: nil)

    For OTP inputs.

  • zero_tap_terms_accepted (Boolean, nil) (defaults to: nil)

    For zero-tap OTP inputs.

  • supported_apps (Array<Hash, Button::Otp::SupportedApp>, nil) (defaults to: nil)

    Required for APP.



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_typeString?

Returns:

  • (String, nil)


49
50
51
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 49

def otp_type
  @otp_type
end

#phone_numberString?

Returns:

  • (String, nil)


45
46
47
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 45

def phone_number
  @phone_number
end

#supported_appsArray<Button::Otp::SupportedApp>?

Returns:



57
58
59
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 57

def supported_apps
  @supported_apps
end

#typeString



37
38
39
# File 'lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb', line 37

def type
  @type
end

#urlHash?

Returns { base_url:, url_suffix_example: }.

Returns:

  • (Hash, nil)

    { 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_acceptedBoolean?

Returns:

  • (Boolean, nil)


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

#serializeHash

Returns The serialized button input.

Returns:

  • (Hash)

    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