fix(qqbot): surface failed media sends (#92823) · openclaw/openclaw@650c5ca
zhangguiping
·
2026-06-14
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -114,4 +114,54 @@ describe("qqbot message adapter", () => {
|
114 | 114 | expect(proofResults.find((result) => result.capability === "media")?.status).toBe("verified"); |
115 | 115 | expect(proofResults.find((result) => result.capability === "replyTo")?.status).toBe("verified"); |
116 | 116 | }); |
| 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 | +}); |
117 | 167 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -134,8 +134,14 @@ async function sendQQBotMedia(params: {
|
134 | 134 | } |
135 | 135 | |
136 | 136 | 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 | +} |
137 | 143 | return { |
138 | | -messageId: result.messageId, |
| 144 | +messageId: result.messageId || result.receipt.primaryPlatformMessageId, |
139 | 145 | receipt: result.receipt, |
140 | 146 | } satisfies ChannelMessageSendResult; |
141 | 147 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。