fix(telegram): preserve inbound quote context and avoid QUOTE_TEXT_INVALID

This commit is contained in:
Denis Rybnikov
2026-02-08 23:48:14 +01:00
committed by Ayaan Zaidi
parent 727a390d13
commit a4b38ce886
4 changed files with 60 additions and 26 deletions

View File

@@ -226,31 +226,33 @@ export type TelegramReplyTarget = {
export function describeReplyTarget(msg: Message): TelegramReplyTarget | null {
const reply = msg.reply_to_message;
const quote = msg.quote;
const externalReply = msg.external_reply;
const quoteText = msg.quote?.text ?? reply?.quote?.text ?? externalReply?.quote?.text;
let body = "";
let kind: TelegramReplyTarget["kind"] = "reply";
if (quote?.text) {
body = quote.text.trim();
if (typeof quoteText === "string") {
body = quoteText.trim();
if (body) {
kind = "quote";
}
}
if (!body && reply) {
const replyBody = (reply.text ?? reply.caption ?? "").trim();
const replyLike = reply ?? externalReply;
if (!body && replyLike) {
const replyBody = (replyLike.text ?? replyLike.caption ?? "").trim();
body = replyBody;
if (!body) {
if (reply.photo) {
if (replyLike.photo) {
body = "<media:image>";
} else if (reply.video) {
} else if (replyLike.video) {
body = "<media:video>";
} else if (reply.audio || reply.voice) {
} else if (replyLike.audio || replyLike.voice) {
body = "<media:audio>";
} else if (reply.document) {
} else if (replyLike.document) {
body = "<media:document>";
} else {
const locationData = extractTelegramLocation(reply);
const locationData = extractTelegramLocation(replyLike);
if (locationData) {
body = formatLocationText(locationData);
}
@@ -260,11 +262,11 @@ export function describeReplyTarget(msg: Message): TelegramReplyTarget | null {
if (!body) {
return null;
}
const sender = reply ? buildSenderName(reply) : undefined;
const sender = replyLike ? buildSenderName(replyLike) : undefined;
const senderLabel = sender ?? "unknown sender";
return {
id: reply?.message_id ? String(reply.message_id) : undefined,
id: replyLike?.message_id ? String(replyLike.message_id) : undefined,
sender: senderLabel,
body,
kind,