-
Notifications
You must be signed in to change notification settings - Fork 5.1k
feat: implement disable/enable linkPreview support for Evolution Bot #1908
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
Conversation
- 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
Reviewer's GuideThis PR enriches the Evolution Bot integration by extracting and honoring a linkPreview flag from webhook responses, replacing the legacy sendMessageWhatsApp call with a direct textMessage invocation that includes link preview control, and adding extensive debug logging while preserving backward compatibility. File-Level Changes
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 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
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
linkPreviewparameter from webhook responses - Replaces the base class
sendMessageWhatsAppmethod with directtextMessagecalls 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 |
Copilot
AI
Sep 4, 2025
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.
The property assignment uses redundant syntax. Use shorthand property notation: linkPreview, instead of linkPreview: linkPreview,
| linkPreview: linkPreview, // Use linkPreview from n8n response | |
| linkPreview, // Use linkPreview from n8n response |
| } | ||
|
|
||
| let message = response?.data?.message; | ||
| const linkPreview = response?.data?.linkPreview; // Extract linkPreview from n8n response |
Copilot
AI
Sep 4, 2025
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.
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
| const linkPreview = response?.data?.linkPreview; // Extract linkPreview from n8n response | |
| const linkPreview = response?.data?.linkPreview; // Extract linkPreview from webhook response |
- 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
📋 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
linkPreview: falseto disable link previews{ "message": "text", "linkPreview": boolean }response format🔧 Implementation Details
src/api/integrations/chatbot/evolutionBot/services/evolutionBot.service.tslinkPreviewfrom webhook response and pass totextMessagelinkPreview: falsefrom 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