Skip to content

Conversation

@dersonbsb2022
Copy link
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
Contributor

sourcery-ai bot commented Sep 4, 2025

Reviewer's Guide

This 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

Change Details Files
Introduce dynamic linkPreview support
  • Extract linkPreview boolean from webhook response
  • Pass linkPreview into the textMessage payload
  • Default to existing behavior if linkPreview is undefined
src/api/integrations/chatbot/evolutionBot/services/evolutionBot.service.ts
Replace sendMessageWhatsApp with textMessage call
  • Remove base class sendMessageWhatsApp invocation
  • Invoke instance.textMessage with number, delay, text, and linkPreview
  • Split remoteJid to derive the phone number
src/api/integrations/chatbot/evolutionBot/services/evolutionBot.service.ts
Add comprehensive debug logging
  • Log endpoint, payload, and headers before HTTP call
  • Log response status and data after HTTP call
  • Log raw message, linkPreview setting, cleaned message, and final send outcome
  • Warn if no message content is returned
src/api/integrations/chatbot/evolutionBot/services/evolutionBot.service.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
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

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
const linkPreview = response?.data?.linkPreview; // Extract linkPreview from n8n response
const linkPreview = response?.data?.linkPreview; // Extract linkPreview from webhook response

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.

2 participants