From 5fea53d89c099103cb5504af79ade13194f72a8b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 8 Jan 2026 21:20:59 +0100 Subject: [PATCH] fix(cron): parse telegram targets with prefixes (thanks @mitschabaude-bot) --- CHANGELOG.md | 1 + src/cron/isolated-agent.test.ts | 16 ++++++++++++++++ src/cron/isolated-agent.ts | 11 ++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c87f3113..f4bb1a5c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Daemon: align generated systemd unit with docs for network-online + restart delay. (#479) — thanks @azade-c - Outbound: default Telegram account selection for config-only tokens; remove heartbeat-specific accountId handling. (follow-up #516) — thanks @YuriNachos +- Cron: allow Telegram delivery targets with topic/thread IDs (e.g. `-100…:topic:123`). (#474) — thanks @mitschabaude-bot - Heartbeat: resolve Telegram account IDs from config-only tokens; cron tool accepts canonical `jobId` and legacy `id` for job actions. (#516) — thanks @YuriNachos - Discord: stop provider when gateway reconnects are exhausted and surface errors. (#514) — thanks @joshp123 - Auto-reply: preserve block reply ordering with timeout fallback for streaming. (#503) — thanks @joshp123 diff --git a/src/cron/isolated-agent.test.ts b/src/cron/isolated-agent.test.ts index c9677c7f7..d7f29716c 100644 --- a/src/cron/isolated-agent.test.ts +++ b/src/cron/isolated-agent.test.ts @@ -716,4 +716,20 @@ describe("parseTelegramTarget", () => { topicId: undefined, }); }); + + it("strips internal telegram prefix", () => { + expect(parseTelegramTarget("telegram:123")).toEqual({ + chatId: "123", + topicId: undefined, + }); + }); + + it("strips internal telegram + group prefixes before parsing topic", () => { + expect(parseTelegramTarget("telegram:group:-1001234567890:topic:456")).toEqual( + { + chatId: "-1001234567890", + topicId: 456, + }, + ); + }); }); diff --git a/src/cron/isolated-agent.ts b/src/cron/isolated-agent.ts index 0cc056c5a..fa093719f 100644 --- a/src/cron/isolated-agent.ts +++ b/src/cron/isolated-agent.ts @@ -61,7 +61,16 @@ export function parseTelegramTarget(to: string): { chatId: string; topicId: number | undefined; } { - const trimmed = to.trim(); + let trimmed = to.trim(); + + // Cron "lastTo" values can include internal prefixes like `telegram:...` or + // `telegram:group:...` (see normalizeChatId in telegram/send.ts). + // Strip these before parsing `:topic:` / `:` suffixes. + while (true) { + const next = trimmed.replace(/^(telegram|tg|group):/i, "").trim(); + if (next === trimmed) break; + trimmed = next; + } // Try format: chatId:topic:topicId const topicMatch = /^(.+?):topic:(\d+)$/.exec(trimmed);