From eeb324227b55c9f9b1a37013438d57294d3e083b Mon Sep 17 00:00:00 2001 From: Vitordotpy Date: Fri, 26 Sep 2025 16:12:40 -0300 Subject: [PATCH] =?UTF-8?q?fix(baileys):=20adicionar=20log=20de=20aviso=20?= =?UTF-8?q?para=20mensagens=20n=C3=A3o=20encontradas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implementada uma mensagem de aviso no serviço Baileys quando a mensagem original não é encontrada durante a atualização, melhorando a rastreabilidade de erros. - Ajustada a lógica de verificação do caminho de traduções para garantir que o diretório correto seja utilizado, com tratamento de erro caso não seja encontrado. --- .../whatsapp/whatsapp.baileys.service.ts | 1 + src/utils/i18n.ts | 37 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index ccb594f2..82252dcb 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1499,6 +1499,7 @@ export class BaileysStartupService extends ChannelStartupService { findMessage = messages[0] || null; if (!findMessage?.id) { + this.logger.warn(`Original message not found for update. Skipping. Key: ${JSON.stringify(key)}`); continue; } message.messageId = findMessage.id; diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts index 09b9feb0..e8aea42b 100644 --- a/src/utils/i18n.ts +++ b/src/utils/i18n.ts @@ -3,24 +3,37 @@ import fs from 'fs'; import i18next from 'i18next'; import path from 'path'; -const translationsPath = fs.existsSync(path.resolve(process.cwd(), 'dist')) - ? path.resolve(process.cwd(), 'dist', 'translations') - : path.resolve(process.cwd(), 'src', 'utils', 'translations'); +const distPath = path.resolve(process.cwd(), 'dist', 'translations'); +const srcPath = path.resolve(process.cwd(), 'src', 'utils', 'translations'); + +let translationsPath; + +if (fs.existsSync(distPath)) { + translationsPath = distPath; +} else if (fs.existsSync(srcPath)) { + translationsPath = srcPath; +} else { + console.error('Translations directory not found in dist or src.'); + // Fallback to a non-existent path or handle error appropriately + translationsPath = ''; +} const languages = ['en', 'pt-BR', 'es']; const configService: ConfigService = new ConfigService(); const resources: any = {}; -languages.forEach((language) => { - const languagePath = path.join(translationsPath, `${language}.json`); - if (fs.existsSync(languagePath)) { - const translationContent = fs.readFileSync(languagePath, 'utf8'); - resources[language] = { - translation: JSON.parse(translationContent), - }; - } -}); +if (translationsPath) { + languages.forEach((language) => { + const languagePath = path.join(translationsPath, `${language}.json`); + if (fs.existsSync(languagePath)) { + const translationContent = fs.readFileSync(languagePath, 'utf8'); + resources[language] = { + translation: JSON.parse(translationContent), + }; + } + }); +} i18next.init({ resources,