Class: Whatsapp::MessageTemplates::Component::Footer

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/whatsapp/message_templates/component/footer.rb

Overview

The optional small-print line below the body. At most one per template.

Two mutually exclusive shapes, mirroring Body:

standard       — `text` (60 chars, and no placeholders at all)
authentication — `code_expiration_minutes`, which renders Meta's own
               localised "This code expires in N minutes." Omit the footer
               entirely to omit that notice.

Forbidden altogether in limited-time-offer templates, which Template enforces. Source: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components/

Defined Under Namespace

Modules: Defaults

Instance Attribute Summary collapse

Attributes inherited from Base

#example_error, #parameter_format

Instance Method Summary collapse

Methods inherited from Base

#api_type

Methods included from ValueObject

included

Constructor Details

#initialize(text: nil, code_expiration_minutes: nil) ⇒ Footer

Returns a new instance of Footer.

Parameters:

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

    The footer text (max 60 characters, no placeholders).

  • code_expiration_minutes (Integer, nil) (defaults to: nil)

    Authentication templates only; must be within 1..90. Mutually exclusive with text.

  • kwargs (Hash)

    Forwarded to Base (parameter_format). @raise [ActiveModel::ValidationError] if validation fails.



41
42
43
44
45
46
47
48
# File 'lib/ruby/whatsapp/message_templates/component/footer.rb', line 41

def initialize(text: nil, code_expiration_minutes: nil, **)
  super(**)

  @text = text
  @code_expiration_minutes = code_expiration_minutes

  validate!
end

Instance Attribute Details

#code_expiration_minutesInteger?

Returns Authentication templates only.

Returns:

  • (Integer, nil)

    Authentication templates only.



30
31
32
# File 'lib/ruby/whatsapp/message_templates/component/footer.rb', line 30

def code_expiration_minutes
  @code_expiration_minutes
end

#textString?

Returns:

  • (String, nil)


26
27
28
# File 'lib/ruby/whatsapp/message_templates/component/footer.rb', line 26

def text
  @text
end

Instance Method Details

#authentication?Boolean

Returns Whether this is the expiry-based authentication shape.

Returns:

  • (Boolean)

    Whether this is the expiry-based authentication shape.



51
52
53
# File 'lib/ruby/whatsapp/message_templates/component/footer.rb', line 51

def authentication?
  !code_expiration_minutes.nil?
end

#serializeHash

Returns The serialized component.

Returns:

  • (Hash)

    The serialized component.



56
57
58
59
60
# File 'lib/ruby/whatsapp/message_templates/component/footer.rb', line 56

def serialize
  return { type: Defaults::TYPE, code_expiration_minutes: } if authentication?

  { type: Defaults::TYPE, text: }
end