Revert "fix(whatsapp): allow per-message link preview override\n\nWhatsApp messages default to enabling link previews for URLs. This adds\nsupport for overriding this behavior per-message via the \nparameter (e.g. from tool options), consistent with Telegram.\n\nFix: Updated internal WhatsApp Web API layers to pass option\ndown to Baileys ."

This reverts commit 1bef2fc68b.
This commit is contained in:
Sebastian
2026-02-16 22:59:37 -05:00
parent 67014228cf
commit 65fa529e03
6 changed files with 9 additions and 97 deletions

View File

@@ -1,12 +1,11 @@
import { formatCliCommand } from "../cli/command-format.js";
import type { PollInput } from "../polls.js";
import { formatCliCommand } from "../cli/command-format.js";
import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js";
export type ActiveWebSendOptions = {
gifPlayback?: boolean;
accountId?: string;
fileName?: string;
linkPreview?: boolean;
};
export type ActiveWebListener = {

View File

@@ -1,5 +1,6 @@
import type { AnyMessageContent, proto, WAMessage } from "@whiskeysockets/baileys";
import { DisconnectReason, isJidGroup } from "@whiskeysockets/baileys";
import type { WebInboundMessage, WebListenerCloseReason } from "./types.js";
import { createInboundDebouncer } from "../../auto-reply/inbound-debounce.js";
import { formatLocationText } from "../../channels/location.js";
import { logVerbose, shouldLogVerbose } from "../../globals.js";
@@ -20,7 +21,6 @@ import {
} from "./extract.js";
import { downloadInboundMedia } from "./media.js";
import { createWebSendApi } from "./send-api.js";
import type { WebInboundMessage, WebListenerCloseReason } from "./types.js";
export async function monitorWebInbox(options: {
verbose: boolean;
@@ -366,10 +366,7 @@ export async function monitorWebInbox(options: {
const sendApi = createWebSendApi({
sock: {
sendMessage: (jid, content, options) =>
options === undefined
? sock.sendMessage(jid, content)
: sock.sendMessage(jid, content, options),
sendMessage: (jid: string, content: AnyMessageContent) => sock.sendMessage(jid, content),
sendPresenceUpdate: (presence, jid?: string) => sock.sendPresenceUpdate(presence, jid),
},
defaultAccountId: options.accountId,

View File

@@ -1,11 +1,7 @@
import type {
AnyMessageContent,
MiscMessageGenerationOptions,
WAPresence,
} from "@whiskeysockets/baileys";
import type { AnyMessageContent, WAPresence } from "@whiskeysockets/baileys";
import type { ActiveWebSendOptions } from "../active-listener.js";
import { recordChannelActivity } from "../../infra/channel-activity.js";
import { toWhatsappJid } from "../../utils.js";
import type { ActiveWebSendOptions } from "../active-listener.js";
function recordWhatsAppOutbound(accountId: string) {
recordChannelActivity({
@@ -23,11 +19,7 @@ function resolveOutboundMessageId(result: unknown): string {
export function createWebSendApi(params: {
sock: {
sendMessage: (
jid: string,
content: AnyMessageContent,
options?: MiscMessageGenerationOptions,
) => Promise<unknown>;
sendMessage: (jid: string, content: AnyMessageContent) => Promise<unknown>;
sendPresenceUpdate: (presence: WAPresence, jid?: string) => Promise<unknown>;
};
defaultAccountId: string;
@@ -71,14 +63,7 @@ export function createWebSendApi(params: {
} else {
payload = { text };
}
let result;
if (sendOptions?.linkPreview === false) {
// Baileys types have changed across releases; keep backward-compatible runtime behavior.
const miscOptions = { linkPreview: null } as unknown as MiscMessageGenerationOptions;
result = await params.sock.sendMessage(jid, payload, miscOptions);
} else {
result = await params.sock.sendMessage(jid, payload);
}
const result = await params.sock.sendMessage(jid, payload);
const accountId = sendOptions?.accountId ?? params.defaultAccountId;
recordWhatsAppOutbound(accountId);
const messageId = resolveOutboundMessageId(result);

View File

@@ -21,7 +21,6 @@ export async function sendMessageWhatsApp(
mediaLocalRoots?: readonly string[];
gifPlayback?: boolean;
accountId?: string;
linkPreview?: boolean;
},
): Promise<{ messageId: string; toJid: string }> {
let text = body;
@@ -76,14 +75,10 @@ export async function sendMessageWhatsApp(
const hasExplicitAccountId = Boolean(options.accountId?.trim());
const accountId = hasExplicitAccountId ? resolvedAccountId : undefined;
const sendOptions: ActiveWebSendOptions | undefined =
options.gifPlayback ||
options.accountId ||
options.linkPreview !== undefined ||
documentFileName
options.gifPlayback || accountId || documentFileName
? {
...(options.gifPlayback ? { gifPlayback: true } : {}),
...(documentFileName ? { fileName: documentFileName } : {}),
...(options.linkPreview !== undefined ? { linkPreview: options.linkPreview } : {}),
accountId,
}
: undefined;