mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-25 09:19:32 +00:00
fix(qa): read rich Telegram replies in live checks
(cherry picked from commit 9c8b880353)
This commit is contained in:
@@ -286,6 +286,43 @@ describe("telegram live qa runtime", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes Telegram rich messages as observed text", () => {
|
||||
expect(
|
||||
testing.normalizeTelegramObservedMessage({
|
||||
update_id: 8,
|
||||
message: {
|
||||
message_id: 10,
|
||||
date: 1_700_000_001,
|
||||
rich_message: { markdown: "**hello** rich" },
|
||||
chat: { id: -100123 },
|
||||
from: {
|
||||
id: 88,
|
||||
is_bot: true,
|
||||
username: "sut_bot",
|
||||
},
|
||||
reply_to_message: { message_id: 9 },
|
||||
},
|
||||
})?.text,
|
||||
).toBe("**hello** rich");
|
||||
|
||||
expect(
|
||||
testing.normalizeTelegramObservedMessage({
|
||||
update_id: 9,
|
||||
message: {
|
||||
message_id: 11,
|
||||
date: 1_700_000_002,
|
||||
rich_message: { html: "<b>hello</b> rich" },
|
||||
chat: { id: -100123 },
|
||||
from: {
|
||||
id: 88,
|
||||
is_bot: true,
|
||||
username: "sut_bot",
|
||||
},
|
||||
},
|
||||
})?.text,
|
||||
).toBe("<b>hello</b> rich");
|
||||
});
|
||||
|
||||
it("ignores unrelated sut replies when matching the canary response", () => {
|
||||
expect(
|
||||
testing.classifyCanaryReply({
|
||||
|
||||
@@ -203,11 +203,17 @@ type TelegramReplyMarkup = {
|
||||
inline_keyboard?: Array<Array<{ text?: string }>>;
|
||||
};
|
||||
|
||||
type TelegramRichMessage = {
|
||||
markdown?: string;
|
||||
html?: string;
|
||||
};
|
||||
|
||||
type TelegramMessage = {
|
||||
message_id: number;
|
||||
date: number;
|
||||
text?: string;
|
||||
caption?: string;
|
||||
rich_message?: TelegramRichMessage;
|
||||
reply_markup?: TelegramReplyMarkup;
|
||||
reply_to_message?: { message_id?: number };
|
||||
from?: {
|
||||
@@ -697,6 +703,16 @@ function detectMediaKinds(message: TelegramMessage) {
|
||||
return kinds;
|
||||
}
|
||||
|
||||
function selectTelegramObservedText(message: TelegramMessage) {
|
||||
return (
|
||||
message.text ||
|
||||
message.caption ||
|
||||
message.rich_message?.markdown ||
|
||||
message.rich_message?.html ||
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeTelegramObservedMessage(update: TelegramUpdate): TelegramObservedMessage | null {
|
||||
const message = update.message ?? update.edited_message;
|
||||
if (!message?.from?.id) {
|
||||
@@ -709,7 +725,7 @@ function normalizeTelegramObservedMessage(update: TelegramUpdate): TelegramObser
|
||||
senderId: message.from.id,
|
||||
senderIsBot: message.from.is_bot === true,
|
||||
senderUsername: message.from.username,
|
||||
text: message.text ?? message.caption ?? "",
|
||||
text: selectTelegramObservedText(message),
|
||||
caption: message.caption,
|
||||
replyToMessageId: message.reply_to_message?.message_id,
|
||||
timestamp: message.date * 1000,
|
||||
|
||||
Reference in New Issue
Block a user