-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(baileys): message update and i18n errors #2021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(baileys): message update and i18n errors #2021
Conversation
- Ajustada a lógica de verificação para garantir que o ID da mensagem seja definido apenas quando disponível, evitando possíveis erros de referência. - Atualizada a definição do caminho de traduções para suportar a estrutura de diretórios em produção.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a guard in the Baileys message update handler to skip missing message records—preventing Prisma validation errors—and refactors the i18n initialization to dynamically resolve translation file paths for production and development environments. Sequence diagram for Baileys message update handler with missing message guardsequenceDiagram
participant BaileysService
participant Database
participant Prisma
BaileysService->>Database: Query for original message
Database-->>BaileysService: Return message (may be null)
alt Message found
BaileysService->>Prisma: Create MessageUpdate record
Prisma-->>BaileysService: Success
else Message not found
BaileysService->>BaileysService: Skip update, continue loop
end
Class diagram for i18n initialization and translation path resolutionclassDiagram
class ConfigService {
}
class I18n {
+languages: string[]
+translationsPath: string
+resources: any
}
I18n -- ConfigService: uses
I18n : +resolveTranslationsPath()
I18n : +initialize()
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Consider logging a warning or info when skipping a message update due to a missing original message to aid debugging and monitoring.
- In the i18n initializer, verify the existence of the resolved translations directory (not just the ‘dist’ folder) before loading to avoid false positives when ‘dist’ exists but translations are missing.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider logging a warning or info when skipping a message update due to a missing original message to aid debugging and monitoring.
- In the i18n initializer, verify the existence of the resolved translations directory (not just the ‘dist’ folder) before loading to avoid false positives when ‘dist’ exists but translations are missing.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 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.
This pull request resolves two distinct issues to enhance application stability and ensure correct internationalization (i18n) in production environments. It addresses a critical Prisma validation error during message status updates and corrects a file path issue that prevented translation files from being loaded after the build process.
Fixes:
1. Prevent Prisma Validation Error on Message Updates:
PrismaClientValidationError
would occur when processing incoming message status updates (e.g., "read" receipts). This happened when an update was received for a message that did not exist in the local database, causing an unhandled promise rejection because the requiredMessage
relation could not be linked.messages.update
handler in the Baileys service. Before attempting to create aMessageUpdate
record, the system now queries for the original message. If the original message is not found, the operation is gracefully skipped for that specific update, preventing the validation error and ensuring the stability of the message processing queue.2. Correct Dynamic Path for i18n Translations:
qrgeneratedsuccesfully
) to be displayed to the user instead of the actual translated text. The file path was hardcoded to look inside thesrc/
directory, which is not present in the compileddist/
output.dist
directory at runtime. Ifdist
exists, it loads translations fromdist/translations
; otherwise, it falls back tosrc/utils/translations
for the development environment. This ensures that localization works correctly in all environments.Enhancements:
Summary
This PR improves the application's reliability by fixing a critical crash in the Baileys message update handler and ensures proper localization in production by correcting the i18n module's translation file path.
Summary by Sourcery
Prevent message processing crashes by guarding missing records during updates and fix production i18n by resolving translation paths dynamically.
Bug Fixes:
Enhancements: