fix: honor telegram action discovery account config

This commit is contained in:
Tak Hoffman
2026-04-03 11:20:19 -05:00
parent 2b900b576c
commit fb8048a188
2 changed files with 67 additions and 1 deletions

View File

@@ -193,6 +193,45 @@ describe("telegramMessageActions", () => {
}
});
it("honors account-scoped action gates during discovery", () => {
const cfg = {
channels: {
telegram: {
botToken: "tok-default",
actions: {
reactions: false,
poll: true,
},
accounts: {
work: {
botToken: "tok-work",
actions: {
reactions: true,
poll: false,
},
},
},
},
},
} as OpenClawConfig;
const defaultActions =
telegramMessageActions.describeMessageTool?.({
cfg,
accountId: "default",
})?.actions ?? [];
const workActions =
telegramMessageActions.describeMessageTool?.({
cfg,
accountId: "work",
})?.actions ?? [];
expect(defaultActions).toContain("poll");
expect(defaultActions).not.toContain("react");
expect(workActions).toContain("react");
expect(workActions).not.toContain("poll");
});
it("normalizes reaction message identifiers before dispatch", async () => {
const cfg = { channels: { telegram: { botToken: "tok" } } } as OpenClawConfig;
const cases = [

View File

@@ -16,6 +16,7 @@ import { extractToolSend } from "openclaw/plugin-sdk/tool-send";
import {
createTelegramActionGate,
listEnabledTelegramAccounts,
resolveTelegramAccount,
resolveTelegramPollActionGateState,
} from "./accounts.js";
import { isTelegramInlineButtonsEnabled } from "./inline-buttons.js";
@@ -82,12 +83,38 @@ function resolveTelegramActionDiscovery(cfg: Parameters<typeof listEnabledTelegr
};
}
function resolveScopedTelegramActionDiscovery(params: {
cfg: Parameters<typeof listEnabledTelegramAccounts>[0];
accountId?: string | null;
}) {
if (!params.accountId) {
return resolveTelegramActionDiscovery(params.cfg);
}
const account = resolveTelegramAccount({ cfg: params.cfg, accountId: params.accountId });
if (!account.enabled || account.tokenSource === "none") {
return null;
}
const gate = createTelegramActionGate({
cfg: params.cfg,
accountId: account.accountId,
});
return {
isEnabled: (key: keyof TelegramActionConfig, defaultValue = true) => gate(key, defaultValue),
pollEnabled: resolveTelegramPollActionGateState(gate).enabled,
buttonsEnabled: isTelegramInlineButtonsEnabled({
cfg: params.cfg,
accountId: account.accountId,
}),
};
}
function describeTelegramMessageTool({
cfg,
accountId,
}: Parameters<
NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>
>[0]): ChannelMessageToolDiscovery {
const discovery = resolveTelegramActionDiscovery(cfg);
const discovery = resolveScopedTelegramActionDiscovery({ cfg, accountId });
if (!discovery) {
return {
actions: [],