From 988bd782f73cf2ce522ae804ab1983a287b2cc3a Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Mon, 23 Mar 2026 02:18:46 -0700 Subject: [PATCH] fix: restore Telegram topic announce delivery (#51688) (thanks @mvanhorn) When `replyLike.text` or `replyLike.caption` is an unexpected non-string value (edge case from some Telegram API responses), the reply body was coerced to "[object Object]" via string concatenation. Add a `typeof === "string"` guard to gracefully fall back to empty string, matching the existing pattern used for `quoteText` in the same function. Co-authored-by: Penchan --- extensions/telegram/src/bot/helpers.test.ts | 19 +++++++++++++++++++ extensions/telegram/src/bot/helpers.ts | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/extensions/telegram/src/bot/helpers.test.ts b/extensions/telegram/src/bot/helpers.test.ts index 5777216f2ac..924c0f369d8 100644 --- a/extensions/telegram/src/bot/helpers.test.ts +++ b/extensions/telegram/src/bot/helpers.test.ts @@ -248,6 +248,25 @@ describe("describeReplyTarget", () => { expect(result?.kind).toBe("reply"); }); + it("handles non-string reply text gracefully (issue #27201)", () => { + const result = describeReplyTarget({ + message_id: 2, + date: 1000, + chat: { id: 1, type: "private" }, + reply_to_message: { + message_id: 1, + date: 900, + chat: { id: 1, type: "private" }, + // Simulate edge case where text is an unexpected non-string value + text: { some: "object" }, + from: { id: 42, first_name: "Alice", is_bot: false }, + }, + // oxlint-disable-next-line typescript/no-explicit-any + } as any); + // Should not produce "[object Object]" — should return null (no valid body) + expect(result).toBeNull(); + }); + it("extracts forwarded context from reply_to_message (issue #9619)", () => { // When user forwards a message with a comment, the comment message has // reply_to_message pointing to the forwarded message. We should extract diff --git a/extensions/telegram/src/bot/helpers.ts b/extensions/telegram/src/bot/helpers.ts index 29561953466..ce1282eb794 100644 --- a/extensions/telegram/src/bot/helpers.ts +++ b/extensions/telegram/src/bot/helpers.ts @@ -406,7 +406,8 @@ export function describeReplyTarget(msg: Message): TelegramReplyTarget | null { const replyLike = reply ?? externalReply; if (!body && replyLike) { - const replyBody = (replyLike.text ?? replyLike.caption ?? "").trim(); + const rawText = replyLike.text ?? replyLike.caption ?? ""; + const replyBody = (typeof rawText === "string" ? rawText : "").trim(); body = replyBody; if (!body) { body = resolveTelegramMediaPlaceholder(replyLike) ?? "";