Class: Whatsapp::MessageTemplates::Button::CopyCode

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

Overview

Copies a string — typically a coupon code — to the recipient's clipboard.

Two things are unusual about this button: it carries no text, because Meta supplies and localises the label itself; and its example is a bare string rather than an array. At most one per template.

In a limited-time-offer template the example is capped at 15 characters rather than 20, and the button must sit at index 0 — both enforced by Template, which is the only place that can see the sibling components. Source: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components/

Defined Under Namespace

Modules: Defaults

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(example:, text: nil) ⇒ CopyCode

Returns a new instance of CopyCode.

Parameters:

  • example (String)

    The code to copy (max 20 characters).

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

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



38
39
40
41
42
43
# File 'lib/ruby/whatsapp/message_templates/button/copy_code.rb', line 38

def initialize(example:, text: nil)
  @example = example
  @text = text

  validate!
end

Instance Attribute Details

#exampleString

Returns:

  • (String)


24
25
26
# File 'lib/ruby/whatsapp/message_templates/button/copy_code.rb', line 24

def example
  @example
end

#textnil

Always nil. Accepted only so a caller who supplies one gets told why it is not allowed, rather than an opaque ArgumentError.

Returns:

  • (nil)


30
31
32
# File 'lib/ruby/whatsapp/message_templates/button/copy_code.rb', line 30

def text
  @text
end

Instance Method Details

#serializeHash

Returns The serialized button.

Returns:

  • (Hash)

    The serialized button.



46
47
48
# File 'lib/ruby/whatsapp/message_templates/button/copy_code.rb', line 46

def serialize
  { type: Defaults::TYPE, example: }
end