@areumtecnologia/baileys 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,10 @@ class MessageHandler {
36
36
  this.client._validateConnection();
37
37
  const verifiedJid = await this.client.users.isOnWhatsApp(jid);
38
38
  if (verifiedJid && verifiedJid.exists) {
39
+ if (options.composing) {
40
+ this.client.sock.sendPresenceUpdate('composing', verifiedJid.jid);
41
+ await new Promise(r => setTimeout(() => r(true), options.composing?.timeout));
42
+ }
39
43
  const msg = await this.client.sock.sendMessage(verifiedJid.jid, content, options);
40
44
  const nmsg = await MessageNormalizer.normalize(msg, this.client);
41
45
  return nmsg;
@@ -216,29 +220,12 @@ class MessageHandler {
216
220
  // MÉTODOS INTERATIVOS E OUTROS
217
221
  // =================================================================================================
218
222
  /** Envia acoes */
219
- async sendTyping(jid) {
220
- try {
221
- this.client._validateConnection();
222
- const verifiedJid = await this.client.users.isOnWhatsApp(jid);
223
- if (verifiedJid && verifiedJid.exists) {
224
-
225
- await this.client.sock.presenceSubscribe(jid)
226
- await this.client.sock.sendPresenceUpdate('available', jid)
227
- await Utils.delay(500);
228
-
229
- await this.client.sock.sendPresenceUpdate('composing', jid)
230
- await Utils.delay(5000)
231
223
 
232
- return await this.client.sock.sendPresenceUpdate('paused', jid)
233
- }
234
- else {
235
- return verifiedJid;
236
- }
237
-
238
- } catch (error) {
239
- throw error;
240
- }
224
+ // Metodo para enviar notificacao "digitando"
225
+ composing(jid, ts) {
226
+ return this.client.sock.sendPresenceUpdate('composing', jid);
241
227
  }
228
+
242
229
  /** Marca mensagens como lidas. */
243
230
  async read(messageKey) {
244
231
  this.client._validateConnection();
package/index.js CHANGED
@@ -416,6 +416,10 @@ class Client extends EventEmitter {
416
416
  return false;
417
417
  }
418
418
  }
419
+ // Metodo para enviar notificacao "digitando"
420
+ composing(jid, ts) {
421
+ return this.sock.sendPresenceUpdate('composing', jid);
422
+ }
419
423
 
420
424
  }
421
425
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@areumtecnologia/baileys",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "More baileys fork",
5
5
  "license": "ISC",
6
6
  "author": "Áreum Tecnologia",
@@ -31,7 +31,7 @@ class MessageNormalizer {
31
31
  const type = this._getFriendlyType(rawMessage.message);
32
32
  const messageContent = rawMessage.message[originalType];
33
33
  const contextInfo = messageContent?.contextInfo;
34
- const chatId = rawMessage.key.remoteJid.includes('@lid') ? rawMessage.key.remoteJidAlt : rawMessage.key.remoteJid;
34
+ const chatId = rawMessage.key.remoteJid.includes('@lid') ? rawMessage.key.remoteJidAlt?.replace(/:.*?@/, "@") : rawMessage.key.remoteJid;
35
35
  const isGroup = chatId.endsWith('@g.us');
36
36
  const clientJid = client.jidNormalizedUser(client.sock.user.id);
37
37
  const from = isGroup ? rawMessage.key.participant : rawMessage.key.fromMe ? clientJid : chatId;
@@ -91,24 +91,52 @@ class MessageNormalizer {
91
91
 
92
92
  /**
93
93
  * @private Retorna um tipo amigável baseado no conteúdo da mensagem.
94
+ *
95
+ *
96
+ * {
97
+ "text": "This is an Interactive message!",
98
+ "title": "Hiii",
99
+ "subtitle": "There is a subtitle",
100
+ "footer": "Hello World!",
101
+ "interactiveButtons": [
102
+ {
103
+ "name": "cta_copy",
104
+ "buttonParamsJson": "{\"display_text\":\"Click Me!\",\"copy_code\":\"12345\"}"
105
+ }
106
+ ]
107
+ }
108
+ *
94
109
  */
95
110
  static _getFriendlyType(message) {
96
111
  if (!message) return 'unknown'
97
112
 
98
- if (message.conversation || message.extendedTextMessage) return 'text'
99
- if (message.imageMessage) return 'image'
100
- if (message.videoMessage) return 'video'
101
- if (message.audioMessage) return 'audio'
102
- if (message.documentMessage) return 'document'
103
- if (message.stickerMessage) return 'sticker'
104
- if (message.locationMessage) return 'location'
105
- if (message.contactMessage || message.contactsArrayMessage) return 'contact'
106
- if (message.buttonsResponseMessage || message.listResponseMessage) return 'interactive_reply'
107
- if (message.reactionMessage) return 'reaction'
108
- if (message.pollCreationMessage || message.pollCreationMessageV3) return 'poll_creation'
109
- if (message.pollUpdateMessage) return 'poll_update'
110
-
111
- return 'unknown'
113
+ if (message.conversation || message.extendedTextMessage) return 'text';
114
+ if (message.imageMessage) return 'image';
115
+ if (message.videoMessage) return 'video';
116
+ if (message.audioMessage) return 'audio';
117
+ if (message.documentMessage) return 'document';
118
+ if (message.stickerMessage) return 'sticker';
119
+ if (message.locationMessage) return 'location';
120
+ if (message.contactMessage || message.contactsArrayMessage) return 'contact';
121
+ if (message.buttonsResponseMessage || message.listResponseMessage) return 'interactive_reply';
122
+ if (message.reactionMessage) return 'reaction';
123
+ if (message.pollCreationMessage || message.pollCreationMessageV3) return 'poll_creation';
124
+ if (message.pollUpdateMessage) return 'poll_update';
125
+ // Detectar o tipo de interactiveButtons pela propriedade name, se interactive buttons tiver apenas um botão
126
+ if (message.interactiveMessage && message.interactiveMessage.interactiveButtons && message.interactiveMessage.interactiveButtons[0].name === 'review_and_pay') return 'review_and_pay';
127
+ if (message.interactiveMessage && message.interactiveMessage.interactiveButtons && message.interactiveMessage.interactiveButtons[0].name === 'review_order') return 'review_order';
128
+ if (message.interactiveMessage && message.interactiveMessage.interactiveButtons && message.interactiveMessage.interactiveButtons[0].name === 'quick_reply') return 'quick_reply';
129
+ if (message.interactiveMessage && message.interactiveMessage.interactiveButtons && message.interactiveMessage.interactiveButtons[0].name === 'cta_url') return 'cta_url';
130
+ if (message.interactiveMessage && message.interactiveMessage.interactiveButtons && message.interactiveMessage.interactiveButtons[0].name === 'cta_copy') return 'cta_copy';
131
+ if (message.interactiveMessage && message.interactiveMessage.interactiveButtons && message.interactiveMessage.interactiveButtons[0].name === 'cta_call') return 'cta_call';
132
+ if (message.interactiveMessage && message.interactiveMessage.interactiveButtons && message.interactiveMessage.interactiveButtons[0].name === 'voice_call') return 'voice_call';
133
+
134
+ if (message.interactiveMessage) return 'interactive_message';
135
+ if (message.interactiveMessage.interactiveButtons) return 'interactive_buttons';
136
+ if (message.interactiveMessage.interactiveList) return 'interactive_list';
137
+
138
+
139
+ return 'unknown';
112
140
  }
113
141
 
114
142