mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-21 16:41:56 +00:00
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:
56
extensions/whatsapp/src/channel.send-options.test.ts
Normal file
56
extensions/whatsapp/src/channel.send-options.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { whatsappPlugin } from "./channel.js";
|
||||
|
||||
// Mock runtime
|
||||
const mockSendMessageWhatsApp = vi.fn().mockResolvedValue({ messageId: "123", toJid: "123@s.whatsapp.net" });
|
||||
|
||||
vi.mock("./runtime.js", () => ({
|
||||
getWhatsAppRuntime: () => ({
|
||||
channel: {
|
||||
text: { chunkText: (t: string) => [t] },
|
||||
whatsapp: {
|
||||
sendMessageWhatsApp: mockSendMessageWhatsApp,
|
||||
createLoginTool: vi.fn(),
|
||||
},
|
||||
},
|
||||
logging: { shouldLogVerbose: () => false },
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("whatsappPlugin.outbound.sendText", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("passes linkPreview option to sendMessageWhatsApp", async () => {
|
||||
await whatsappPlugin.outbound.sendText({
|
||||
to: "1234567890",
|
||||
text: "http://example.com",
|
||||
// @ts-expect-error - injecting extra param as per runtime behavior
|
||||
linkPreview: false,
|
||||
});
|
||||
|
||||
expect(mockSendMessageWhatsApp).toHaveBeenCalledWith(
|
||||
"1234567890",
|
||||
"http://example.com",
|
||||
expect.objectContaining({
|
||||
linkPreview: false,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("passes linkPreview=undefined when omitted", async () => {
|
||||
await whatsappPlugin.outbound.sendText({
|
||||
to: "1234567890",
|
||||
text: "hello",
|
||||
});
|
||||
|
||||
expect(mockSendMessageWhatsApp).toHaveBeenCalledWith(
|
||||
"1234567890",
|
||||
"hello",
|
||||
expect.objectContaining({
|
||||
linkPreview: undefined,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -290,12 +290,15 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> = {
|
||||
pollMaxOptions: 12,
|
||||
resolveTarget: ({ to, allowFrom, mode }) =>
|
||||
resolveWhatsAppOutboundTarget({ to, allowFrom, mode }),
|
||||
sendText: async ({ to, text, accountId, deps, gifPlayback }) => {
|
||||
sendText: async (params) => {
|
||||
const { to, text, accountId, deps, gifPlayback } = params;
|
||||
const linkPreview = (params as { linkPreview?: boolean }).linkPreview;
|
||||
const send = deps?.sendWhatsApp ?? getWhatsAppRuntime().channel.whatsapp.sendMessageWhatsApp;
|
||||
const result = await send(to, text, {
|
||||
verbose: false,
|
||||
accountId: accountId ?? undefined,
|
||||
gifPlayback,
|
||||
linkPreview,
|
||||
});
|
||||
return { channel: "whatsapp", ...result };
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user