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 commit is contained in:
@@ -6,6 +6,7 @@ export type ActiveWebSendOptions = {
|
||||
gifPlayback?: boolean;
|
||||
accountId?: string;
|
||||
fileName?: string;
|
||||
linkPreview?: boolean;
|
||||
};
|
||||
|
||||
export type ActiveWebListener = {
|
||||
|
||||
@@ -366,7 +366,7 @@ export async function monitorWebInbox(options: {
|
||||
|
||||
const sendApi = createWebSendApi({
|
||||
sock: {
|
||||
sendMessage: (jid: string, content: AnyMessageContent) => sock.sendMessage(jid, content),
|
||||
sendMessage: (jid, content, options) => sock.sendMessage(jid, content, options),
|
||||
sendPresenceUpdate: (presence, jid?: string) => sock.sendPresenceUpdate(presence, jid),
|
||||
},
|
||||
defaultAccountId: options.accountId,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AnyMessageContent, WAPresence } from "@whiskeysockets/baileys";
|
||||
import type { AnyMessageContent, MiscMessageGenerationOptions, WAPresence } from "@whiskeysockets/baileys";
|
||||
import type { ActiveWebSendOptions } from "../active-listener.js";
|
||||
import { recordChannelActivity } from "../../infra/channel-activity.js";
|
||||
import { toWhatsappJid } from "../../utils.js";
|
||||
@@ -19,7 +19,11 @@ function resolveOutboundMessageId(result: unknown): string {
|
||||
|
||||
export function createWebSendApi(params: {
|
||||
sock: {
|
||||
sendMessage: (jid: string, content: AnyMessageContent) => Promise<unknown>;
|
||||
sendMessage: (
|
||||
jid: string,
|
||||
content: AnyMessageContent,
|
||||
options?: MiscMessageGenerationOptions,
|
||||
) => Promise<unknown>;
|
||||
sendPresenceUpdate: (presence: WAPresence, jid?: string) => Promise<unknown>;
|
||||
};
|
||||
defaultAccountId: string;
|
||||
@@ -63,7 +67,10 @@ export function createWebSendApi(params: {
|
||||
} else {
|
||||
payload = { text };
|
||||
}
|
||||
const result = await params.sock.sendMessage(jid, payload);
|
||||
const miscOptions: MiscMessageGenerationOptions = {
|
||||
linkPreview: sendOptions?.linkPreview === false ? null : undefined,
|
||||
};
|
||||
const result = await params.sock.sendMessage(jid, payload, miscOptions);
|
||||
const accountId = sendOptions?.accountId ?? params.defaultAccountId;
|
||||
recordWhatsAppOutbound(accountId);
|
||||
const messageId = resolveOutboundMessageId(result);
|
||||
|
||||
@@ -21,6 +21,7 @@ export async function sendMessageWhatsApp(
|
||||
mediaLocalRoots?: readonly string[];
|
||||
gifPlayback?: boolean;
|
||||
accountId?: string;
|
||||
linkPreview?: boolean;
|
||||
},
|
||||
): Promise<{ messageId: string; toJid: string }> {
|
||||
let text = body;
|
||||
@@ -75,10 +76,16 @@ export async function sendMessageWhatsApp(
|
||||
const hasExplicitAccountId = Boolean(options.accountId?.trim());
|
||||
const accountId = hasExplicitAccountId ? resolvedAccountId : undefined;
|
||||
const sendOptions: ActiveWebSendOptions | undefined =
|
||||
options.gifPlayback || accountId || documentFileName
|
||||
options.gifPlayback ||
|
||||
options.accountId ||
|
||||
options.linkPreview !== undefined ||
|
||||
documentFileName
|
||||
? {
|
||||
...(options.gifPlayback ? { gifPlayback: true } : {}),
|
||||
...(documentFileName ? { fileName: documentFileName } : {}),
|
||||
...(options.linkPreview !== undefined
|
||||
? { linkPreview: options.linkPreview }
|
||||
: {}),
|
||||
accountId,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
Reference in New Issue
Block a user