fix(outbound): unify resolved cfg threading across send paths (#33987)

This commit is contained in:
Josh Avant
2026-03-04 00:20:44 -06:00
committed by GitHub
parent 4d183af0cf
commit 646817dd80
62 changed files with 1780 additions and 117 deletions

View File

@@ -0,0 +1,46 @@
import type { OpenClawConfig } from "openclaw/plugin-sdk";
import { describe, expect, it, vi } from "vitest";
const hoisted = vi.hoisted(() => ({
sendPollWhatsApp: vi.fn(async () => ({ messageId: "wa-poll-1", toJid: "1555@s.whatsapp.net" })),
}));
vi.mock("./runtime.js", () => ({
getWhatsAppRuntime: () => ({
logging: {
shouldLogVerbose: () => false,
},
channel: {
whatsapp: {
sendPollWhatsApp: hoisted.sendPollWhatsApp,
},
},
}),
}));
import { whatsappPlugin } from "./channel.js";
describe("whatsappPlugin outbound sendPoll", () => {
it("threads cfg into runtime sendPollWhatsApp call", async () => {
const cfg = { marker: "resolved-cfg" } as OpenClawConfig;
const poll = {
question: "Lunch?",
options: ["Pizza", "Sushi"],
maxSelections: 1,
};
const result = await whatsappPlugin.outbound!.sendPoll!({
cfg,
to: "+1555",
poll,
accountId: "work",
});
expect(hoisted.sendPollWhatsApp).toHaveBeenCalledWith("+1555", poll, {
verbose: false,
accountId: "work",
cfg,
});
expect(result).toEqual({ messageId: "wa-poll-1", toJid: "1555@s.whatsapp.net" });
});
});

View File

@@ -286,19 +286,30 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> = {
pollMaxOptions: 12,
resolveTarget: ({ to, allowFrom, mode }) =>
resolveWhatsAppOutboundTarget({ to, allowFrom, mode }),
sendText: async ({ to, text, accountId, deps, gifPlayback }) => {
sendText: async ({ cfg, to, text, accountId, deps, gifPlayback }) => {
const send = deps?.sendWhatsApp ?? getWhatsAppRuntime().channel.whatsapp.sendMessageWhatsApp;
const result = await send(to, text, {
verbose: false,
cfg,
accountId: accountId ?? undefined,
gifPlayback,
});
return { channel: "whatsapp", ...result };
},
sendMedia: async ({ to, text, mediaUrl, mediaLocalRoots, accountId, deps, gifPlayback }) => {
sendMedia: async ({
cfg,
to,
text,
mediaUrl,
mediaLocalRoots,
accountId,
deps,
gifPlayback,
}) => {
const send = deps?.sendWhatsApp ?? getWhatsAppRuntime().channel.whatsapp.sendMessageWhatsApp;
const result = await send(to, text, {
verbose: false,
cfg,
mediaUrl,
mediaLocalRoots,
accountId: accountId ?? undefined,
@@ -306,10 +317,11 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> = {
});
return { channel: "whatsapp", ...result };
},
sendPoll: async ({ to, poll, accountId }) =>
sendPoll: async ({ cfg, to, poll, accountId }) =>
await getWhatsAppRuntime().channel.whatsapp.sendPollWhatsApp(to, poll, {
verbose: getWhatsAppRuntime().logging.shouldLogVerbose(),
accountId: accountId ?? undefined,
cfg,
}),
},
auth: {