File tree 2 files changed +37
-1
lines changed
packages/nodes-base/utils/sendAndWait
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -368,6 +368,34 @@ describe('Send and Wait utils tests', () => {
368
368
369
369
expect ( result . workflowData ) . toEqual ( [ [ { json : { data : { 'test 1' : 'test value' } } } ] ] ) ;
370
370
} ) ;
371
+
372
+ it ( 'should return noWebhookResponse if method GET and user-agent is bot' , async ( ) => {
373
+ mockWebhookFunctions . getRequestObject . mockReturnValue ( {
374
+ method : 'GET' ,
375
+ headers : {
376
+ 'user-agent' : 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' ,
377
+ } ,
378
+ query : { approved : 'false' } ,
379
+ } as any ) ;
380
+
381
+ const send = jest . fn ( ) ;
382
+
383
+ mockWebhookFunctions . getResponseObject . mockReturnValue ( {
384
+ send,
385
+ } as any ) ;
386
+
387
+ mockWebhookFunctions . getNodeParameter . mockImplementation ( ( parameterName : string ) => {
388
+ const params : { [ key : string ] : any } = {
389
+ responseType : 'approval' ,
390
+ } ;
391
+ return params [ parameterName ] ;
392
+ } ) ;
393
+
394
+ const result = await sendAndWaitWebhook . call ( mockWebhookFunctions ) ;
395
+
396
+ expect ( send ) . toHaveBeenCalledWith ( '' ) ;
397
+ expect ( result ) . toEqual ( { noWebhookResponse : true } ) ;
398
+ } ) ;
371
399
} ) ;
372
400
} ) ;
373
401
Original file line number Diff line number Diff line change
1
+ import isbot from 'isbot' ;
1
2
import {
2
3
NodeOperationError ,
3
4
SEND_AND_WAIT_OPERATION ,
@@ -324,11 +325,18 @@ const getFormResponseCustomizations = (context: IWebhookFunctions) => {
324
325
export async function sendAndWaitWebhook ( this : IWebhookFunctions ) {
325
326
const method = this . getRequestObject ( ) . method ;
326
327
const res = this . getResponseObject ( ) ;
328
+ const req = this . getRequestObject ( ) ;
329
+
327
330
const responseType = this . getNodeParameter ( 'responseType' , 'approval' ) as
328
331
| 'approval'
329
332
| 'freeText'
330
333
| 'customForm' ;
331
334
335
+ if ( responseType === 'approval' && isbot ( req . headers [ 'user-agent' ] ) ) {
336
+ res . send ( '' ) ;
337
+ return { noWebhookResponse : true } ;
338
+ }
339
+
332
340
if ( responseType === 'freeText' ) {
333
341
if ( method === 'GET' ) {
334
342
const { formTitle, formDescription, buttonLabel } = getFormResponseCustomizations ( this ) ;
@@ -424,7 +432,7 @@ export async function sendAndWaitWebhook(this: IWebhookFunctions) {
424
432
}
425
433
}
426
434
427
- const query = this . getRequestObject ( ) . query as { approved : 'false' | 'true' } ;
435
+ const query = req . query as { approved : 'false' | 'true' } ;
428
436
const approved = query . approved === 'true' ;
429
437
return {
430
438
webhookResponse : ACTION_RECORDED_PAGE ,
You can’t perform that action at this time.
0 commit comments