Class: Whatsapp::MessageTemplates::Button::PhoneNumber

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

Overview

Places a phone call to the business when tapped.

At most one per template. Meta may strip leading zeros that follow the country code, so store the number in full international form. 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(text:, phone_number:) ⇒ PhoneNumber

Returns a new instance of PhoneNumber.

Parameters:

  • text (String)

    The button label (max 25 characters).

  • phone_number (String)

    The number to call (max 20 characters). @raise [ActiveModel::ValidationError] if validation fails.



31
32
33
34
35
36
# File 'lib/ruby/whatsapp/message_templates/button/phone_number.rb', line 31

def initialize(text:, phone_number:)
  @text = text
  @phone_number = phone_number

  validate!
end

Instance Attribute Details

#phone_numberString

Returns:

  • (String)


23
24
25
# File 'lib/ruby/whatsapp/message_templates/button/phone_number.rb', line 23

def phone_number
  @phone_number
end

#textString

Returns:

  • (String)


19
20
21
# File 'lib/ruby/whatsapp/message_templates/button/phone_number.rb', line 19

def text
  @text
end

Instance Method Details

#serializeHash

Returns The serialized button.

Returns:

  • (Hash)

    The serialized button.



39
40
41
# File 'lib/ruby/whatsapp/message_templates/button/phone_number.rb', line 39

def serialize
  { type: Defaults::TYPE, text:, phone_number: }
end