Skip to content

Commit b62917e

Browse files
Merge pull request #2021 from Vitordotpy/fix/message-update-and-i18n-errors
fix(baileys): message update and i18n errors
2 parents 22465c0 + eeb3242 commit b62917e

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,11 @@ export class BaileysStartupService extends ChannelStartupService {
14981498
`) as any[];
14991499
findMessage = messages[0] || null;
15001500

1501-
if (findMessage) message.messageId = findMessage.id;
1501+
if (!findMessage?.id) {
1502+
this.logger.warn(`Original message not found for update. Skipping. Key: ${JSON.stringify(key)}`);
1503+
continue;
1504+
}
1505+
message.messageId = findMessage.id;
15021506
}
15031507

15041508
if (update.message === null && update.status === undefined) {

src/utils/i18n.ts

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

6-
const __dirname = path.resolve(process.cwd(), 'src', 'utils');
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+
}
720

821
const languages = ['en', 'pt-BR', 'es'];
9-
const translationsPath = path.join(__dirname, 'translations');
1022
const configService: ConfigService = new ConfigService();
1123

1224
const resources: any = {};
1325

14-
languages.forEach((language) => {
15-
const languagePath = path.join(translationsPath, `${language}.json`);
16-
if (fs.existsSync(languagePath)) {
17-
const translationContent = fs.readFileSync(languagePath, 'utf8');
18-
resources[language] = {
19-
translation: JSON.parse(translationContent),
20-
};
21-
}
22-
});
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+
}
2337

2438
i18next.init({
2539
resources,

0 commit comments

Comments
 (0)