Skip to content

Commit 526a2e4

Browse files
authoredMar 11, 2025··
fix: Do not trigger sendAndWait response on bot visit if response type is approval (#13792)
1 parent 899f6c9 commit 526a2e4

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
 

‎packages/nodes-base/utils/sendAndWait/test/util.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,34 @@ describe('Send and Wait utils tests', () => {
368368

369369
expect(result.workflowData).toEqual([[{ json: { data: { 'test 1': 'test value' } } }]]);
370370
});
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+
});
371399
});
372400
});
373401

‎packages/nodes-base/utils/sendAndWait/utils.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import isbot from 'isbot';
12
import {
23
NodeOperationError,
34
SEND_AND_WAIT_OPERATION,
@@ -324,11 +325,18 @@ const getFormResponseCustomizations = (context: IWebhookFunctions) => {
324325
export async function sendAndWaitWebhook(this: IWebhookFunctions) {
325326
const method = this.getRequestObject().method;
326327
const res = this.getResponseObject();
328+
const req = this.getRequestObject();
329+
327330
const responseType = this.getNodeParameter('responseType', 'approval') as
328331
| 'approval'
329332
| 'freeText'
330333
| 'customForm';
331334

335+
if (responseType === 'approval' && isbot(req.headers['user-agent'])) {
336+
res.send('');
337+
return { noWebhookResponse: true };
338+
}
339+
332340
if (responseType === 'freeText') {
333341
if (method === 'GET') {
334342
const { formTitle, formDescription, buttonLabel } = getFormResponseCustomizations(this);
@@ -424,7 +432,7 @@ export async function sendAndWaitWebhook(this: IWebhookFunctions) {
424432
}
425433
}
426434

427-
const query = this.getRequestObject().query as { approved: 'false' | 'true' };
435+
const query = req.query as { approved: 'false' | 'true' };
428436
const approved = query.approved === 'true';
429437
return {
430438
webhookResponse: ACTION_RECORDED_PAGE,

0 commit comments

Comments
 (0)
Please sign in to comment.