fix: allow telegram prefixes/topics for inline buttons (#1072) — thanks @danielz1z

Co-authored-by: danielz1z <danielz1z@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-17 07:49:57 +00:00
parent 80bb6b712c
commit d63cc1e8a7
3 changed files with 18 additions and 8 deletions

View File

@@ -43,6 +43,7 @@
- Plugins: add zip installs and `--link` to avoid copying local paths.
### Fixes
- Telegram: accept tg/group/telegram prefixes + topic targets for inline button validation. (#1072) — thanks @danielz1z.
- Sub-agents: normalize announce delivery origin + queue bucketing by accountId to keep multi-account routing stable. (#1061, #1058) — thanks @adam91holt.
- Sessions: include deliveryContext in sessions.list and reuse normalized delivery routing for announce/restart fallbacks. (#1058)
- Sessions: propagate deliveryContext into last-route updates to keep account/channel routing stable. (#1058)

View File

@@ -19,6 +19,16 @@ describe("resolveTelegramTargetChatType", () => {
expect(resolveTelegramTargetChatType("TELEGRAM:5232990709")).toBe("direct");
});
it("handles tg/group prefixes and topic suffixes", () => {
expect(resolveTelegramTargetChatType("tg:5232990709")).toBe("direct");
expect(resolveTelegramTargetChatType("group:-123456789")).toBe("group");
expect(resolveTelegramTargetChatType("telegram:group:-1001234567890")).toBe("group");
expect(resolveTelegramTargetChatType("telegram:group:-1001234567890:topic:456")).toBe(
"group",
);
expect(resolveTelegramTargetChatType("-1001234567890:456")).toBe("group");
});
it("returns 'unknown' for usernames", () => {
expect(resolveTelegramTargetChatType("@username")).toBe("unknown");
expect(resolveTelegramTargetChatType("telegram:@username")).toBe("unknown");

View File

@@ -1,6 +1,7 @@
import type { ClawdbotConfig } from "../config/config.js";
import type { TelegramInlineButtonsScope } from "../config/types.telegram.js";
import { listTelegramAccountIds, resolveTelegramAccount } from "./accounts.js";
import { parseTelegramTarget } from "./targets.js";
const DEFAULT_INLINE_BUTTONS_SCOPE: TelegramInlineButtonsScope = "allowlist";
@@ -61,14 +62,12 @@ export function isTelegramInlineButtonsEnabled(params: {
}
export function resolveTelegramTargetChatType(target: string): "direct" | "group" | "unknown" {
let trimmed = target.trim();
if (!trimmed) return "unknown";
// Strip telegram: prefix added by normalizeTelegramMessagingTarget
if (trimmed.toLowerCase().startsWith("telegram:")) {
trimmed = trimmed.slice("telegram:".length).trim();
}
if (/^-?\d+$/.test(trimmed)) {
return trimmed.startsWith("-") ? "group" : "direct";
if (!target.trim()) return "unknown";
const parsed = parseTelegramTarget(target);
const chatId = parsed.chatId.trim();
if (!chatId) return "unknown";
if (/^-?\d+$/.test(chatId)) {
return chatId.startsWith("-") ? "group" : "direct";
}
return "unknown";
}