test(actions): table-drive telegram and signal mappings

This commit is contained in:
Peter Steinberger
2026-02-21 23:19:55 +00:00
parent 884c6afc26
commit 01ec832f78

View File

@@ -34,6 +34,51 @@ function telegramCfg(): OpenClawConfig {
return { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig; return { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
} }
type TelegramActionInput = Parameters<NonNullable<typeof telegramMessageActions.handleAction>>[0];
async function runTelegramAction(
action: TelegramActionInput["action"],
params: TelegramActionInput["params"],
options?: { cfg?: OpenClawConfig; accountId?: string },
) {
const cfg = options?.cfg ?? telegramCfg();
const handleAction = telegramMessageActions.handleAction;
if (!handleAction) {
throw new Error("telegram handleAction unavailable");
}
await handleAction({
channel: "telegram",
action,
params,
cfg,
accountId: options?.accountId,
});
return { cfg };
}
type SignalActionInput = Parameters<NonNullable<typeof signalMessageActions.handleAction>>[0];
async function runSignalAction(
action: SignalActionInput["action"],
params: SignalActionInput["params"],
options?: { cfg?: OpenClawConfig; accountId?: string },
) {
const cfg =
options?.cfg ?? ({ channels: { signal: { account: "+15550001111" } } } as OpenClawConfig);
const handleAction = signalMessageActions.handleAction;
if (!handleAction) {
throw new Error("signal handleAction unavailable");
}
await handleAction({
channel: "signal",
action,
params,
cfg,
accountId: options?.accountId,
});
return { cfg };
}
function slackHarness() { function slackHarness() {
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig; const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
const actions = createSlackActions("slack"); const actions = createSlackActions("slack");
@@ -398,77 +443,49 @@ describe("telegramMessageActions", () => {
} }
}); });
it("allows media-only sends and passes asVoice", async () => { it("maps action params into telegram actions", async () => {
const cfg = telegramCfg(); const cases = [
{
await telegramMessageActions.handleAction?.({ name: "media-only send preserves asVoice",
channel: "telegram", action: "send" as const,
action: "send",
params: { params: {
to: "123", to: "123",
media: "https://example.com/voice.ogg", media: "https://example.com/voice.ogg",
asVoice: true, asVoice: true,
}, },
cfg, expectedPayload: expect.objectContaining({
accountId: undefined,
});
expect(handleTelegramAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "sendMessage", action: "sendMessage",
to: "123", to: "123",
content: "", content: "",
mediaUrl: "https://example.com/voice.ogg", mediaUrl: "https://example.com/voice.ogg",
asVoice: true, asVoice: true,
}), }),
cfg, },
); {
}); name: "silent send forwards silent flag",
action: "send" as const,
it("passes silent flag for silent sends", async () => {
const cfg = telegramCfg();
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "send",
params: { params: {
to: "456", to: "456",
message: "Silent notification test", message: "Silent notification test",
silent: true, silent: true,
}, },
cfg, expectedPayload: expect.objectContaining({
accountId: undefined,
});
expect(handleTelegramAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "sendMessage", action: "sendMessage",
to: "456", to: "456",
content: "Silent notification test", content: "Silent notification test",
silent: true, silent: true,
}), }),
cfg, },
); {
}); name: "edit maps to editMessage",
action: "edit" as const,
it("maps edit action params into editMessage", async () => {
const cfg = telegramCfg();
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "edit",
params: { params: {
chatId: "123", chatId: "123",
messageId: 42, messageId: 42,
message: "Updated", message: "Updated",
buttons: [], buttons: [],
}, },
cfg, expectedPayload: {
accountId: undefined,
});
expect(handleTelegramAction).toHaveBeenCalledWith(
{
action: "editMessage", action: "editMessage",
chatId: "123", chatId: "123",
messageId: 42, messageId: 42,
@@ -476,8 +493,33 @@ describe("telegramMessageActions", () => {
buttons: [], buttons: [],
accountId: undefined, accountId: undefined,
}, },
},
{
name: "topic-create maps to createForumTopic",
action: "topic-create" as const,
params: {
to: "telegram:group:-1001234567890:topic:271",
name: "Build Updates",
},
expectedPayload: {
action: "createForumTopic",
chatId: "telegram:group:-1001234567890:topic:271",
name: "Build Updates",
iconColor: undefined,
iconCustomEmojiId: undefined,
accountId: undefined,
},
},
] as const;
for (const testCase of cases) {
handleTelegramAction.mockClear();
const { cfg } = await runTelegramAction(testCase.action, testCase.params);
expect(handleTelegramAction, testCase.name).toHaveBeenCalledWith(
testCase.expectedPayload,
cfg, cfg,
); );
}
}); });
it("rejects non-integer messageId for edit before reaching telegram-actions", async () => { it("rejects non-integer messageId for edit before reaching telegram-actions", async () => {
@@ -548,33 +590,6 @@ describe("telegramMessageActions", () => {
expect(String(callPayload.messageId)).toBe("456"); expect(String(callPayload.messageId)).toBe("456");
expect(callPayload.emoji).toBe("ok"); expect(callPayload.emoji).toBe("ok");
}); });
it("maps topic-create params into createForumTopic", async () => {
const cfg = telegramCfg();
await telegramMessageActions.handleAction?.({
channel: "telegram",
action: "topic-create",
params: {
to: "telegram:group:-1001234567890:topic:271",
name: "Build Updates",
},
cfg,
accountId: undefined,
});
expect(handleTelegramAction).toHaveBeenCalledWith(
{
action: "createForumTopic",
chatId: "telegram:group:-1001234567890:topic:271",
name: "Build Updates",
iconColor: undefined,
iconCustomEmojiId: undefined,
accountId: undefined,
},
cfg,
);
});
}); });
describe("signalMessageActions", () => { describe("signalMessageActions", () => {
@@ -641,8 +656,11 @@ describe("signalMessageActions", () => {
).rejects.toThrow(/actions\.reactions/); ).rejects.toThrow(/actions\.reactions/);
}); });
it("uses account-level actions when enabled", async () => { it("maps reaction targets into signal sendReaction calls", async () => {
const cfg = { const cases = [
{
name: "uses account-level actions when enabled",
cfg: {
channels: { channels: {
signal: { signal: {
actions: { reactions: false }, actions: { reactions: false },
@@ -651,44 +669,54 @@ describe("signalMessageActions", () => {
}, },
}, },
}, },
} as OpenClawConfig; } as OpenClawConfig,
accountId: "work",
await signalMessageActions.handleAction?.({
channel: "signal",
action: "react",
params: { to: "+15550001111", messageId: "123", emoji: "👍" }, params: { to: "+15550001111", messageId: "123", emoji: "👍" },
cfg, expectedArgs: ["+15550001111", 123, "👍", { accountId: "work" }],
accountId: "work", },
}); {
name: "normalizes uuid recipients",
expect(sendReactionSignal).toHaveBeenCalledWith("+15550001111", 123, "👍", { cfg: { channels: { signal: { account: "+15550001111" } } } as OpenClawConfig,
accountId: "work", accountId: undefined,
});
});
it("normalizes uuid recipients", async () => {
const cfg = {
channels: { signal: { account: "+15550001111" } },
} as OpenClawConfig;
await signalMessageActions.handleAction?.({
channel: "signal",
action: "react",
params: { params: {
recipient: "uuid:123e4567-e89b-12d3-a456-426614174000", recipient: "uuid:123e4567-e89b-12d3-a456-426614174000",
messageId: "123", messageId: "123",
emoji: "🔥", emoji: "🔥",
}, },
cfg, expectedArgs: ["123e4567-e89b-12d3-a456-426614174000", 123, "🔥", { accountId: undefined }],
},
{
name: "passes groupId and targetAuthor for group reactions",
cfg: { channels: { signal: { account: "+15550001111" } } } as OpenClawConfig,
accountId: undefined, accountId: undefined,
}); params: {
to: "signal:group:group-id",
expect(sendReactionSignal).toHaveBeenCalledWith( targetAuthor: "uuid:123e4567-e89b-12d3-a456-426614174000",
"123e4567-e89b-12d3-a456-426614174000", messageId: "123",
emoji: "✅",
},
expectedArgs: [
"",
123, 123,
"🔥", "",
{ accountId: undefined }, {
); accountId: undefined,
groupId: "group-id",
targetAuthor: "uuid:123e4567-e89b-12d3-a456-426614174000",
targetAuthorUuid: undefined,
},
],
},
] as const;
for (const testCase of cases) {
sendReactionSignal.mockClear();
await runSignalAction("react", testCase.params, {
cfg: testCase.cfg,
accountId: testCase.accountId,
});
expect(sendReactionSignal, testCase.name).toHaveBeenCalledWith(...testCase.expectedArgs);
}
}); });
it("requires targetAuthor for group reactions", async () => { it("requires targetAuthor for group reactions", async () => {
@@ -710,32 +738,6 @@ describe("signalMessageActions", () => {
}), }),
).rejects.toThrow(/targetAuthor/); ).rejects.toThrow(/targetAuthor/);
}); });
it("passes groupId and targetAuthor for group reactions", async () => {
const cfg = {
channels: { signal: { account: "+15550001111" } },
} as OpenClawConfig;
await signalMessageActions.handleAction?.({
channel: "signal",
action: "react",
params: {
to: "signal:group:group-id",
targetAuthor: "uuid:123e4567-e89b-12d3-a456-426614174000",
messageId: "123",
emoji: "✅",
},
cfg,
accountId: undefined,
});
expect(sendReactionSignal).toHaveBeenCalledWith("", 123, "✅", {
accountId: undefined,
groupId: "group-id",
targetAuthor: "uuid:123e4567-e89b-12d3-a456-426614174000",
targetAuthorUuid: undefined,
});
});
}); });
describe("slack actions adapter", () => { describe("slack actions adapter", () => {