feat: expose bot task progress

This commit is contained in:
zenord
2026-08-17 14:37:51 +08:00
parent 91bf4e7a0c
commit 2795567f8c
13 changed files with 321 additions and 54 deletions
+11 -4
View File
@@ -20,16 +20,23 @@ test("normalizes GROUP and C2C author openid while ACK remains immediate", async
assert.equal(received[1].chatId, "user:u2"); assert.equal(received[1].userId, "u2");
});
test("sendMessage uses nested author.user_openid for C2C endpoint", async () => {
const original = globalThis.fetch; const urls: string[] = [];
globalThis.fetch = (async (input: string | URL | Request) => {
test("sendMessage uses C2C endpoint and forwards reply sequences as msg_seq", async () => {
const original = globalThis.fetch; const urls: string[] = []; const bodies: Array<Record<string, unknown>> = [];
globalThis.fetch = (async (input: string | URL | Request, init?: RequestInit) => {
urls.push(String(input));
if (String(input).includes("getAppAccessToken")) return new Response(JSON.stringify({ access_token: "token", expires_in: 7200 }), { status: 200 });
bodies.push(JSON.parse(String(init?.body)) as Record<string, unknown>);
return new Response(JSON.stringify({ id: "sent" }), { status: 200 });
}) as typeof fetch;
try {
const adapter = new QqAdapter(config, { receive: async () => ({ ok: true }) } as never);
await adapter.sendMessage({ target: { platform: "qq", chatId: "user:u2", raw: { author: { user_openid: "u2" } } }, text: "reply", replyTo: "m2" });
const target = { platform: "qq", chatId: "user:u2", raw: { author: { user_openid: "u2" } } };
await adapter.sendMessage({ target, text: "ack", replyTo: "m2", replySequence: 1 });
await adapter.sendMessage({ target, text: "reply", replyTo: "m2", replySequence: 2 });
assert.ok(urls.some((url) => url.endsWith("/v2/users/u2/messages")));
assert.deepEqual(bodies, [
{ content: "ack", msg_id: "m2", msg_seq: 1 },
{ content: "reply", msg_id: "m2", msg_seq: 2 }
]);
} finally { globalThis.fetch = original; }
});