refactor(telegram): unify action normalization

This commit is contained in:
Ayaan Zaidi
2026-03-18 09:14:50 +05:30
parent 4c9028439c
commit a89cb3e10e
5 changed files with 312 additions and 393 deletions

View File

@@ -236,6 +236,31 @@ describe("handleTelegramAction", () => {
);
});
it("accepts shared sticker action aliases", async () => {
const cfg = {
channels: { telegram: { botToken: "tok", actions: { sticker: true } } },
} as OpenClawConfig;
await handleTelegramAction(
{
action: "sticker",
target: "123",
stickerId: ["sticker"],
replyTo: 9,
threadId: 11,
},
cfg,
);
expect(sendStickerTelegram).toHaveBeenCalledWith(
"123",
"sticker",
expect.objectContaining({
token: "tok",
replyToMessageId: 9,
messageThreadId: 11,
}),
);
});
it("removes reactions when remove flag set", async () => {
const cfg = reactionConfig("extensive");
await handleTelegramAction(
@@ -320,6 +345,26 @@ describe("handleTelegramAction", () => {
});
});
it("accepts shared send action aliases", async () => {
await handleTelegramAction(
{
action: "send",
to: "@testchannel",
message: "Hello from alias",
media: "https://example.com/image.jpg",
},
telegramConfig(),
);
expect(sendMessageTelegram).toHaveBeenCalledWith(
"@testchannel",
"Hello from alias",
expect.objectContaining({
token: "tok",
mediaUrl: "https://example.com/image.jpg",
}),
);
});
it("sends a poll", async () => {
const result = await handleTelegramAction(
{
@@ -357,6 +402,41 @@ describe("handleTelegramAction", () => {
});
});
it("accepts shared poll action aliases", async () => {
await handleTelegramAction(
{
action: "poll",
to: "@testchannel",
pollQuestion: "Ready?",
pollOption: ["Yes", "No"],
pollMulti: "true",
pollPublic: "true",
pollDurationSeconds: 60,
replyTo: 55,
threadId: 77,
silent: "true",
},
telegramConfig(),
);
expect(sendPollTelegram).toHaveBeenCalledWith(
"@testchannel",
{
question: "Ready?",
options: ["Yes", "No"],
maxSelections: 2,
durationSeconds: 60,
durationHours: undefined,
},
expect.objectContaining({
token: "tok",
isAnonymous: false,
replyToMessageId: 55,
messageThreadId: 77,
silent: true,
}),
);
});
it("parses string booleans for poll flags", async () => {
await handleTelegramAction(
{