Class: Whatsapp::MessageTemplates::Component::LimitedTimeOffer

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

Overview

The offer banner that turns a marketing template into a limited-time offer, optionally with a live countdown timer.

Its presence changes the rules for the rest of the template: a footer becomes forbidden, the body drops to 600 characters, the header narrows to image or video, and the category must be MARKETING. Those are all cross-component rules, so Template enforces them.

The expiry timestamp itself is not set here — it is supplied per message when sending, as expiration_time_ms. This component only declares that the template has one. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/marketing-templates/limited-time-offer-templates

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:, has_expiration: nil) ⇒ LimitedTimeOffer

Returns a new instance of LimitedTimeOffer.

Parameters:

  • text (String)

    The offer label (max 16 characters).

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

    Whether to show a countdown timer.

  • kwargs (Hash)

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



38
39
40
41
42
43
44
45
# File 'lib/ruby/whatsapp/message_templates/component/limited_time_offer.rb', line 38

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

  @text = text
  @has_expiration = has_expiration

  validate!
end

Instance Attribute Details

#has_expirationBoolean?

Returns:

  • (Boolean, nil)


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

def has_expiration
  @has_expiration
end

#textString

Returns:

  • (String)


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

def text
  @text
end

Instance Method Details

#serializeHash

Returns The serialized component.

Returns:

  • (Hash)

    The serialized component.



48
49
50
51
52
53
# File 'lib/ruby/whatsapp/message_templates/component/limited_time_offer.rb', line 48

def serialize
  {
    type: Defaults::TYPE,
    limited_time_offer: { text:, has_expiration: }.compact,
  }
end