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:
@@ -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");
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user