

























@@ -1681,6 +1681,103 @@ describe("createTelegramBot", () => {
16811681expect(messagesById.get("201")?.body).toBe("After the incident review.");
16821682});
168316831684+it("updates cached bot messages from Telegram edit updates", async () => {
1685+onSpy.mockClear();
1686+replySpy.mockClear();
1687+1688+loadConfig.mockReturnValue({
1689+agents: {
1690+defaults: {
1691+envelopeTimezone: "utc",
1692+},
1693+},
1694+channels: {
1695+telegram: {
1696+groupPolicy: "open",
1697+groups: { "*": { requireMention: false } },
1698+},
1699+},
1700+});
1701+1702+createTelegramBot({ token: "tok" });
1703+const handler = getOnHandler("message") as (ctx: Record<string, unknown>) => Promise<void>;
1704+const editedHandler = getOnHandler("edited_message") as (
1705+ctx: Record<string, unknown>,
1706+) => Promise<void>;
1707+const baseCtx = {
1708+me: { id: 999, username: "openclaw_bot" },
1709+getFile: async () => ({ download: async () => new Uint8Array() }),
1710+};
1711+const chat = { id: 42, type: "group", title: "Ops" };
1712+const question = {
1713+ chat,
1714+text: "/ask which bikes can reach 383kmph",
1715+date: 1778474813,
1716+message_id: 35014,
1717+from: { id: 201, is_bot: false, first_name: "Kesava" },
1718+};
1719+const fullAnswer =
1720+"Kawasaki Ninja H2R (claimed 400 km/h) and MTT 420RR turbine (claimed up to 439 km/h) exceed 383 km/h. Dodge Tomahawk reaches higher but is a 4-wheeled concept, not a standard bike.";
1721+1722+await handler({
1723+ ...baseCtx,
1724+message: question,
1725+});
1726+await handler({
1727+ ...baseCtx,
1728+message: {
1729+ chat,
1730+text: "K",
1731+date: 1778474823,
1732+message_id: 35016,
1733+from: { id: 777, is_bot: true, first_name: "Super Serious Bot" },
1734+reply_to_message: question,
1735+},
1736+});
1737+1738+replySpy.mockClear();
1739+await editedHandler({
1740+ ...baseCtx,
1741+editedMessage: {
1742+ chat,
1743+text: fullAnswer,
1744+date: 1778474823,
1745+edit_date: 1778474824,
1746+message_id: 35016,
1747+from: { id: 777, is_bot: true, first_name: "Super Serious Bot" },
1748+reply_to_message: question,
1749+},
1750+});
1751+expect(replySpy).not.toHaveBeenCalled();
1752+1753+await handler({
1754+ ...baseCtx,
1755+message: {
1756+ chat,
1757+text: "wtf",
1758+date: 1778474850,
1759+message_id: 35018,
1760+from: { id: 202, is_bot: false, first_name: "Kesava" },
1761+},
1762+});
1763+1764+expect(replySpy).toHaveBeenCalledTimes(1);
1765+const payload = replySpy.mock.calls[0][0];
1766+const [conversationContext] = requireArray(
1767+payload.UntrustedStructuredContext,
1768+"structured context",
1769+);
1770+const contextRecord = requireRecord(conversationContext, "conversation context");
1771+const contextPayload = requireRecord(contextRecord.payload, "conversation context payload");
1772+const messages = requireArray(contextPayload.messages, "conversation context messages").map(
1773+(message, index) => requireRecord(message, `conversation context message ${index + 1}`),
1774+);
1775+const messagesById = new Map(messages.map((message) => [message.message_id, message]));
1776+expect(messagesById.get("35016")?.sender).toBe("Super Serious Bot");
1777+expect(messagesById.get("35016")?.body).toBe(fullAnswer);
1778+expect(messagesById.get("35016")?.body).not.toBe("K");
1779+});
1780+16841781it("uses quote text when a Telegram partial reply is received", async () => {
16851782onSpy.mockClear();
16861783sendMessageSpy.mockClear();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。