Skip to content

Commit c4f20b6

Browse files
authored
fix(telegram): preserve implicit default account (#82794)
Keep the top-level Telegram default account in the account list when named accounts or bindings are added alongside top-level credentials. This preserves default polling while still allowing named-only configs to resolve to their single configured account.
1 parent 94ed68b commit c4f20b6

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

extensions/telegram/src/account-selection.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
3737
return [...ids];
3838
}
3939

40+
function hasConfiguredDefaultAccountSource(cfg: OpenClawConfig): boolean {
41+
const telegram = cfg.channels?.telegram;
42+
if (!telegram) {
43+
return false;
44+
}
45+
const botToken = telegram.botToken;
46+
if (typeof botToken === "string") {
47+
return botToken.trim().length > 0;
48+
}
49+
if (botToken && typeof botToken === "object") {
50+
return true;
51+
}
52+
return typeof telegram.tokenFile === "string" && telegram.tokenFile.trim().length > 0;
53+
}
54+
4055
function resolveBindingAccount(params: {
4156
binding: unknown;
4257
channelId: string;
@@ -114,7 +129,10 @@ function resolveListedDefaultAccountId(params: {
114129
export function listTelegramAccountIds(cfg: OpenClawConfig): string[] {
115130
return combineAccountIds({
116131
configuredAccountIds: listConfiguredAccountIds(cfg),
117-
additionalAccountIds: listBoundAccountIds(cfg, "telegram"),
132+
additionalAccountIds: [
133+
...listBoundAccountIds(cfg, "telegram"),
134+
...(hasConfiguredDefaultAccountSource(cfg) ? [DEFAULT_ACCOUNT_ID] : []),
135+
],
118136
});
119137
}
120138

extensions/telegram/src/accounts.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,33 @@ describe("resolveTelegramAccount", () => {
145145
expect(accounts.map((account) => account.accountId)).toEqual(["work"]);
146146
expect(accounts[0]?.token).toBe("tok-work");
147147
});
148+
149+
it("keeps the implicit default account when named accounts are added to top-level credentials (#82780)", () => {
150+
const cfg = {
151+
channels: {
152+
telegram: {
153+
botToken: "tok-default",
154+
accounts: {
155+
fusion: {
156+
enabled: false,
157+
name: "Fusion",
158+
botToken: "tok-fusion",
159+
},
160+
},
161+
},
162+
},
163+
bindings: [{ agentId: "fusion", match: { channel: "telegram", accountId: "fusion" } }],
164+
} as unknown as OpenClawConfig;
165+
166+
expect(listTelegramAccountIds(cfg)).toEqual(["default", "fusion"]);
167+
expect(resolveDefaultTelegramAccountId(cfg)).toBe("default");
168+
expectNoMissingDefaultWarning();
169+
170+
const accounts = listEnabledTelegramAccounts(cfg);
171+
expect(accounts.map((account) => account.accountId)).toEqual(["default"]);
172+
expect(accounts[0]?.token).toBe("tok-default");
173+
expect(accounts[0]?.tokenSource).toBe("config");
174+
});
148175
});
149176

150177
describe("resolveDefaultTelegramAccountId", () => {

0 commit comments

Comments
 (0)