fix: preserve Telegram reply context text (#50500) (thanks @p3nchan)

* fix: guard Telegram reply context text (#50500) (thanks @p3nchan)

* fix: preserve Telegram reply caption fallback (#50500) (thanks @p3nchan)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
This commit is contained in:
Penchan
2026-03-23 17:24:39 +08:00
committed by GitHub
parent 75b65c2a35
commit 95fec668a0
3 changed files with 28 additions and 3 deletions

View File

@@ -263,10 +263,29 @@ describe("describeReplyTarget", () => {
},
// oxlint-disable-next-line typescript/no-explicit-any
} as any);
// Should not produce "[object Object]" — should return null (no valid body)
// Should not throw when reply text is malformed; return null instead.
expect(result).toBeNull();
});
it("falls back to caption when reply text is malformed", () => {
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" },
text: { some: "object" },
caption: "Caption body",
from: { id: 42, first_name: "Alice", is_bot: false },
},
// oxlint-disable-next-line typescript/no-explicit-any
} as any);
expect(result?.body).toBe("Caption body");
expect(result?.kind).toBe("reply");
});
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,8 +406,13 @@ export function describeReplyTarget(msg: Message): TelegramReplyTarget | null {
const replyLike = reply ?? externalReply;
if (!body && replyLike) {
const rawText = replyLike.text ?? replyLike.caption ?? "";
const replyBody = (typeof rawText === "string" ? rawText : "").trim();
const replyBody = (
typeof replyLike.text === "string"
? replyLike.text
: typeof replyLike.caption === "string"
? replyLike.caption
: ""
).trim();
body = replyBody;
if (!body) {
body = resolveTelegramMediaPlaceholder(replyLike) ?? "";