From 08fc4f5a062be538fdc730a4787b1c1c7dc41c61 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 1 Aug 2026 00:15:17 -0700 Subject: [PATCH] fix(telegram): hide disabled send actions from discovery (#117241) Co-authored-by: Peter Steinberger --- .../telegram/src/channel-actions.test.ts | 34 +++++++++++++++++++ extensions/telegram/src/channel-actions.ts | 5 ++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/extensions/telegram/src/channel-actions.test.ts b/extensions/telegram/src/channel-actions.test.ts index de34acc96941..7f859262c1cf 100644 --- a/extensions/telegram/src/channel-actions.test.ts +++ b/extensions/telegram/src/channel-actions.test.ts @@ -127,6 +127,7 @@ describe("telegramMessageActions", () => { { name: "configured telegram enables poll", cfg: { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig, + expectSend: true, expectPoll: true, expectTopicEdit: true, }, @@ -140,6 +141,7 @@ describe("telegramMessageActions", () => { }, }, } as OpenClawConfig, + expectSend: false, expectPoll: false, expectTopicEdit: true, }, @@ -153,6 +155,7 @@ describe("telegramMessageActions", () => { }, }, } as OpenClawConfig, + expectSend: true, expectPoll: false, expectTopicEdit: true, }, @@ -180,6 +183,29 @@ describe("telegramMessageActions", () => { }, }, } as OpenClawConfig, + expectSend: true, + expectPoll: false, + expectTopicEdit: true, + }, + { + name: "all account send gates disabled hide send", + cfg: { + channels: { + telegram: { + accounts: { + first: { + botToken: "tok-first", + actions: { sendMessage: false }, + }, + second: { + botToken: "tok-second", + actions: { sendMessage: false }, + }, + }, + }, + }, + } as OpenClawConfig, + expectSend: false, expectPoll: false, expectTopicEdit: true, }, @@ -190,6 +216,11 @@ describe("telegramMessageActions", () => { telegramMessageActions.describeMessageTool?.({ cfg: testCase.cfg, })?.actions ?? []; + if (testCase.expectSend) { + expect(actions, testCase.name).toContain("send"); + } else { + expect(actions, testCase.name).not.toContain("send"); + } if (testCase.expectPoll) { expect(actions, testCase.name).toContain("poll"); } else { @@ -267,6 +298,7 @@ describe("telegramMessageActions", () => { work: { botToken: "tok-work", actions: { + sendMessage: false, reactions: true, poll: false, }, @@ -287,8 +319,10 @@ describe("telegramMessageActions", () => { accountId: "work", })?.actions ?? []; + expect(defaultActions).toContain("send"); expect(defaultActions).toContain("poll"); expect(defaultActions).not.toContain("react"); + expect(workActions).not.toContain("send"); expect(workActions).toContain("react"); expect(workActions).not.toContain("poll"); }); diff --git a/extensions/telegram/src/channel-actions.ts b/extensions/telegram/src/channel-actions.ts index b11bf7460657..f5324211c149 100644 --- a/extensions/telegram/src/channel-actions.ts +++ b/extensions/telegram/src/channel-actions.ts @@ -170,7 +170,10 @@ function describeTelegramMessageTool({ schema: null, }; } - const actions = new Set(["send"]); + const actions = new Set(); + if (discovery.isEnabled("sendMessage")) { + actions.add("send"); + } if (discovery.pollEnabled) { actions.add("poll"); }