Class: WhatsAppCloudApi::Text

Inherits:
BaseModel show all
Defined in:
lib/whats_app_cloud_api/models/text.rb

Overview

Text Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(body = nil, preview_url = false) ⇒ Text

Returns a new instance of Text.



53
54
55
56
57
# File 'lib/whats_app_cloud_api/models/text.rb', line 53

def initialize(body = nil,
               preview_url = false)
  @body = body unless body == SKIP
  @preview_url = preview_url unless preview_url == SKIP
end

Instance Attribute Details

#bodyString

Required for text messages. The text of the text message which can contain URLs which begin with http:// or https:// and formatting. See available formatting options here. If you include URLs in your text and want to include a preview box in text messages (preview_url: true), make sure the URL starts with http:// or https:// —https:// URLs are preferred. You must include a hostname, since IP addresses will not be matched.

Returns:

  • (String)


19
20
21
# File 'lib/whats_app_cloud_api/models/text.rb', line 19

def body
  @body
end

#preview_urlBoolean

By default, WhatsApp recognizes URLs and makes them clickable, but you can also include a preview box with more information about the link. Set this field to true if you want to include a URL preview box. The majority of the time, the receiver will see a URL they can click on when you send an URL, set preview_url to true, and provide a body object with a http or https link. URL previews are only rendered after one of the following has happened: The business has sent a message template to the user. The user initiates a conversation with a “click to chat” link. The user adds the business phone number to their address book and initiates a conversation.

Returns:

  • (Boolean)


31
32
33
# File 'lib/whats_app_cloud_api/models/text.rb', line 31

def preview_url
  @preview_url
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/whats_app_cloud_api/models/text.rb', line 60

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  body = hash.key?('body') ? hash['body'] : SKIP
  preview_url = hash['preview_url'] ||= false

  # Create object from extracted values.
  Text.new(body,
           preview_url)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
# File 'lib/whats_app_cloud_api/models/text.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['body'] = 'body'
  @_hash['preview_url'] = 'preview_url'
  @_hash
end

Instance Method Details

#nullablesObject

An array for nullable fields



49
50
51
# File 'lib/whats_app_cloud_api/models/text.rb', line 49

def nullables
  []
end

#optionalsObject

An array for optional fields



42
43
44
45
46
# File 'lib/whats_app_cloud_api/models/text.rb', line 42

def optionals
  %w[
    preview_url
  ]
end