Skip to content

Commit eeb3242

Browse files
committed
fix(baileys): adicionar log de aviso para mensagens não encontradas
- 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.
1 parent c31b62f commit eeb3242

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ export class BaileysStartupService extends ChannelStartupService {
14991499
findMessage = messages[0] || null;
15001500

15011501
if (!findMessage?.id) {
1502+
this.logger.warn(`Original message not found for update. Skipping. Key: ${JSON.stringify(key)}`);
15021503
continue;
15031504
}
15041505
message.messageId = findMessage.id;

src/utils/i18n.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,37 @@ import fs from 'fs';
33
import i18next from 'i18next';
44
import path from 'path';
55

6-
const translationsPath = fs.existsSync(path.resolve(process.cwd(), 'dist'))
7-
? path.resolve(process.cwd(), 'dist', 'translations')
8-
: path.resolve(process.cwd(), 'src', 'utils', 'translations');
6+
const distPath = path.resolve(process.cwd(), 'dist', 'translations');
7+
const srcPath = path.resolve(process.cwd(), 'src', 'utils', 'translations');
8+
9+
let translationsPath;
10+
11+
if (fs.existsSync(distPath)) {
12+
translationsPath = distPath;
13+
} else if (fs.existsSync(srcPath)) {
14+
translationsPath = srcPath;
15+
} else {
16+
console.error('Translations directory not found in dist or src.');
17+
// Fallback to a non-existent path or handle error appropriately
18+
translationsPath = '';
19+
}
920

1021
const languages = ['en', 'pt-BR', 'es'];
1122
const configService: ConfigService = new ConfigService();
1223

1324
const resources: any = {};
1425

15-
languages.forEach((language) => {
16-
const languagePath = path.join(translationsPath, `${language}.json`);
17-
if (fs.existsSync(languagePath)) {
18-
const translationContent = fs.readFileSync(languagePath, 'utf8');
19-
resources[language] = {
20-
translation: JSON.parse(translationContent),
21-
};
22-
}
23-
});
26+
if (translationsPath) {
27+
languages.forEach((language) => {
28+
const languagePath = path.join(translationsPath, `${language}.json`);
29+
if (fs.existsSync(languagePath)) {
30+
const translationContent = fs.readFileSync(languagePath, 'utf8');
31+
resources[language] = {
32+
translation: JSON.parse(translationContent),
33+
};
34+
}
35+
});
36+
}
2437

2538
i18next.init({
2639
resources,

0 commit comments

Comments
 (0)