Class: Whatsapp::Messages::Text

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

Overview

Text messages are messages containing only a text body and an optional link preview. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/messages/text-messages

Defined Under Namespace

Modules: Defaults

Instance Attribute Summary collapse

Attributes inherited from Base

#to

Instance Method Summary collapse

Constructor Details

#initialize(body:, preview_url: true) ⇒ Text

Returns a new instance of Text.

Parameters:

  • body (String)

    The text of the message.

  • preview_url (Boolean) (defaults to: true)

    Whether to enable URL preview in the message.

  • kwargs (Hash)

    Additional keyword arguments. @raise [ActiveModel::ValidationError] if validation fails.



27
28
29
30
31
32
33
34
# File 'lib/ruby/whatsapp/messages/text.rb', line 27

def initialize(body:, preview_url: true, **)
  super(**)

  @body = body
  @preview_url = preview_url

  validate!
end

Instance Attribute Details

#bodyString

Returns:

  • (String)


14
15
16
# File 'lib/ruby/whatsapp/messages/text.rb', line 14

def body
  @body
end

#preview_urlBoolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ruby/whatsapp/messages/text.rb', line 18

def preview_url
  @preview_url
end

Instance Method Details

#serializeHash

Serializes the text message to a hash format suitable for the WhatsApp API.

Returns:

  • (Hash)

    The serialized text message.



38
39
40
# File 'lib/ruby/whatsapp/messages/text.rb', line 38

def serialize
  envelope(type: Defaults::TYPE, text: { body:, preview_url: })
end