Class: WhatsAppCloudApi::Message
- Defined in:
- lib/whats_app_cloud_api/models/message.rb
Overview
Message Model.
Instance Attribute Summary collapse
-
#audio ⇒ Audio
A media object containing audio.
-
#contacts ⇒ List of Contact
A contact object.
-
#document ⇒ Document
A media object containing a document.
-
#image ⇒ Image
A media object containing an image.
-
#interactive ⇒ Interactive
This option is used to send List Messages and Reply Buttons.
-
#location ⇒ Location
A location object.
-
#messaging_product ⇒ String
Messaging service used for the request.
-
#recipient_type ⇒ String
Currently, you can only send messages to individuals.
-
#sticker ⇒ Sticker
A media object containing a sticker.
-
#template ⇒ Template
A template object.
-
#text ⇒ Text
Required for text messages.
-
#to ⇒ String
WhatsApp ID or phone number for the person you want to send a message to.
-
#type ⇒ MessageTypeEnum
The type of message you want to send.
-
#video ⇒ Video
A media object containing a video.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
Instance Method Summary collapse
-
#initialize(messaging_product = nil, to = nil, audio = nil, contacts = nil, document = nil, image = nil, interactive = nil, location = nil, recipient_type = 'individual', sticker = nil, template = nil, text = nil, type = nil, video = nil) ⇒ Message
constructor
A new instance of Message.
-
#nullables ⇒ Object
An array for nullable fields.
-
#optionals ⇒ Object
An array for optional fields.
Methods inherited from BaseModel
Constructor Details
#initialize(messaging_product = nil, to = nil, audio = nil, contacts = nil, document = nil, image = nil, interactive = nil, location = nil, recipient_type = 'individual', sticker = nil, template = nil, text = nil, type = nil, video = nil) ⇒ Message
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 117 def initialize(messaging_product = nil, to = nil, audio = nil, contacts = nil, document = nil, image = nil, interactive = nil, location = nil, recipient_type = 'individual', sticker = nil, template = nil, text = nil, type = nil, video = nil) @audio = audio unless audio == SKIP @contacts = contacts unless contacts == SKIP @document = document unless document == SKIP @image = image unless image == SKIP @interactive = interactive unless interactive == SKIP @location = location unless location == SKIP @messaging_product = messaging_product unless messaging_product == SKIP @recipient_type = recipient_type unless recipient_type == SKIP @sticker = sticker unless sticker == SKIP @template = template unless template == SKIP @text = text unless text == SKIP @to = to unless to == SKIP @type = type unless type == SKIP @video = video unless video == SKIP end |
Instance Attribute Details
#audio ⇒ Audio
A media object containing audio. Required when type=audio.
14 15 16 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 14 def audio @audio end |
#contacts ⇒ List of Contact
A contact object. Required when type=contacts.
18 19 20 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 18 def contacts @contacts end |
#document ⇒ Document
A media object containing a document. Required when type=document.
22 23 24 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 22 def document @document end |
#image ⇒ Image
A media object containing an image. Required when type=image.
26 27 28 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 26 def image @image end |
#interactive ⇒ Interactive
This option is used to send List Messages and Reply Buttons. The components of each interactive object generally follow a consistent pattern: header, body, footer, and action. Required when type=interactive.
32 33 34 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 32 def interactive @interactive end |
#location ⇒ Location
A location object. Required when type=location.
36 37 38 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 36 def location @location end |
#messaging_product ⇒ String
Messaging service used for the request.
40 41 42 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 40 def messaging_product @messaging_product end |
#recipient_type ⇒ String
Currently, you can only send messages to individuals.
44 45 46 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 44 def recipient_type @recipient_type end |
#sticker ⇒ Sticker
A media object containing a sticker. Currently, we support inbound both and outbound stickers: For outbound, we only support static third-party stickers. For inbound, we support all types of stickers. The sticker needs to be 512x512 pixels and the file’s size needs to be less than 100 KB. Required when type=sticker.
52 53 54 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 52 def sticker @sticker end |
#template ⇒ Template
A template object. Required when type=template.
56 57 58 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 56 def template @template end |
#text ⇒ Text
Required for text messages.
60 61 62 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 60 def text @text end |
#to ⇒ String
WhatsApp ID or phone number for the person you want to send a message to.
64 65 66 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 64 def to @to end |
#type ⇒ MessageTypeEnum
The type of message you want to send.
68 69 70 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 68 def type @type end |
#video ⇒ Video
A media object containing a video. Required when type=video.
72 73 74 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 72 def video @video end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 148 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. messaging_product = hash.key?('messaging_product') ? hash['messaging_product'] : SKIP to = hash.key?('to') ? hash['to'] : SKIP audio = Audio.from_hash(hash['audio']) if hash['audio'] # Parameter is an array, so we need to iterate through it contacts = nil unless hash['contacts'].nil? contacts = [] hash['contacts'].each do |structure| contacts << (Contact.from_hash(structure) if structure) end end contacts = SKIP unless hash.key?('contacts') document = Document.from_hash(hash['document']) if hash['document'] image = Image.from_hash(hash['image']) if hash['image'] interactive = Interactive.from_hash(hash['interactive']) if hash['interactive'] location = Location.from_hash(hash['location']) if hash['location'] recipient_type = hash['recipient_type'] ||= 'individual' sticker = Sticker.from_hash(hash['sticker']) if hash['sticker'] template = Template.from_hash(hash['template']) if hash['template'] text = Text.from_hash(hash['text']) if hash['text'] type = hash.key?('type') ? hash['type'] : SKIP video = Video.from_hash(hash['video']) if hash['video'] # Create object from extracted values. Message.new(messaging_product, to, audio, contacts, document, image, interactive, location, recipient_type, sticker, template, text, type, video) end |
.names ⇒ Object
A mapping from model property names to API property names.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 75 def self.names @_hash = {} if @_hash.nil? @_hash['audio'] = 'audio' @_hash['contacts'] = 'contacts' @_hash['document'] = 'document' @_hash['image'] = 'image' @_hash['interactive'] = 'interactive' @_hash['location'] = 'location' @_hash['messaging_product'] = 'messaging_product' @_hash['recipient_type'] = 'recipient_type' @_hash['sticker'] = 'sticker' @_hash['template'] = 'template' @_hash['text'] = 'text' @_hash['to'] = 'to' @_hash['type'] = 'type' @_hash['video'] = 'video' @_hash end |
Instance Method Details
#nullables ⇒ Object
An array for nullable fields
113 114 115 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 113 def nullables [] end |
#optionals ⇒ Object
An array for optional fields
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/whats_app_cloud_api/models/message.rb', line 95 def optionals %w[ audio contacts document image interactive location recipient_type sticker template text type video ] end |