Merge pull request #1732 from rafwell/testmsg

Ignore events that are not messages (like EPHEMERAL_SYNC_RESPONSE)
This commit is contained in:
Davidson Gomes 2025-07-21 13:15:38 -03:00 committed by GitHub
commit 5386d7171b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -567,6 +567,13 @@ export class ChatwootService {
}
public async createConversation(instance: InstanceDto, body: any) {
if (!body?.key) {
this.logger.warn(
`body.key is null or undefined in createConversation. Full body object: ${JSON.stringify(body)}`,
);
return null;
}
const isLid = body.key.previousRemoteJid?.includes('@lid') && body.key.senderPn;
const remoteJid = body.key.remoteJid;
const cacheKey = `${instance.instanceName}:createConversation-${remoteJid}`;
@ -1893,6 +1900,12 @@ export class ChatwootService {
public async eventWhatsapp(event: string, instance: InstanceDto, body: any) {
try {
// Ignore events that are not messages (like EPHEMERAL_SYNC_RESPONSE)
if (body?.type && body.type !== 'message' && body.type !== 'conversation') {
this.logger.verbose(`Ignoring non-message event type: ${body.type}`);
return;
}
const waInstance = this.waMonitor.waInstances[instance.instanceName];
if (!waInstance) {
@ -1938,6 +1951,11 @@ export class ChatwootService {
}
if (event === 'messages.upsert' || event === 'send.message') {
if (!body?.key) {
this.logger.warn(`body.key is null or undefined. Full body object: ${JSON.stringify(body)}`);
return;
}
if (body.key.remoteJid === 'status@broadcast') {
return;
}
@ -2260,10 +2278,23 @@ export class ChatwootService {
}
if (event === 'messages.edit' || event === 'send.message.update') {
// Ignore events that are not messages (like EPHEMERAL_SYNC_RESPONSE)
if (body?.type && body.type !== 'message') {
this.logger.verbose(`Ignoring non-message event type: ${body.type}`);
return;
}
if (!body?.key?.id) {
this.logger.warn(
`body.key.id is null or undefined in messages.edit. Full body object: ${JSON.stringify(body)}`,
);
return;
}
const editedText = `${
body?.editedMessage?.conversation || body?.editedMessage?.extendedTextMessage?.text
}\n\n_\`${i18next.t('cw.message.edited')}.\`_`;
const message = await this.getMessageByKeyId(instance, body?.key?.id);
const message = await this.getMessageByKeyId(instance, body.key.id);
const key = message.key as {
id: string;
fromMe: boolean;