


















@@ -48,6 +48,26 @@ vi.mock("../media.js", () => ({
4848let deliverWebReply: typeof import("./deliver-reply.js").deliverWebReply;
4949let whatsappOutbound: typeof import("../outbound-adapter.js").whatsappOutbound;
505051+function acceptedSendResult(kind: "media" | "text", id: string) {
52+return {
53+ kind,
54+messageId: id,
55+messageIds: [id],
56+keys: [{ id }],
57+providerAccepted: true,
58+};
59+}
60+61+function unacceptedSendResult(kind: "media" | "text") {
62+return {
63+ kind,
64+messageId: "unknown",
65+messageIds: [],
66+keys: [],
67+providerAccepted: false,
68+};
69+}
70+5171function makeMsg(): WebInboundMsg {
5272return {
5373from: "+10000000000",
@@ -58,8 +78,8 @@ function makeMsg(): WebInboundMsg {
5878id: "msg-1",
5979body: "latest batch body",
6080senderJid: "222@s.whatsapp.net",
61-reply: vi.fn(async () => undefined),
62-sendMedia: vi.fn(async () => undefined),
81+reply: vi.fn(async () => acceptedSendResult("text", "reply-sent-1")),
82+sendMedia: vi.fn(async () => acceptedSendResult("media", "media-sent-1")),
6383} as unknown as WebInboundMsg;
6484}
6585@@ -99,7 +119,7 @@ function expectFirstSendMediaPayload(msg: WebInboundMsg) {
99119100120function mockSecondReplySuccess(msg: WebInboundMsg) {
101121(msg.reply as unknown as { mockResolvedValueOnce: (v: unknown) => void }).mockResolvedValueOnce(
102-undefined,
122+acceptedSendResult("text", "reply-retry-2"),
103123);
104124}
105125@@ -162,7 +182,7 @@ describe("deliverWebReply", () => {
162182it("sends chunked text replies and logs a summary", async () => {
163183const msg = makeMsg();
164184165-await deliverWebReply({
185+const delivery = await deliverWebReply({
166186replyResult: { text: "aaaaaa" },
167187 msg,
168188maxMediaBytes: 1024 * 1024,
@@ -175,6 +195,32 @@ describe("deliverWebReply", () => {
175195expect(msg.reply).toHaveBeenNthCalledWith(1, "aaa", undefined);
176196expect(msg.reply).toHaveBeenNthCalledWith(2, "aaa", undefined);
177197expect(replyLogger.info).toHaveBeenCalledWith(expect.any(Object), "auto-reply sent (text)");
198+expect(delivery.providerAccepted).toBe(true);
199+expect(delivery.messageIds).toEqual(["reply-sent-1"]);
200+});
201+202+it("reports text replies that Baileys did not accept", async () => {
203+const msg = makeMsg();
204+vi.mocked(msg.reply).mockResolvedValueOnce(unacceptedSendResult("text"));
205+206+const delivery = await deliverWebReply({
207+replyResult: { text: "hello" },
208+ msg,
209+maxMediaBytes: 1024 * 1024,
210+textLimit: 200,
211+ replyLogger,
212+skipLog: true,
213+});
214+215+expect(msg.reply).toHaveBeenCalledTimes(1);
216+expect(delivery).toMatchObject({
217+messageIds: [],
218+providerAccepted: false,
219+});
220+expect(replyLogger.warn).toHaveBeenCalledWith(
221+expect.any(Object),
222+"auto-reply text was not accepted by WhatsApp provider",
223+);
178224});
179225180226it("strips raw XML tool-call blocks before WhatsApp text delivery", async () => {
@@ -421,7 +467,7 @@ describe("deliverWebReply", () => {
421467mockFirstSendMediaFailure(msg, "socket reset");
422468(
423469msg.sendMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }
424-).mockResolvedValueOnce(undefined);
470+).mockResolvedValueOnce(acceptedSendResult("media", "media-retry-2"));
425471426472await deliverWebReply({
427473replyResult: { text: "caption", mediaUrl: "http://example.com/img.jpg" },
@@ -484,7 +530,7 @@ describe("deliverWebReply", () => {
484530mockFirstSendMediaFailure(msg, "boom");
485531(
486532msg.sendMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }
487-).mockResolvedValueOnce(undefined);
533+).mockResolvedValueOnce(acceptedSendResult("media", "media-second-1"));
488534489535await deliverWebReply({
490536replyResult: {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。