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:
@@ -43,6 +43,7 @@
|
|||||||
- Plugins: add zip installs and `--link` to avoid copying local paths.
|
- Plugins: add zip installs and `--link` to avoid copying local paths.
|
||||||
|
|
||||||
### Fixes
|
### 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.
|
- 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: 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)
|
- Sessions: propagate deliveryContext into last-route updates to keep account/channel routing stable. (#1058)
|
||||||
|
|||||||
@@ -19,6 +19,16 @@ describe("resolveTelegramTargetChatType", () => {
|
|||||||
expect(resolveTelegramTargetChatType("TELEGRAM:5232990709")).toBe("direct");
|
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", () => {
|
it("returns 'unknown' for usernames", () => {
|
||||||
expect(resolveTelegramTargetChatType("@username")).toBe("unknown");
|
expect(resolveTelegramTargetChatType("@username")).toBe("unknown");
|
||||||
expect(resolveTelegramTargetChatType("telegram:@username")).toBe("unknown");
|
expect(resolveTelegramTargetChatType("telegram:@username")).toBe("unknown");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { ClawdbotConfig } from "../config/config.js";
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
import type { TelegramInlineButtonsScope } from "../config/types.telegram.js";
|
import type { TelegramInlineButtonsScope } from "../config/types.telegram.js";
|
||||||
import { listTelegramAccountIds, resolveTelegramAccount } from "./accounts.js";
|
import { listTelegramAccountIds, resolveTelegramAccount } from "./accounts.js";
|
||||||
|
import { parseTelegramTarget } from "./targets.js";
|
||||||
|
|
||||||
const DEFAULT_INLINE_BUTTONS_SCOPE: TelegramInlineButtonsScope = "allowlist";
|
const DEFAULT_INLINE_BUTTONS_SCOPE: TelegramInlineButtonsScope = "allowlist";
|
||||||
|
|
||||||
@@ -61,14 +62,12 @@ export function isTelegramInlineButtonsEnabled(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function resolveTelegramTargetChatType(target: string): "direct" | "group" | "unknown" {
|
export function resolveTelegramTargetChatType(target: string): "direct" | "group" | "unknown" {
|
||||||
let trimmed = target.trim();
|
if (!target.trim()) return "unknown";
|
||||||
if (!trimmed) return "unknown";
|
const parsed = parseTelegramTarget(target);
|
||||||
// Strip telegram: prefix added by normalizeTelegramMessagingTarget
|
const chatId = parsed.chatId.trim();
|
||||||
if (trimmed.toLowerCase().startsWith("telegram:")) {
|
if (!chatId) return "unknown";
|
||||||
trimmed = trimmed.slice("telegram:".length).trim();
|
if (/^-?\d+$/.test(chatId)) {
|
||||||
}
|
return chatId.startsWith("-") ? "group" : "direct";
|
||||||
if (/^-?\d+$/.test(trimmed)) {
|
|
||||||
return trimmed.startsWith("-") ? "group" : "direct";
|
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user