mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-07 10:34:44 +00:00
fix(qqbot): surface failed media sends (#92823)
* fix(qqbot): surface media send failures * test(qqbot): cover text send failures --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
@@ -114,4 +114,54 @@ describe("qqbot message adapter", () => {
|
||||
expect(proofResults.find((result) => result.capability === "media")?.status).toBe("verified");
|
||||
expect(proofResults.find((result) => result.capability === "replyTo")?.status).toBe("verified");
|
||||
});
|
||||
|
||||
it("rejects media sends when QQBot reports an outbound error", async () => {
|
||||
sendMediaMock.mockResolvedValue({ error: "QQ API returned 400 Bad Request" });
|
||||
|
||||
await expect(
|
||||
qqbotPlugin.message?.send?.media?.({
|
||||
cfg,
|
||||
to: "qqbot:c2c:user-1",
|
||||
text: "image",
|
||||
mediaUrl: "https://example.com/image.png",
|
||||
}),
|
||||
).rejects.toThrow("QQ API returned 400 Bad Request");
|
||||
});
|
||||
|
||||
it("rejects text sends when QQBot reports an outbound error", async () => {
|
||||
sendTextMock.mockResolvedValue({ error: "QQ API returned 400 Bad Request" });
|
||||
|
||||
await expect(
|
||||
qqbotPlugin.message?.send?.text?.({
|
||||
cfg,
|
||||
to: "qqbot:c2c:user-1",
|
||||
text: "hello",
|
||||
}),
|
||||
).rejects.toThrow("QQ API returned 400 Bad Request");
|
||||
});
|
||||
|
||||
it("rejects media sends without a QQ platform message id", async () => {
|
||||
sendMediaMock.mockResolvedValue({});
|
||||
|
||||
await expect(
|
||||
qqbotPlugin.message?.send?.media?.({
|
||||
cfg,
|
||||
to: "qqbot:c2c:user-1",
|
||||
text: "image",
|
||||
mediaUrl: "https://example.com/image.png",
|
||||
}),
|
||||
).rejects.toThrow("QQBot message adapter send did not return a platform message id");
|
||||
});
|
||||
|
||||
it("rejects text sends without a QQ platform message id", async () => {
|
||||
sendTextMock.mockResolvedValue({});
|
||||
|
||||
await expect(
|
||||
qqbotPlugin.message?.send?.text?.({
|
||||
cfg,
|
||||
to: "qqbot:c2c:user-1",
|
||||
text: "hello",
|
||||
}),
|
||||
).rejects.toThrow("QQBot message adapter send did not return a platform message id");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -134,8 +134,14 @@ async function sendQQBotMedia(params: {
|
||||
}
|
||||
|
||||
function toQQBotMessageSendResult(result: Awaited<ReturnType<typeof sendQQBotText>>) {
|
||||
if (result.meta?.error) {
|
||||
throw new Error(result.meta.error);
|
||||
}
|
||||
if (result.receipt.platformMessageIds.length === 0) {
|
||||
throw new Error("QQBot message adapter send did not return a platform message id");
|
||||
}
|
||||
return {
|
||||
messageId: result.messageId,
|
||||
messageId: result.messageId || result.receipt.primaryPlatformMessageId,
|
||||
receipt: result.receipt,
|
||||
} satisfies ChannelMessageSendResult;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user