Class: EvolutionApi::Message
- Inherits:
-
Object
- Object
- EvolutionApi::Message
- Defined in:
- lib/evolution_api/message.rb
Overview
Classe para representar mensagens do WhatsApp
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#instance_name ⇒ Object
readonly
Returns the value of attribute instance_name.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#message_timestamp ⇒ Object
readonly
Returns the value of attribute message_timestamp.
-
#participant ⇒ Object
readonly
Returns the value of attribute participant.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#audio ⇒ Object
Obtém informações do áudio.
-
#audio? ⇒ Boolean
Verifica se é uma mensagem de áudio.
-
#broadcast? ⇒ Boolean
Verifica se é uma mensagem de broadcast.
-
#button ⇒ Object
Obtém informações do botão.
-
#button? ⇒ Boolean
Verifica se é uma mensagem de botão.
-
#contact ⇒ Object
Obtém informações do contato.
-
#contact? ⇒ Boolean
Verifica se é um contato.
-
#delivered? ⇒ Boolean
Verifica se a mensagem foi entregue.
-
#document ⇒ Object
Obtém informações do documento.
-
#document? ⇒ Boolean
Verifica se é um documento.
-
#failed? ⇒ Boolean
Verifica se a mensagem falhou.
-
#from ⇒ Object
Obtém o número do remetente.
-
#from_me? ⇒ Boolean
Verifica se a mensagem foi enviada pelo próprio usuário.
-
#group? ⇒ Boolean
Verifica se é uma mensagem de grupo.
-
#image ⇒ Object
Obtém informações da imagem.
-
#image? ⇒ Boolean
Verifica se é uma mensagem de imagem.
-
#initialize(data, instance_name = nil) ⇒ Message
constructor
A new instance of Message.
-
#list ⇒ Object
Obtém informações da lista.
-
#list? ⇒ Boolean
Verifica se é uma lista.
-
#location ⇒ Object
Obtém informações da localização.
-
#location? ⇒ Boolean
Verifica se é uma localização.
-
#message_id ⇒ Object
Obtém o ID da mensagem.
-
#private? ⇒ Boolean
Verifica se é uma mensagem privada.
-
#reaction ⇒ Object
Obtém informações da reação.
-
#reaction? ⇒ Boolean
Verifica se é uma mensagem de reação.
-
#read? ⇒ Boolean
Verifica se a mensagem foi lida.
-
#sent? ⇒ Boolean
Verifica se a mensagem foi enviada.
-
#sticker ⇒ Object
Obtém informações do sticker.
-
#sticker? ⇒ Boolean
Verifica se é uma mensagem de sticker.
-
#text ⇒ Object
Obtém o texto da mensagem.
-
#text? ⇒ Boolean
Verifica se é uma mensagem de texto.
-
#timestamp ⇒ Object
Obtém o timestamp da mensagem.
-
#to_h ⇒ Object
Converte para hash.
-
#to_json(*args) ⇒ Object
Converte para JSON.
-
#type ⇒ Object
Obtém o tipo da mensagem.
-
#video ⇒ Object
Obtém informações do vídeo.
-
#video? ⇒ Boolean
Verifica se é uma mensagem de vídeo.
Constructor Details
#initialize(data, instance_name = nil) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 14 15 16 |
# File 'lib/evolution_api/message.rb', line 8 def initialize(data, instance_name = nil) @id = data['id'] @key = data['key'] @message = data['message'] @message_timestamp = data['messageTimestamp'] @status = data['status'] @participant = data['participant'] @instance_name = instance_name end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/evolution_api/message.rb', line 6 def id @id end |
#instance_name ⇒ Object (readonly)
Returns the value of attribute instance_name.
6 7 8 |
# File 'lib/evolution_api/message.rb', line 6 def instance_name @instance_name end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/evolution_api/message.rb', line 6 def key @key end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/evolution_api/message.rb', line 6 def @message end |
#message_timestamp ⇒ Object (readonly)
Returns the value of attribute message_timestamp.
6 7 8 |
# File 'lib/evolution_api/message.rb', line 6 def @message_timestamp end |
#participant ⇒ Object (readonly)
Returns the value of attribute participant.
6 7 8 |
# File 'lib/evolution_api/message.rb', line 6 def participant @participant end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/evolution_api/message.rb', line 6 def status @status end |
Instance Method Details
#audio ⇒ Object
Obtém informações do áudio
49 50 51 52 53 |
# File 'lib/evolution_api/message.rb', line 49 def audio return nil unless audio? ['audioMessage'] end |
#audio? ⇒ Boolean
Verifica se é uma mensagem de áudio
44 45 46 |
# File 'lib/evolution_api/message.rb', line 44 def audio? &.key?('audioMessage') end |
#broadcast? ⇒ Boolean
Verifica se é uma mensagem de broadcast
169 170 171 |
# File 'lib/evolution_api/message.rb', line 169 def broadcast? key['remoteJid']&.include?('@broadcast') end |
#button ⇒ Object
Obtém informações do botão
109 110 111 112 113 114 |
# File 'lib/evolution_api/message.rb', line 109 def return ['buttonsResponseMessage'] if &.key?('buttonsResponseMessage') return ['buttonMessage'] if &.key?('buttonMessage') nil end |
#button? ⇒ Boolean
Verifica se é uma mensagem de botão
104 105 106 |
# File 'lib/evolution_api/message.rb', line 104 def &.key?('buttonsResponseMessage') || &.key?('buttonMessage') end |
#contact ⇒ Object
Obtém informações do contato
97 98 99 100 101 |
# File 'lib/evolution_api/message.rb', line 97 def contact return nil unless contact? ['contactMessage'] end |
#contact? ⇒ Boolean
Verifica se é um contato
92 93 94 |
# File 'lib/evolution_api/message.rb', line 92 def contact? &.key?('contactMessage') end |
#delivered? ⇒ Boolean
Verifica se a mensagem foi entregue
194 195 196 |
# File 'lib/evolution_api/message.rb', line 194 def delivered? status == 'delivered' end |
#document ⇒ Object
Obtém informações do documento
73 74 75 76 77 |
# File 'lib/evolution_api/message.rb', line 73 def document return nil unless document? ['documentMessage'] end |
#document? ⇒ Boolean
Verifica se é um documento
68 69 70 |
# File 'lib/evolution_api/message.rb', line 68 def document? &.key?('documentMessage') end |
#failed? ⇒ Boolean
Verifica se a mensagem falhou
204 205 206 |
# File 'lib/evolution_api/message.rb', line 204 def failed? status == 'failed' end |
#from ⇒ Object
Obtém o número do remetente
154 155 156 |
# File 'lib/evolution_api/message.rb', line 154 def from key['remoteJid']&.split('@')&.first end |
#from_me? ⇒ Boolean
Verifica se a mensagem foi enviada pelo próprio usuário
179 180 181 |
# File 'lib/evolution_api/message.rb', line 179 def from_me? key['fromMe'] == true end |
#group? ⇒ Boolean
Verifica se é uma mensagem de grupo
164 165 166 |
# File 'lib/evolution_api/message.rb', line 164 def group? key['remoteJid']&.include?('@g.us') end |
#image ⇒ Object
Obtém informações da imagem
37 38 39 40 41 |
# File 'lib/evolution_api/message.rb', line 37 def image return nil unless image? ['imageMessage'] end |
#image? ⇒ Boolean
Verifica se é uma mensagem de imagem
32 33 34 |
# File 'lib/evolution_api/message.rb', line 32 def image? &.key?('imageMessage') end |
#list ⇒ Object
Obtém informações da lista
122 123 124 125 126 127 |
# File 'lib/evolution_api/message.rb', line 122 def list return ['listResponseMessage'] if &.key?('listResponseMessage') return ['listMessage'] if &.key?('listMessage') nil end |
#list? ⇒ Boolean
Verifica se é uma lista
117 118 119 |
# File 'lib/evolution_api/message.rb', line 117 def list? &.key?('listResponseMessage') || &.key?('listMessage') end |
#location ⇒ Object
Obtém informações da localização
85 86 87 88 89 |
# File 'lib/evolution_api/message.rb', line 85 def location return nil unless location? ['locationMessage'] end |
#location? ⇒ Boolean
Verifica se é uma localização
80 81 82 |
# File 'lib/evolution_api/message.rb', line 80 def location? &.key?('locationMessage') end |
#message_id ⇒ Object
Obtém o ID da mensagem
159 160 161 |
# File 'lib/evolution_api/message.rb', line 159 def key['id'] end |
#private? ⇒ Boolean
Verifica se é uma mensagem privada
174 175 176 |
# File 'lib/evolution_api/message.rb', line 174 def private? !group? && !broadcast? end |
#reaction ⇒ Object
Obtém informações da reação
135 136 137 138 139 |
# File 'lib/evolution_api/message.rb', line 135 def reaction return nil unless reaction? ['reactionMessage'] end |
#reaction? ⇒ Boolean
Verifica se é uma mensagem de reação
130 131 132 |
# File 'lib/evolution_api/message.rb', line 130 def reaction? &.key?('reactionMessage') end |
#read? ⇒ Boolean
Verifica se a mensagem foi lida
189 190 191 |
# File 'lib/evolution_api/message.rb', line 189 def read? status == 'read' end |
#sent? ⇒ Boolean
Verifica se a mensagem foi enviada
199 200 201 |
# File 'lib/evolution_api/message.rb', line 199 def sent? status == 'sent' end |
#sticker ⇒ Object
Obtém informações do sticker
147 148 149 150 151 |
# File 'lib/evolution_api/message.rb', line 147 def sticker return nil unless sticker? ['stickerMessage'] end |
#sticker? ⇒ Boolean
Verifica se é uma mensagem de sticker
142 143 144 |
# File 'lib/evolution_api/message.rb', line 142 def sticker? &.key?('stickerMessage') end |
#text ⇒ Object
Obtém o texto da mensagem
24 25 26 27 28 29 |
# File 'lib/evolution_api/message.rb', line 24 def text return ['conversation'] if &.key?('conversation') return ['extendedTextMessage']['text'] if &.key?('extendedTextMessage') nil end |
#text? ⇒ Boolean
Verifica se é uma mensagem de texto
19 20 21 |
# File 'lib/evolution_api/message.rb', line 19 def text? &.key?('conversation') || &.key?('extendedTextMessage') end |
#timestamp ⇒ Object
Obtém o timestamp da mensagem
184 185 186 |
# File 'lib/evolution_api/message.rb', line 184 def Time.at() if end |
#to_h ⇒ Object
Converte para hash
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/evolution_api/message.rb', line 226 def to_h { id: id, key: key, message: , message_timestamp: , status: status, participant: participant, instance_name: instance_name, type: type, from: from, from_me: from_me?, group: group?, timestamp: , text: text } end |
#to_json(*args) ⇒ Object
Converte para JSON
245 246 247 |
# File 'lib/evolution_api/message.rb', line 245 def to_json(*args) to_h.to_json(*args) end |
#type ⇒ Object
Obtém o tipo da mensagem
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/evolution_api/message.rb', line 209 def type return 'text' if text? return 'image' if image? return 'audio' if audio? return 'video' if video? return 'document' if document? return 'location' if location? return 'contact' if contact? return 'button' if return 'list' if list? return 'reaction' if reaction? return 'sticker' if sticker? 'unknown' end |
#video ⇒ Object
Obtém informações do vídeo
61 62 63 64 65 |
# File 'lib/evolution_api/message.rb', line 61 def video return nil unless video? ['videoMessage'] end |
#video? ⇒ Boolean
Verifica se é uma mensagem de vídeo
56 57 58 |
# File 'lib/evolution_api/message.rb', line 56 def video? &.key?('videoMessage') end |