Permitir correta utilização da evolution quando mensagens não são persistidas no DB by onerrogus · Pull Request #1798 · EvolutionAPI/evolution-api · GitHub
Skip to content

Permitir correta utilização da evolution quando mensagens não são persistidas no DB#1798

Merged
DavidsonGomes merged 8 commits intoEvolutionAPI:developfrom
apresentame:fix/webhook_event
Aug 4, 2025
Merged

Permitir correta utilização da evolution quando mensagens não são persistidas no DB#1798
DavidsonGomes merged 8 commits intoEvolutionAPI:developfrom
apresentame:fix/webhook_event

Conversation

@onerrogus
Copy link
Copy Markdown
Contributor

@onerrogus onerrogus commented Aug 4, 2025

Summary by Sourcery

Add configuration flags to control message persistence and history retrieval, enabling selective saving and logging of incoming messages and updates based on SAVE_DATA settings

Enhancements:

  • Use SAVE_DATA.HISTORIC and SAVE_DATA.NEW_MESSAGE flags to conditionally fetch and assign stored message IDs
  • Guard creation of message update records behind the SAVE_DATA.MESSAGE_UPDATE flag
  • Bypass message formatting and editing validations when new message persistence is disabled

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @onerrogus - I've reviewed your changes - here's some feedback:

  • Cache the DATABASE.SAVE_DATA config at the start of the method or as a class property to avoid repeating configService.get calls and improve readability.
  • Extract the conditional logic for historic, new message, and message update handling into dedicated helper methods to reduce nesting and duplication.
  • Centralize the SAVE_DATA flag checks into a single guard or utility function to ensure consistent behavior across all message operations.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Cache the DATABASE.SAVE_DATA config at the start of the method or as a class property to avoid repeating configService.get calls and improve readability.
- Extract the conditional logic for historic, new message, and message update handling into dedicated helper methods to reduce nesting and duplication.
- Centralize the SAVE_DATA flag checks into a single guard or utility function to ensure consistent behavior across all message operations.

## Individual Comments

### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:3789` </location>
<code_context>

   private async formatUpdateMessage(data: UpdateMessageDto) {
     try {
+      if (!this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
+        return data;
+      }
</code_context>

<issue_to_address>
Early return skips formatting if NEW_MESSAGE is false.

Ensure that all consumers of this method are prepared to handle unformatted data when NEW_MESSAGE is false, as this may affect downstream processing.
</issue_to_address>

### Comment 2
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:3852` </location>
<code_context>

           const messageId = messageSent.message?.protocolMessage?.key?.id;
-          if (messageId) {
+          if (messageId && this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
             let message = await this.prismaRepository.message.findFirst({
               where: { key: { path: ['id'], equals: messageId } },
</code_context>

<issue_to_address>
Message update logic is now gated by NEW_MESSAGE flag.

Consider whether message updates should ever occur when NEW_MESSAGE is false, as this change will prevent all such updates.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


private async formatUpdateMessage(data: UpdateMessageDto) {
try {
if (!this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (bug_risk): Early return skips formatting if NEW_MESSAGE is false.

Ensure that all consumers of this method are prepared to handle unformatted data when NEW_MESSAGE is false, as this may affect downstream processing.


const messageId = messageSent.message?.protocolMessage?.key?.id;
if (messageId) {
if (messageId && this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (bug_risk): Message update logic is now gated by NEW_MESSAGE flag.

Consider whether message updates should ever occur when NEW_MESSAGE is false, as this change will prevent all such updates.

@onerrogus
Copy link
Copy Markdown
Contributor Author

onerrogus commented Aug 4, 2025

@DavidsonGomes DavidsonGomes merged commit 03a44cf into EvolutionAPI:develop Aug 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants