From 33b59441d25f2e557a2b926669b48e89272987bd Mon Sep 17 00:00:00 2001 From: Nimrod Gutman Date: Tue, 17 Feb 2026 09:43:57 +0200 Subject: [PATCH] Revert "Fix Telegram poll action wiring" This reverts commit 556b531a140330540a10299cd6c4907750a2c0b6. --- src/agents/tools/message-tool.ts | 7 +-- src/agents/tools/telegram-actions.e2e.test.ts | 39 ++---------- src/agents/tools/telegram-actions.ts | 61 ------------------- src/channels/plugins/actions/actions.test.ts | 37 ----------- src/channels/plugins/actions/telegram.ts | 41 +------------ 5 files changed, 8 insertions(+), 177 deletions(-) diff --git a/src/agents/tools/message-tool.ts b/src/agents/tools/message-tool.ts index 4ddc6116bd..324c8aa48b 100644 --- a/src/agents/tools/message-tool.ts +++ b/src/agents/tools/message-tool.ts @@ -1,4 +1,6 @@ import { Type } from "@sinclair/typebox"; +import type { OpenClawConfig } from "../../config/config.js"; +import type { AnyAgentTool } from "./common.js"; import { BLUEBUBBLES_GROUP_ACTIONS } from "../../channels/plugins/bluebubbles-actions.js"; import { listChannelMessageActions, @@ -11,7 +13,6 @@ import { CHANNEL_MESSAGE_ACTION_NAMES, type ChannelMessageActionName, } from "../../channels/plugins/types.js"; -import type { OpenClawConfig } from "../../config/config.js"; import { loadConfig } from "../../config/config.js"; import { GATEWAY_CLIENT_IDS, GATEWAY_CLIENT_MODES } from "../../gateway/protocol/client-info.js"; import { getToolResult, runMessageAction } from "../../infra/outbound/message-action-runner.js"; @@ -22,7 +23,6 @@ import { normalizeMessageChannel } from "../../utils/message-channel.js"; import { resolveSessionAgentId } from "../agent-scope.js"; import { listChannelSupportedActions } from "../channel-tools.js"; import { channelTargetSchema, channelTargetsSchema, stringEnum } from "../schema/typebox.js"; -import type { AnyAgentTool } from "./common.js"; import { jsonResult, readNumberParam, readStringParam } from "./common.js"; import { resolveGatewayOptions } from "./gateway.js"; @@ -262,11 +262,8 @@ function buildPollSchema() { return { pollQuestion: Type.Optional(Type.String()), pollOption: Type.Optional(Type.Array(Type.String())), - pollDurationSeconds: Type.Optional(Type.Number()), pollDurationHours: Type.Optional(Type.Number()), pollMulti: Type.Optional(Type.Boolean()), - pollAnonymous: Type.Optional(Type.Boolean()), - pollPublic: Type.Optional(Type.Boolean()), }; } diff --git a/src/agents/tools/telegram-actions.e2e.test.ts b/src/agents/tools/telegram-actions.e2e.test.ts index a93b64c8d3..6a6777ac4a 100644 --- a/src/agents/tools/telegram-actions.e2e.test.ts +++ b/src/agents/tools/telegram-actions.e2e.test.ts @@ -11,20 +11,14 @@ const sendStickerTelegram = vi.fn(async () => ({ messageId: "456", chatId: "123", })); -const sendPollTelegram = vi.fn(async () => ({ - messageId: "999", - chatId: "123", - pollId: "poll-1", -})); const deleteMessageTelegram = vi.fn(async () => ({ ok: true })); const originalToken = process.env.TELEGRAM_BOT_TOKEN; vi.mock("../../telegram/send.js", () => ({ - reactMessageTelegram, - sendMessageTelegram, - sendStickerTelegram, - sendPollTelegram, - deleteMessageTelegram, + reactMessageTelegram: (...args: unknown[]) => reactMessageTelegram(...args), + sendMessageTelegram: (...args: unknown[]) => sendMessageTelegram(...args), + sendStickerTelegram: (...args: unknown[]) => sendStickerTelegram(...args), + deleteMessageTelegram: (...args: unknown[]) => deleteMessageTelegram(...args), })); describe("handleTelegramAction", () => { @@ -55,7 +49,6 @@ describe("handleTelegramAction", () => { reactMessageTelegram.mockClear(); sendMessageTelegram.mockClear(); sendStickerTelegram.mockClear(); - sendPollTelegram.mockClear(); deleteMessageTelegram.mockClear(); process.env.TELEGRAM_BOT_TOKEN = "tok"; }); @@ -369,30 +362,6 @@ describe("handleTelegramAction", () => { ); }); - it("sends a poll", async () => { - const cfg = { - channels: { telegram: { botToken: "tok" } }, - } as OpenClawConfig; - await handleTelegramAction( - { - action: "poll", - to: "123", - question: "Ready?", - options: ["Yes", "No"], - }, - cfg, - ); - expect(sendPollTelegram).toHaveBeenCalledWith( - "123", - expect.objectContaining({ - question: "Ready?", - options: ["Yes", "No"], - maxSelections: 1, - }), - expect.objectContaining({ token: "tok" }), - ); - }); - it("respects deleteMessage gating", async () => { const cfg = { channels: { diff --git a/src/agents/tools/telegram-actions.ts b/src/agents/tools/telegram-actions.ts index 6dd624f5d7..15b122dd59 100644 --- a/src/agents/tools/telegram-actions.ts +++ b/src/agents/tools/telegram-actions.ts @@ -12,7 +12,6 @@ import { editMessageTelegram, reactMessageTelegram, sendMessageTelegram, - sendPollTelegram, sendStickerTelegram, } from "../../telegram/send.js"; import { getCacheStats, searchStickers } from "../../telegram/sticker-cache.js"; @@ -212,66 +211,6 @@ export async function handleTelegramAction( }); } - if (action === "poll") { - if (!isActionEnabled("polls")) { - throw new Error("Telegram polls are disabled."); - } - const to = readStringParam(params, "to", { required: true }); - const question = readStringParam(params, "question", { required: true }); - const options = params.options ?? params.answers; - if (!Array.isArray(options)) { - throw new Error("options must be an array of strings"); - } - const pollOptions = options.filter((option): option is string => typeof option === "string"); - if (pollOptions.length !== options.length) { - throw new Error("options must be an array of strings"); - } - const durationSeconds = readNumberParam(params, "durationSeconds", { - integer: true, - }); - const durationHours = readNumberParam(params, "durationHours", { - integer: true, - }); - const replyToMessageId = readNumberParam(params, "replyToMessageId", { - integer: true, - }); - const messageThreadId = readNumberParam(params, "messageThreadId", { - integer: true, - }); - const maxSelections = - typeof params.allowMultiselect === "boolean" && params.allowMultiselect ? 2 : 1; - const token = resolveTelegramToken(cfg, { accountId }).token; - if (!token) { - throw new Error( - "Telegram bot token missing. Set TELEGRAM_BOT_TOKEN or channels.telegram.botToken.", - ); - } - const result = await sendPollTelegram( - to, - { - question, - options: pollOptions, - maxSelections, - durationSeconds: durationSeconds ?? undefined, - durationHours: durationHours ?? undefined, - }, - { - token, - accountId: accountId ?? undefined, - replyToMessageId: replyToMessageId ?? undefined, - messageThreadId: messageThreadId ?? undefined, - silent: typeof params.silent === "boolean" ? params.silent : undefined, - isAnonymous: typeof params.isAnonymous === "boolean" ? params.isAnonymous : undefined, - }, - ); - return jsonResult({ - ok: true, - messageId: result.messageId, - chatId: result.chatId, - pollId: result.pollId, - }); - } - if (action === "deleteMessage") { if (!isActionEnabled("deleteMessage")) { throw new Error("Telegram deleteMessage is disabled."); diff --git a/src/channels/plugins/actions/actions.test.ts b/src/channels/plugins/actions/actions.test.ts index 25726718e9..68aa5ed0ad 100644 --- a/src/channels/plugins/actions/actions.test.ts +++ b/src/channels/plugins/actions/actions.test.ts @@ -142,43 +142,6 @@ 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?.({ - channel: "telegram", - 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({ diff --git a/src/channels/plugins/actions/telegram.ts b/src/channels/plugins/actions/telegram.ts index 0f33692815..940fc85cd3 100644 --- a/src/channels/plugins/actions/telegram.ts +++ b/src/channels/plugins/actions/telegram.ts @@ -1,3 +1,5 @@ +import type { TelegramActionConfig } from "../../../config/types.telegram.js"; +import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js"; import { readNumberParam, readStringArrayParam, @@ -5,14 +7,12 @@ import { readStringParam, } from "../../../agents/tools/common.js"; import { handleTelegramAction } from "../../../agents/tools/telegram-actions.js"; -import type { TelegramActionConfig } from "../../../config/types.telegram.js"; import { extractToolSend } from "../../../plugin-sdk/tool-send.js"; import { createTelegramActionGate, listEnabledTelegramAccounts, } from "../../../telegram/accounts.js"; import { isTelegramInlineButtonsEnabled } from "../../../telegram/inline-buttons.js"; -import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js"; const providerId = "telegram"; @@ -65,9 +65,6 @@ export const telegramMessageActions: ChannelMessageActionAdapter = { if (gate("deleteMessage")) { actions.add("delete"); } - if (gate("polls")) { - actions.add("poll"); - } if (gate("editMessage")) { actions.add("edit"); } @@ -126,40 +123,6 @@ 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") ??