@areumtecnologia/baileys 1.1.21 → 1.1.23
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.
- package/handlers/messages.js +2 -1
- package/index.js +17 -6
- package/package.json +1 -1
package/handlers/messages.js
CHANGED
|
@@ -45,7 +45,8 @@ class MessageHandler {
|
|
|
45
45
|
await new Promise(r => setTimeout(() => r(true), options.recording?.timeout));
|
|
46
46
|
}
|
|
47
47
|
const msg = await this.client.sock.sendMessage(verifiedJid.jid, content, options);
|
|
48
|
-
const
|
|
48
|
+
const c = await this.client.contacts.normalize({ key: { remoteJid: verifiedJid.jid } });
|
|
49
|
+
const nmsg = await MessageNormalizer.normalize(c, msg, this.client);
|
|
49
50
|
return nmsg;
|
|
50
51
|
}
|
|
51
52
|
else {
|
package/index.js
CHANGED
|
@@ -317,7 +317,9 @@ class Client extends EventEmitter {
|
|
|
317
317
|
for (const g of grupos) {
|
|
318
318
|
let contact = await this.contacts.get(g.id);
|
|
319
319
|
contact = await this.contacts.normalize({ key: { remoteJid: g.id, fromMe: false } });
|
|
320
|
-
|
|
320
|
+
if (contact && contact.id && contact.name && contact.id !== this.user?.id) {
|
|
321
|
+
this.contacts.set(contact.id, contact);
|
|
322
|
+
}
|
|
321
323
|
this.groups.store.set(g.id, contact.metadata);
|
|
322
324
|
groupCache.set(g.id, contact.metadata);
|
|
323
325
|
gp.push(contact.metadata);
|
|
@@ -330,7 +332,9 @@ class Client extends EventEmitter {
|
|
|
330
332
|
let contact = await this.contacts.get(event.id);
|
|
331
333
|
if (!contact) {
|
|
332
334
|
contact = await this.contacts.normalize({ key: { remoteJid: event.id, fromMe: false } });
|
|
333
|
-
|
|
335
|
+
if (contact && contact.id && contact.name && contact.id !== this.user?.id) {
|
|
336
|
+
this.contacts.set(contact.id, contact);
|
|
337
|
+
}
|
|
334
338
|
}
|
|
335
339
|
this.groups.store.set(event.id, contact.metadata);
|
|
336
340
|
});
|
|
@@ -356,7 +360,7 @@ class Client extends EventEmitter {
|
|
|
356
360
|
contact = await this.contacts.normalize({ key: { remoteJid: jid } });
|
|
357
361
|
}
|
|
358
362
|
// Adiciona contato valido no cache e no array
|
|
359
|
-
if (contact && contact.id) {
|
|
363
|
+
if (contact && contact.id && contact.name && contact.id !== this.user?.id) {
|
|
360
364
|
cxs.push(contact);
|
|
361
365
|
this.contacts.set(contact.id, contact);
|
|
362
366
|
}
|
|
@@ -378,13 +382,17 @@ class Client extends EventEmitter {
|
|
|
378
382
|
for (const contact of contacts) {
|
|
379
383
|
const chatId = contact.id;
|
|
380
384
|
const c = await this.contacts.normalize({ key: { remoteJid: chatId } });
|
|
381
|
-
|
|
385
|
+
if (c && c.id && c.name && c.id !== this.user?.id) {
|
|
386
|
+
this.contacts.set(c.id, c);
|
|
387
|
+
}
|
|
382
388
|
}
|
|
383
389
|
// Normaliza os chats
|
|
384
390
|
for (const chat of chats) {
|
|
385
391
|
const chatId = chat.id;
|
|
386
392
|
const c = await this.contacts.normalize({ key: { remoteJid: chatId } });
|
|
387
|
-
|
|
393
|
+
if (c && c.id && c.name && c.id !== this.user?.id) {
|
|
394
|
+
this.contacts.set(c.id, c);
|
|
395
|
+
}
|
|
388
396
|
const messages = messages.filter(m => m.key.remoteJid === chatId);
|
|
389
397
|
for (const msg of messages) {
|
|
390
398
|
const nmsg = MessageNormalizer.normalize(c, msg, this);
|
|
@@ -411,7 +419,6 @@ class Client extends EventEmitter {
|
|
|
411
419
|
let contact = await this.contacts.get(msg.key.remoteJid);
|
|
412
420
|
if (!contact) {
|
|
413
421
|
contact = await this.contacts.normalize(msg); // msg ja contem tudo que precisa
|
|
414
|
-
this.contacts.set(contact.id, contact);
|
|
415
422
|
}
|
|
416
423
|
if (msg.broadcast || msg.key.remoteJid == 'status@broadcast') {
|
|
417
424
|
this.emit(ClientEvent.BROADCAST_MESSAGE, msg);
|
|
@@ -430,6 +437,10 @@ class Client extends EventEmitter {
|
|
|
430
437
|
if (msg.key.fromMe) {
|
|
431
438
|
this.emit(ClientEvent.MESSAGE_SENT, nmsg);
|
|
432
439
|
} else {
|
|
440
|
+
// So adiciona contato no cache se for recebido
|
|
441
|
+
if (contact && contact.id && contact.name && contact.id !== this.user?.id) {
|
|
442
|
+
this.contacts.set(contact.id, contact);
|
|
443
|
+
}
|
|
433
444
|
this.emit(ClientEvent.MESSAGE_RECEIVED, nmsg);
|
|
434
445
|
}
|
|
435
446
|
|