feat: implement disable/enable linkPreview support for Evolution Bot by dersonbsb2022 · Pull Request #1908 · EvolutionAPI/evolution-api · GitHub
Skip to content

feat: implement disable/enable linkPreview support for Evolution Bot #1908

Merged
DavidsonGomes merged 6 commits intoEvolutionAPI:developfrom
dersonbsb2022:main
Sep 9, 2025
Merged

feat: implement disable/enable linkPreview support for Evolution Bot #1908
DavidsonGomes merged 6 commits intoEvolutionAPI:developfrom
dersonbsb2022:main

Conversation

@dersonbsb2022
Copy link
Copy Markdown
Contributor

@dersonbsb2022 dersonbsb2022 commented Sep 4, 2025

📋 Summary

This PR implements linkPreview support for Evolution Bot integration, allowing webhooks/n8n workflows to control whether link previews are displayed in WhatsApp messages.

✨ What's New

  • Dynamic LinkPreview Control: Webhooks can now return linkPreview: false to disable link previews
  • Flexible Response Format: Support for { "message": "text", "linkPreview": boolean } response format
  • Debug Logging: Added comprehensive debug logs for linkPreview functionality
  • Backward Compatible: Existing implementations continue to work without changes

🔧 Implementation Details

  • File Modified: src/api/integrations/chatbot/evolutionBot/services/evolutionBot.service.ts
  • Feature: Extract linkPreview from webhook response and pass to textMessage
  • Usage: Return linkPreview: false from webhook to disable link previews in WhatsApp

📖 Usage Example

Webhook Response:

{
  "message": "Check this link: https://example.com",
  "linkPreview": false
}

## Summary by Sourcery

Implement link preview support in the Evolution Bot integration to allow webhooks or n8n workflows to dynamically enable or disable link previews in WhatsApp messages, while adding comprehensive debug logging and maintaining backward compatibility.

New Features:
- Allow webhook responses to include a linkPreview flag to control whether link previews are displayed in WhatsApp messages

Enhancements:
- Add detailed debug logs around HTTP requests, responses, message cleanup, and message sending
- Refactor message dispatch to use textMessage with the linkPreview option instead of the base sendMessageWhatsApp method

DavidsonGomes and others added 4 commits September 2, 2025 10:53
- Add linkPreview extraction from webhook/n8n response
- Implement linkPreview parameter in textMessage calls
- Add debug logging for linkPreview functionality
- Support for disabling link previews when linkPreview: false
- Add comprehensive documentation for linkPreview feature

Usage:
- Return { "message": "text", "linkPreview": false } from webhook to disable preview
- Return { "message": "text", "linkPreview": true } from webhook to enable preview
- Omit linkPreview for default WhatsApp behavior
- Remove evolution-bot-documentation.md
- Remove evolution-bot-linkpreview-example.md
- Remove send-text-api-documentation.md
- Keep only the core linkPreview implementation
Copilot AI review requested due to automatic review settings September 4, 2025 15:10
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Sep 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 there - I've reviewed your changes - here's some feedback:

  • Consider defaulting linkPreview to true when the webhook doesn’t specify it so you don’t pass undefined to textMessage and preserve backward compatibility.
  • The large number of debug logs can clutter output and may expose sensitive data—consider consolidating related logs into structured entries and sanitizing payloads before logging.
  • Validate that linkPreview is actually a boolean before passing it to textMessage, and fall back to a safe default if it isn’t.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider defaulting linkPreview to true when the webhook doesn’t specify it so you don’t pass undefined to textMessage and preserve backward compatibility.
- The large number of debug logs can clutter output and may expose sensitive data—consider consolidating related logs into structured entries and sanitizing payloads before logging.
- Validate that linkPreview is actually a boolean before passing it to textMessage, and fall back to a safe default if it isn’t.

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.

@dersonbsb2022 dersonbsb2022 changed the title feat: implement linkPreview support for Evolution Bot feat: implement disable/enable linkPreview support for Evolution Bot Sep 4, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements link preview control functionality for Evolution Bot webhooks, allowing dynamic control over whether link previews are displayed in WhatsApp messages through webhook responses.

  • Adds extraction of linkPreview parameter from webhook responses
  • Replaces the base class sendMessageWhatsApp method with direct textMessage calls to support linkPreview
  • Introduces comprehensive debug logging for webhook requests and responses

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
text: message,
linkPreview: linkPreview, // Use linkPreview from n8n response
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The property assignment uses redundant syntax. Use shorthand property notation: linkPreview, instead of linkPreview: linkPreview,

Suggested change
linkPreview: linkPreview, // Use linkPreview from n8n response
linkPreview, // Use linkPreview from n8n response

Copilot uses AI. Check for mistakes.
}

let message = response?.data?.message;
const linkPreview = response?.data?.linkPreview; // Extract linkPreview from n8n response
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The comment incorrectly refers to 'n8n response' but this is a generic webhook response that could come from any webhook endpoint, not specifically n8n. Update the comment to be more generic: // Extract linkPreview from webhook response

Suggested change

Copilot uses AI. Check for mistakes.
- Default linkPreview to true when not specified for backward compatibility
- Validate linkPreview is boolean before passing to textMessage
- Consolidate debug logs and remove sensitive data from logging
- Sanitize API keys in debug output ([REDACTED])
- Reduce log verbosity while maintaining debugging capability
- Ensure robust fallback behavior for malformed responses

Addresses PR feedback regarding:
- Backward compatibility preservation
- Security considerations in logging
- Input validation and error handling
- Remove unnecessary trailing whitespace
- Use shorthand property syntax for linkPreview parameter
- Apply ESLint formatting standards
- Maintain code consistency and readability
@DavidsonGomes DavidsonGomes merged commit d6a76a0 into EvolutionAPI:develop Sep 9, 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.

3 participants