Skip to content

Commit 650c5ca

Browse files
fix(qqbot): surface failed media sends (#92823)
* fix(qqbot): surface media send failures * test(qqbot): cover text send failures --------- Co-authored-by: Vincent Koc <[email protected]>
1 parent 965fa05 commit 650c5ca

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

extensions/qqbot/src/channel.message-adapter.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,54 @@ describe("qqbot message adapter", () => {
114114
expect(proofResults.find((result) => result.capability === "media")?.status).toBe("verified");
115115
expect(proofResults.find((result) => result.capability === "replyTo")?.status).toBe("verified");
116116
});
117+
118+
it("rejects media sends when QQBot reports an outbound error", async () => {
119+
sendMediaMock.mockResolvedValue({ error: "QQ API returned 400 Bad Request" });
120+
121+
await expect(
122+
qqbotPlugin.message?.send?.media?.({
123+
cfg,
124+
to: "qqbot:c2c:user-1",
125+
text: "image",
126+
mediaUrl: "https://example.com/image.png",
127+
}),
128+
).rejects.toThrow("QQ API returned 400 Bad Request");
129+
});
130+
131+
it("rejects text sends when QQBot reports an outbound error", async () => {
132+
sendTextMock.mockResolvedValue({ error: "QQ API returned 400 Bad Request" });
133+
134+
await expect(
135+
qqbotPlugin.message?.send?.text?.({
136+
cfg,
137+
to: "qqbot:c2c:user-1",
138+
text: "hello",
139+
}),
140+
).rejects.toThrow("QQ API returned 400 Bad Request");
141+
});
142+
143+
it("rejects media sends without a QQ platform message id", async () => {
144+
sendMediaMock.mockResolvedValue({});
145+
146+
await expect(
147+
qqbotPlugin.message?.send?.media?.({
148+
cfg,
149+
to: "qqbot:c2c:user-1",
150+
text: "image",
151+
mediaUrl: "https://example.com/image.png",
152+
}),
153+
).rejects.toThrow("QQBot message adapter send did not return a platform message id");
154+
});
155+
156+
it("rejects text sends without a QQ platform message id", async () => {
157+
sendTextMock.mockResolvedValue({});
158+
159+
await expect(
160+
qqbotPlugin.message?.send?.text?.({
161+
cfg,
162+
to: "qqbot:c2c:user-1",
163+
text: "hello",
164+
}),
165+
).rejects.toThrow("QQBot message adapter send did not return a platform message id");
166+
});
117167
});

extensions/qqbot/src/channel.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ async function sendQQBotMedia(params: {
134134
}
135135

136136
function toQQBotMessageSendResult(result: Awaited<ReturnType<typeof sendQQBotText>>) {
137+
if (result.meta?.error) {
138+
throw new Error(result.meta.error);
139+
}
140+
if (result.receipt.platformMessageIds.length === 0) {
141+
throw new Error("QQBot message adapter send did not return a platform message id");
142+
}
137143
return {
138-
messageId: result.messageId,
144+
messageId: result.messageId || result.receipt.primaryPlatformMessageId,
139145
receipt: result.receipt,
140146
} satisfies ChannelMessageSendResult;
141147
}

0 commit comments

Comments
 (0)