Class: Whatsapp::Messages::Interactive::UrlButton

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/whatsapp/messages/interactive/url_button.rb

Overview

Interactive call-to-action (CTA) URL button message. Maps a URL to a button so the raw URL does not have to appear in the message body. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/messages/interactive-cta-url-messages

Defined Under Namespace

Modules: Defaults

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, display_text:, url:) ⇒ UrlButton

Returns a new instance of UrlButton.

Parameters:

  • name (String)

    The name of the URL button.

  • display_text (String)

    The text displayed on the button.

  • url (String)

    The URL that the button links to.



33
34
35
36
37
38
39
# File 'lib/ruby/whatsapp/messages/interactive/url_button.rb', line 33

def initialize(name:, display_text:, url:)
  @name = name
  @display_text = display_text
  @url = url

  validate!
end

Instance Attribute Details

#display_textString

Returns:

  • (String)


21
22
23
# File 'lib/ruby/whatsapp/messages/interactive/url_button.rb', line 21

def display_text
  @display_text
end

#nameString

Returns:

  • (String)


17
18
19
# File 'lib/ruby/whatsapp/messages/interactive/url_button.rb', line 17

def name
  @name
end

#urlString

Returns:

  • (String)


25
26
27
# File 'lib/ruby/whatsapp/messages/interactive/url_button.rb', line 25

def url
  @url
end

Class Method Details

.serialize(**url_button) ⇒ Hash

Returns Serialized representation of the URL button.

Returns:

  • (Hash)

    Serialized representation of the URL button.



43
44
45
# File 'lib/ruby/whatsapp/messages/interactive/url_button.rb', line 43

def serialize(**url_button)
  new(**url_button).serialize
end

Instance Method Details

#serializeHash

Returns Serialized representation of the URL button.

Returns:

  • (Hash)

    Serialized representation of the URL button.



49
50
51
52
53
54
# File 'lib/ruby/whatsapp/messages/interactive/url_button.rb', line 49

def serialize
  {
    name:,
    parameters:,
  }
end