@@ -212,6 +212,61 @@ describe("sendWebhookMessageDiscord proxy support", () => {
212212 globalFetchMock . mockRestore ( ) ;
213213 } ) ;
214214
215+ it ( "accepts Discord's no-body webhook response when wait is false" , async ( ) => {
216+ const response = new Response ( null , { status : 204 } ) ;
217+ const jsonSpy = vi . spyOn ( response , "json" ) ;
218+ const globalFetchMock = vi . spyOn ( globalThis , "fetch" ) . mockResolvedValue ( response ) ;
219+
220+ const result = await sendWebhookMessageDiscord ( "hello" , {
221+ cfg : { channels : { discord : { token : "Bot test-token" } } } as OpenClawConfig ,
222+ accountId : "default" ,
223+ webhookId : "123" ,
224+ webhookToken : "abc" ,
225+ wait : false ,
226+ } ) ;
227+
228+ expect ( result . messageId ) . toBe ( "unknown" ) ;
229+ expect ( jsonSpy ) . not . toHaveBeenCalled ( ) ;
230+ globalFetchMock . mockRestore ( ) ;
231+ } ) ;
232+
233+ it ( "keeps a successful send when the webhook response body exceeds the limit" , async ( ) => {
234+ const tracked = cancelTrackedResponse ( `{"id":"${ "x" . repeat ( 16 * 1024 * 1024 ) } "}` , {
235+ status : 200 ,
236+ headers : { "content-type" : "application/json" } ,
237+ } ) ;
238+ const globalFetchMock = vi . spyOn ( globalThis , "fetch" ) . mockResolvedValue ( tracked . response ) ;
239+
240+ const result = await sendWebhookMessageDiscord ( "hello" , {
241+ cfg : { channels : { discord : { token : "Bot test-token" } } } as OpenClawConfig ,
242+ accountId : "default" ,
243+ webhookId : "123" ,
244+ webhookToken : "abc" ,
245+ wait : true ,
246+ } ) ;
247+
248+ expect ( result . messageId ) . toBe ( "unknown" ) ;
249+ expect ( tracked . wasCanceled ( ) ) . toBe ( true ) ;
250+ globalFetchMock . mockRestore ( ) ;
251+ } ) ;
252+
253+ it ( "keeps a successful send when the webhook response body is malformed" , async ( ) => {
254+ const globalFetchMock = vi
255+ . spyOn ( globalThis , "fetch" )
256+ . mockResolvedValue ( new Response ( "not json" , { status : 200 } ) ) ;
257+
258+ const result = await sendWebhookMessageDiscord ( "hello" , {
259+ cfg : { channels : { discord : { token : "Bot test-token" } } } as OpenClawConfig ,
260+ accountId : "default" ,
261+ webhookId : "123" ,
262+ webhookToken : "abc" ,
263+ wait : true ,
264+ } ) ;
265+
266+ expect ( result . messageId ) . toBe ( "unknown" ) ;
267+ globalFetchMock . mockRestore ( ) ;
268+ } ) ;
269+
215270 it ( "throws typed rate limit errors for webhook 429 responses" , async ( ) => {
216271 const globalFetchMock = vi . spyOn ( globalThis , "fetch" ) . mockResolvedValue (
217272 new Response ( JSON . stringify ( { message : "Slow down" , retry_after : 0.25 , global : false } ) , {
0 commit comments