Class: Whatsapp::MessageTemplates::Button::Otp

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/whatsapp/message_templates/button/otp.rb,
lib/ruby/whatsapp/message_templates/button/otp/supported_app.rb

Overview

The one-time-passcode button that authentication templates are built around.

Unlike every other button, its label is not settable: Meta supplies and localises both text and autofill_text per language. Passing either is therefore an error rather than something silently dropped. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/authentication-templates/authentication-templates

Defined Under Namespace

Modules: Defaults, OtpTypes Classes: SupportedApp

Constant Summary

Constants inherited from Base

Base::MAX_TEXT_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#api_type

Methods included from ValueObject

included

Constructor Details

#initialize(otp_type:, supported_apps: [], zero_tap_terms_accepted: nil, text: nil, autofill_text: nil) ⇒ Otp

Returns a new instance of Otp.

Parameters:

  • otp_type (String, Symbol)
  • supported_apps (Array<Hash, Otp::SupportedApp>) (defaults to: [])

    Apps allowed to receive the code. Required for ONE_TAP and ZERO_TAP.

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

    Must be true for ZERO_TAP.

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

    Not supported — Meta localises the label.

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

    Not supported — Meta localises the label. @raise [ActiveModel::ValidationError] if validation fails.



69
70
71
72
73
74
75
76
77
# File 'lib/ruby/whatsapp/message_templates/button/otp.rb', line 69

def initialize(otp_type:, supported_apps: [], zero_tap_terms_accepted: nil, text: nil, autofill_text: nil)
  @otp_type = normalize_otp_type(otp_type)
  @supported_apps = build_supported_apps(supported_apps)
  @zero_tap_terms_accepted = zero_tap_terms_accepted
  @text = text
  @autofill_text = autofill_text

  validate!
end

Instance Attribute Details

#autofill_textnil

Always nil — see the class comment.

Returns:

  • (nil)


55
56
57
# File 'lib/ruby/whatsapp/message_templates/button/otp.rb', line 55

def autofill_text
  @autofill_text
end

#otp_typeString

Returns:

  • (String)


37
38
39
# File 'lib/ruby/whatsapp/message_templates/button/otp.rb', line 37

def otp_type
  @otp_type
end

#supported_appsArray<Otp::SupportedApp>

Returns:



41
42
43
# File 'lib/ruby/whatsapp/message_templates/button/otp.rb', line 41

def supported_apps
  @supported_apps
end

#textnil

Always nil — see the class comment.

Returns:

  • (nil)


50
51
52
# File 'lib/ruby/whatsapp/message_templates/button/otp.rb', line 50

def text
  @text
end

#zero_tap_terms_acceptedBoolean?

Returns:

  • (Boolean, nil)


45
46
47
# File 'lib/ruby/whatsapp/message_templates/button/otp.rb', line 45

def zero_tap_terms_accepted
  @zero_tap_terms_accepted
end

Instance Method Details

#serializeHash

Returns The serialized button.

Returns:

  • (Hash)

    The serialized button.



80
81
82
83
84
85
86
87
# File 'lib/ruby/whatsapp/message_templates/button/otp.rb', line 80

def serialize
  {
    type: Defaults::TYPE,
    otp_type:,
    supported_apps: serialized_supported_apps,
    zero_tap_terms_accepted:,
  }.compact
end