Skip to content

fix(whatsapp): only generate link preview when explicitly requested - #2803

Closed
MarToxAk wants to merge 1 commit into
evolution-foundation:developfrom
MarToxAk:fix/baileys-link-preview-default
Closed

MarToxAk wants to merge 1 commit into
evolution-foundation:developfrom
MarToxAk:fix/baileys-link-preview-default

Conversation

@MarToxAk

@MarToxAk MarToxAk commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2762.

On 2.4.0-rc2 (Baileys) the link preview is enabled by default: text messages whose content contains a URL end up going through preview generation, and — on this version — those messages fail to be delivered to the recipient.

What the bug looks like

  • POST /message/sendText/{instance} returns status: "PENDING" with no error, but the message with a link never arrives.
  • The same message sent with linkPreview: false arrives normally.
  • The resulting extendedTextMessage has no matchedText / title / description / thumbnail.
  • Callers that route through Chatwoot (or any integration that does not set linkPreview) have no way to disable the preview, so every message containing a link is affected.

Root cause

textMessage maps linkPreview to undefined unless the caller explicitly passes false:

const linkPreview = options?.linkPreview === false ? false : undefined;

undefined is then forwarded to Baileys (this.client.sendMessage(..., { linkPreview })). In Baileys' generateWAMessageContent (lib/Utils/messages.js), undefined is not "no preview" — it triggers automatic preview generation:

let urlInfo = message.linkPreview;
if (typeof urlInfo === 'undefined') {
  urlInfo = await generateLinkPreviewIfRequired(message.text, options.getUrlInfo, options.logger);
}

So the only value that actually disables the preview is false. Setting the default to undefined (the current behavior) is what keeps every URL message on the broken preview path.

How the fix works

The default is inverted to false: the preview is generated only when linkPreview: true is passed explicitly. When the field is omitted (the common case), false is forwarded to Baileys, which skips preview generation and delivers the message normally. Callers that want the preview can still request it with linkPreview: true.

// before
const linkPreview = options?.linkPreview === false ? false : undefined;
if (linkPreview !== false && (message as any)?.conversation) {
  previewContext = await this.generateLinkPreview((message as any).conversation);
}

// after
const linkPreview = options?.linkPreview === true ? true : false;
if (linkPreview === true && (message as any)?.conversation) {
  previewContext = await this.generateLinkPreview((message as any).conversation);
}

Testing

  • Two-line inversion of an existing boolean guard; the linkPreview: true path is unchanged.
  • Verified the equivalent change against the compiled 2.4.0-rc2 output (dist/api/integrations/channel/whatsapp/whatsapp.baileys.service.js): the minified default goes from ...===!1?!1:void 0... (undefined) to ...===!0?!0:!1... (false), so Baileys no longer auto-generates the preview for messages without an explicit linkPreview: true.

🤖 Generated with Claude Code

@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implementation

Make link preview generation conditional on an explicit linkPreview: true request so messages without the option skip preview generation.

  • src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts L2641-2644

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

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts" line_range="2641" />
<code_context>
       }

-      const linkPreview = options?.linkPreview === false ? false : undefined;
+      const linkPreview = options?.linkPreview === true ? true : undefined;

       let previewContext: any = undefined;
</code_context>
<issue_to_address>
**URL messages still generate previews**

When the caller omits `linkPreview` or passes `false` for a text message containing a URL, `linkPreview` becomes `undefined` and `sendMessage` forwards it to Baileys, whose default enables previews; URL messages still trigger preview generation and fail delivery, and explicit opt-outs are lost.

Set `linkPreview` to `false` unless the caller explicitly passes `true`, and forward that value to Baileys.

Also at `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:2642`.
</issue_to_address>

### Comment 2
<location path="src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts" line_range="2644" />
<code_context>

       let previewContext: any = undefined;
-      if (linkPreview !== false && (message as any)?.conversation) {
+      if (linkPreview === true && (message as any)?.conversation) {
         previewContext = await this.generateLinkPreview((message as any).conversation);
       }
</code_context>
<issue_to_address>
**Chatbot URL replies still fail**

When a chatbot integration sends a reply containing a URL, the chatbot adapters pass `linkPreview: true` for replies without an explicit preview request from the chatbot consumer, so `sendMessageWithTyping` still calls `generateLinkPreview()` and URL replies can remain undelivered.

Have chatbot integrations default to previews off and pass `true` only when their consumer explicitly opts in.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:2641, src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:2644


Sourcery is free for open source - if you like our reviews please consider sharing them ✨


let previewContext: any = undefined;
if (linkPreview !== false && (message as any)?.conversation) {
if (linkPreview === true && (message as any)?.conversation) {

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.

🟡 Medium · Chatbot URL replies still fail

When a chatbot integration sends a reply containing a URL, the chatbot adapters pass linkPreview: true for replies without an explicit preview request from the chatbot consumer, so sendMessageWithTyping still calls generateLinkPreview() and URL replies can remain undelivered.

Have chatbot integrations default to previews off and pass true only when their consumer explicitly opts in.

Prompt for AI agents
In `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts` at line 2644:

**Chatbot URL replies still fail**

When a chatbot integration sends a reply containing a URL, the chatbot adapters pass `linkPreview: true` for replies without an explicit preview request from the chatbot consumer, so `sendMessageWithTyping` still calls `generateLinkPreview()` and URL replies can remain undelivered.

Have chatbot integrations default to previews off and pass `true` only when their consumer explicitly opts in.

Link preview was enabled by default: it was only disabled when the
caller passed linkPreview:false explicitly. On 2.4.0-rc2 (Baileys),
the default path calls generateLinkPreview() for any message whose
text contains a URL, and those messages fail to be delivered to the
recipient (fixes evolution-foundation#2762).

Invert the default so the preview is generated only when
linkPreview:true is passed explicitly. Callers that still want the
preview can send linkPreview:true.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@MarToxAk
MarToxAk force-pushed the fix/baileys-link-preview-default branch from 873cf46 to 825b8da Compare November 23, 2026 16:40
@MarToxAk

Copy link
Copy Markdown
Author

Closing this. The actual cause of the delivery issue was the Baileys 7.0.0-rc.13 outbound bug (present in 2.4.0-rc2), which is fixed by moving to v2.3.8 / Baileys 7.0.0-rc.9 — not by the link preview default. This change (disabling preview by default) is a symptom workaround rather than a root-cause fix, so I'm withdrawing it.

@MarToxAk MarToxAk closed this Nov 23, 2026
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.

1 participant