mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 04:02:54 -06:00
fix:
- [Baileys] Trocar @lids em remoteJid por senderPn em todos os serviços; - [Baileys] Adicionar valor @lid recebido em remoteJid para previousRemoteJid (Posteriormente utilizasse em ChatwootService); - Minors fixes;
This commit is contained in:
parent
52798fd761
commit
630f5c5624
@ -1,7 +1,6 @@
|
|||||||
.git
|
.git
|
||||||
*Dockerfile*
|
*Dockerfile*
|
||||||
*docker-compose*
|
*docker-compose*
|
||||||
package-lock.json
|
|
||||||
.env
|
.env
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
4100
package-lock.json
generated
4100
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -73,7 +73,7 @@
|
|||||||
"form-data": "^4.0.1",
|
"form-data": "^4.0.1",
|
||||||
"https-proxy-agent": "^7.0.6",
|
"https-proxy-agent": "^7.0.6",
|
||||||
"i18next": "^23.7.19",
|
"i18next": "^23.7.19",
|
||||||
"jimp": "^0.16.13",
|
"jimp": "^1.6.0",
|
||||||
"json-schema": "^0.4.0",
|
"json-schema": "^0.4.0",
|
||||||
"jsonschema": "^1.4.1",
|
"jsonschema": "^1.4.1",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
@ -95,7 +95,7 @@
|
|||||||
"qrcode": "^1.5.4",
|
"qrcode": "^1.5.4",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"redis": "^4.7.0",
|
"redis": "^4.7.0",
|
||||||
"sharp": "^0.32.6",
|
"sharp": "^0.34.2",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"socket.io-client": "^4.8.1",
|
"socket.io-client": "^4.8.1",
|
||||||
"swagger-ui-express": "^5.0.1",
|
"swagger-ui-express": "^5.0.1",
|
||||||
|
@ -123,7 +123,7 @@ import makeWASocket, {
|
|||||||
WABrowserDescription,
|
WABrowserDescription,
|
||||||
WAMediaUpload,
|
WAMediaUpload,
|
||||||
WAMessage,
|
WAMessage,
|
||||||
WAMessageUpdate,
|
WAMessageKey,
|
||||||
WAPresence,
|
WAPresence,
|
||||||
WASocket,
|
WASocket,
|
||||||
} from 'baileys';
|
} from 'baileys';
|
||||||
@ -888,7 +888,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
}: {
|
}: {
|
||||||
chats: Chat[];
|
chats: Chat[];
|
||||||
contacts: Contact[];
|
contacts: Contact[];
|
||||||
messages: proto.IWebMessageInfo[];
|
messages: WAMessage[];
|
||||||
isLatest?: boolean;
|
isLatest?: boolean;
|
||||||
progress?: number;
|
progress?: number;
|
||||||
syncType?: proto.HistorySync.HistorySyncType;
|
syncType?: proto.HistorySync.HistorySyncType;
|
||||||
@ -974,6 +974,10 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m.key.remoteJid?.includes('@lid') && m.key.senderPn) {
|
||||||
|
m.key.remoteJid = m.key.senderPn;
|
||||||
|
}
|
||||||
|
|
||||||
if (Long.isLong(m?.messageTimestamp)) {
|
if (Long.isLong(m?.messageTimestamp)) {
|
||||||
m.messageTimestamp = m.messageTimestamp?.toNumber();
|
m.messageTimestamp = m.messageTimestamp?.toNumber();
|
||||||
}
|
}
|
||||||
@ -1031,16 +1035,24 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'messages.upsert': async (
|
'messages.upsert': async (
|
||||||
{ messages, type, requestId }: { messages: proto.IWebMessageInfo[]; type: MessageUpsertType; requestId?: string },
|
{ messages, type, requestId }: { messages: WAMessage[]; type: MessageUpsertType; requestId?: string },
|
||||||
settings: any,
|
settings: any,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
for (const received of messages) {
|
for (const received of messages) {
|
||||||
|
if (received.key.remoteJid?.includes('@lid') && received.key.senderPn) {
|
||||||
|
(received.key as { previousRemoteJid?: string | null }).previousRemoteJid = received.key.remoteJid;
|
||||||
|
received.key.remoteJid = received.key.senderPn;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
received?.messageStubParameters?.some?.((param) =>
|
received?.messageStubParameters?.some?.((param) =>
|
||||||
['No matching sessions found for message', 'Bad MAC', 'failed to decrypt message', 'SessionError'].some(
|
[
|
||||||
(err) => param?.includes?.(err),
|
'No matching sessions found for message',
|
||||||
),
|
'Bad MAC',
|
||||||
|
'failed to decrypt message',
|
||||||
|
'SessionError',
|
||||||
|
'Invalid PreKey ID',
|
||||||
|
].some((err) => param?.includes?.(err)),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
this.logger.warn(`Message ignored with messageStubParameters: ${JSON.stringify(received, null, 2)}`);
|
this.logger.warn(`Message ignored with messageStubParameters: ${JSON.stringify(received, null, 2)}`);
|
||||||
@ -1375,7 +1387,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'messages.update': async (args: WAMessageUpdate[], settings: any) => {
|
'messages.update': async (args: { update: Partial<WAMessage>; key: WAMessageKey }[], settings: any) => {
|
||||||
this.logger.log(`Update messages ${JSON.stringify(args, undefined, 2)}`);
|
this.logger.log(`Update messages ${JSON.stringify(args, undefined, 2)}`);
|
||||||
|
|
||||||
const readChatToUpdate: Record<string, true> = {}; // {remoteJid: true}
|
const readChatToUpdate: Record<string, true> = {}; // {remoteJid: true}
|
||||||
@ -1385,6 +1397,10 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (key.remoteJid?.includes('@lid') && key.senderPn) {
|
||||||
|
key.remoteJid = key.senderPn;
|
||||||
|
}
|
||||||
|
|
||||||
const updateKey = `${this.instance.id}_${key.id}_${update.status}`;
|
const updateKey = `${this.instance.id}_${key.id}_${update.status}`;
|
||||||
|
|
||||||
const cached = await this.baileysCache.get(updateKey);
|
const cached = await this.baileysCache.get(updateKey);
|
||||||
|
@ -26,7 +26,7 @@ import axios from 'axios';
|
|||||||
import { proto } from 'baileys';
|
import { proto } from 'baileys';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
import Jimp from 'jimp';
|
import { Jimp, JimpMime } from 'jimp';
|
||||||
import Long from 'long';
|
import Long from 'long';
|
||||||
import mimeTypes from 'mime-types';
|
import mimeTypes from 'mime-types';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@ -567,7 +567,7 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createConversation(instance: InstanceDto, body: any) {
|
public async createConversation(instance: InstanceDto, body: any) {
|
||||||
const isLid = body.key.remoteJid.includes('@lid') && body.key.senderPn;
|
const isLid = body.key.previousRemoteJid?.includes('@lid') && body.key.senderPn;
|
||||||
const remoteJid = isLid ? body.key.senderPn : body.key.remoteJid;
|
const remoteJid = isLid ? body.key.senderPn : body.key.remoteJid;
|
||||||
const cacheKey = `${instance.instanceName}:createConversation-${remoteJid}`;
|
const cacheKey = `${instance.instanceName}:createConversation-${remoteJid}`;
|
||||||
const lockKey = `${instance.instanceName}:lock:createConversation-${remoteJid}`;
|
const lockKey = `${instance.instanceName}:lock:createConversation-${remoteJid}`;
|
||||||
@ -575,7 +575,11 @@ export class ChatwootService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Processa atualização de contatos já criados @lid
|
// Processa atualização de contatos já criados @lid
|
||||||
if (body.key.remoteJid.includes('@lid') && body.key.senderPn && body.key.senderPn !== body.key.remoteJid) {
|
if (
|
||||||
|
body.key.previousRemoteJid?.includes('@lid') &&
|
||||||
|
body.key.senderPn &&
|
||||||
|
body.key.senderPn !== body.key.previousRemoteJid
|
||||||
|
) {
|
||||||
const contact = await this.findContact(instance, body.key.remoteJid.split('@')[0]);
|
const contact = await this.findContact(instance, body.key.remoteJid.split('@')[0]);
|
||||||
if (contact && contact.identifier !== body.key.senderPn) {
|
if (contact && contact.identifier !== body.key.senderPn) {
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
@ -713,7 +717,6 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const jid = isLid && body?.key?.senderPn ? body.key.senderPn : body.key.remoteJid;
|
|
||||||
contact = await this.createContact(
|
contact = await this.createContact(
|
||||||
instance,
|
instance,
|
||||||
chatId,
|
chatId,
|
||||||
@ -721,7 +724,7 @@ export class ChatwootService {
|
|||||||
isGroup,
|
isGroup,
|
||||||
nameContact,
|
nameContact,
|
||||||
picture_url.profilePictureUrl || null,
|
picture_url.profilePictureUrl || null,
|
||||||
jid,
|
remoteJid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2129,9 +2132,11 @@ export class ChatwootService {
|
|||||||
const fileData = Buffer.from(imgBuffer.data, 'binary');
|
const fileData = Buffer.from(imgBuffer.data, 'binary');
|
||||||
|
|
||||||
const img = await Jimp.read(fileData);
|
const img = await Jimp.read(fileData);
|
||||||
await img.cover(320, 180);
|
await img.cover({
|
||||||
|
w: 320,
|
||||||
const processedBuffer = await img.getBufferAsync(Jimp.MIME_PNG);
|
h: 180,
|
||||||
|
});
|
||||||
|
const processedBuffer = await img.getBuffer(JimpMime.png);
|
||||||
|
|
||||||
const fileStream = new Readable();
|
const fileStream = new Readable();
|
||||||
fileStream._read = () => {}; // _read is required but you can noop it
|
fileStream._read = () => {}; // _read is required but you can noop it
|
||||||
|
Loading…
Reference in New Issue
Block a user