Fix Telegram poll action wiring

This commit is contained in:
Krish
2026-02-16 19:54:49 +05:30
committed by Peter Steinberger
parent afd354c482
commit 556b531a14
5 changed files with 168 additions and 0 deletions

View File

@@ -128,6 +128,42 @@ describe("discord message actions", () => {
});
});
describe("telegram message actions", () => {
it("lists poll action when telegram is configured", () => {
const cfg = { channels: { telegram: { botToken: "t0" } } } as OpenClawConfig;
const actions = telegramMessageActions.listActions?.({ cfg }) ?? [];
expect(actions).toContain("poll");
});
it("routes poll with normalized params", async () => {
await telegramMessageActions.handleAction({
action: "poll",
params: {
to: "123",
pollQuestion: "Ready?",
pollOption: ["Yes", "No"],
pollMulti: true,
pollDurationSeconds: 60,
},
cfg: { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig,
accountId: "ops",
});
expect(handleTelegramAction).toHaveBeenCalledWith(
expect.objectContaining({
action: "poll",
to: "123",
question: "Ready?",
options: ["Yes", "No"],
allowMultiselect: true,
durationSeconds: 60,
accountId: "ops",
}),
expect.any(Object),
);
});
});
describe("handleDiscordMessageAction", () => {
it("forwards context accountId for send", async () => {
await handleDiscordMessageAction({

View File

@@ -58,6 +58,9 @@ export const telegramMessageActions: ChannelMessageActionAdapter = {
if (gate("deleteMessage")) {
actions.add("delete");
}
if (gate("polls")) {
actions.add("poll");
}
if (gate("editMessage")) {
actions.add("edit");
}
@@ -116,6 +119,40 @@ export const telegramMessageActions: ChannelMessageActionAdapter = {
);
}
if (action === "poll") {
const to = readStringParam(params, "to", { required: true });
const question = readStringParam(params, "pollQuestion", { required: true });
const options = readStringArrayParam(params, "pollOption", { required: true }) ?? [];
const allowMultiselect = typeof params.pollMulti === "boolean" ? params.pollMulti : undefined;
const durationSeconds = readNumberParam(params, "pollDurationSeconds", {
integer: true,
});
const durationHours = readNumberParam(params, "pollDurationHours", {
integer: true,
});
const replyToMessageId = readNumberParam(params, "replyTo", { integer: true });
const messageThreadId = readNumberParam(params, "threadId", { integer: true });
const silent = typeof params.silent === "boolean" ? params.silent : undefined;
const isAnonymous = typeof params.isAnonymous === "boolean" ? params.isAnonymous : undefined;
return await handleTelegramAction(
{
action: "poll",
to,
question,
options,
allowMultiselect,
durationSeconds: durationSeconds ?? undefined,
durationHours: durationHours ?? undefined,
replyToMessageId: replyToMessageId ?? undefined,
messageThreadId: messageThreadId ?? undefined,
silent,
isAnonymous,
accountId: accountId ?? undefined,
},
cfg,
);
}
if (action === "delete") {
const chatId =
readStringOrNumberParam(params, "chatId") ??