mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:18:27 +00:00
fix(telegram): preserve inbound quote context and avoid QUOTE_TEXT_INVALID
This commit is contained in:
committed by
Ayaan Zaidi
parent
727a390d13
commit
a4b38ce886
@@ -194,7 +194,7 @@ describe("deliverReplies", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("uses reply_parameters when quote text is provided", async () => {
|
||||
it("uses reply_to_message_id when quote text is provided", async () => {
|
||||
const runtime = { error: vi.fn(), log: vi.fn() };
|
||||
const sendMessage = vi.fn().mockResolvedValue({
|
||||
message_id: 10,
|
||||
@@ -217,10 +217,14 @@ describe("deliverReplies", () => {
|
||||
"123",
|
||||
expect.any(String),
|
||||
expect.objectContaining({
|
||||
reply_parameters: {
|
||||
message_id: 500,
|
||||
quote: "quoted text",
|
||||
},
|
||||
reply_to_message_id: 500,
|
||||
}),
|
||||
);
|
||||
expect(sendMessage).toHaveBeenCalledWith(
|
||||
"123",
|
||||
expect.any(String),
|
||||
expect.not.objectContaining({
|
||||
reply_parameters: expect.anything(),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -484,16 +484,8 @@ function buildTelegramSendParams(opts?: {
|
||||
}): Record<string, unknown> {
|
||||
const threadParams = buildTelegramThreadParams(opts?.thread);
|
||||
const params: Record<string, unknown> = {};
|
||||
const quoteText = opts?.replyQuoteText?.trim();
|
||||
if (opts?.replyToMessageId) {
|
||||
if (quoteText) {
|
||||
params.reply_parameters = {
|
||||
message_id: Math.trunc(opts.replyToMessageId),
|
||||
quote: quoteText,
|
||||
};
|
||||
} else {
|
||||
params.reply_to_message_id = opts.replyToMessageId;
|
||||
}
|
||||
params.reply_to_message_id = opts.replyToMessageId;
|
||||
}
|
||||
if (threadParams) {
|
||||
params.message_thread_id = threadParams.message_thread_id;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user