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 <penchan@penchan.co>
This commit is contained in:
Matt Van Horn 2026-03-23 02:18:46 -07:00 committed by GitHub
parent 7ba28d6dba
commit 988bd782f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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) ?? "";