Skip to content

Commit 5e55b5d

Browse files
committed
test(telegram): prove empty account capability fallback
1 parent 273bd54 commit 5e55b5d

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

extensions/telegram/src/account-config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export function mergeTelegramAccountConfig(
9090
baseAllowFrom: base.allowFrom,
9191
accountAllowFrom: account.allowFrom,
9292
});
93+
const capabilities =
94+
Array.isArray(account.capabilities) && account.capabilities.length === 0
95+
? base.capabilities
96+
: (account.capabilities ?? base.capabilities);
9397

94-
return { ...base, ...account, allowFrom, groups };
98+
return { ...base, ...account, allowFrom, capabilities, groups };
9599
}

extensions/telegram/src/action-runtime.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,25 @@ describe("handleTelegramAction", () => {
17031703
expect(sendMessageTelegram).toHaveBeenCalled();
17041704
});
17051705

1706+
it("allows inline buttons when legacy capabilities are empty", async () => {
1707+
await handleTelegramAction(
1708+
{
1709+
action: "sendMessage",
1710+
to: "@testchannel",
1711+
content: "Choose",
1712+
presentation: {
1713+
blocks: [{ type: "buttons", buttons: [{ label: "Ok", value: "cmd:ok" }] }],
1714+
},
1715+
},
1716+
telegramConfig({ capabilities: [] }),
1717+
);
1718+
const call = mockCall(sendMessageTelegram, 0, "empty legacy capabilities");
1719+
expect(call[0]).toBe("@testchannel");
1720+
expect(requireRecord(call[2], "empty legacy capabilities options").buttons).toEqual([
1721+
[{ text: "Ok", callback_data: "cmd:ok" }],
1722+
]);
1723+
});
1724+
17061725
it("uses interactive button labels as fallback text when message text is omitted", async () => {
17071726
await handleTelegramAction(
17081727
{

extensions/telegram/src/inline-buttons.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ describe("resolveTelegramInlineButtonsScope (#75433 SecretRef tolerance)", () =>
123123
expect(isTelegramInlineButtonsEnabled({ cfg })).toBe(true);
124124
});
125125

126+
it("inherits the channel scope when an account legacy capabilities array is empty", () => {
127+
const cfg = {
128+
channels: {
129+
telegram: {
130+
capabilities: { inlineButtons: "off" },
131+
accounts: {
132+
ops: {
133+
botToken: "123:telegram-ops-token",
134+
capabilities: [],
135+
},
136+
},
137+
},
138+
},
139+
} as unknown as OpenClawConfig;
140+
141+
expect(resolveTelegramInlineButtonsScope({ cfg, accountId: "ops" })).toBe("off");
142+
expect(isTelegramInlineButtonsEnabled({ cfg, accountId: "ops" })).toBe(false);
143+
});
144+
126145
it('preserves configured "off" when botToken is an unresolved SecretRef', () => {
127146
const cfg = {
128147
channels: {

0 commit comments

Comments
 (0)