mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix: Do not trigger sendAndWait response on bot visit if response type is approval (#13792)
This commit is contained in:
@@ -368,6 +368,34 @@ describe('Send and Wait utils tests', () => {
|
|||||||
|
|
||||||
expect(result.workflowData).toEqual([[{ json: { data: { 'test 1': 'test value' } } }]]);
|
expect(result.workflowData).toEqual([[{ json: { data: { 'test 1': 'test value' } } }]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return noWebhookResponse if method GET and user-agent is bot', async () => {
|
||||||
|
mockWebhookFunctions.getRequestObject.mockReturnValue({
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'user-agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
|
||||||
|
},
|
||||||
|
query: { approved: 'false' },
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
const send = jest.fn();
|
||||||
|
|
||||||
|
mockWebhookFunctions.getResponseObject.mockReturnValue({
|
||||||
|
send,
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
mockWebhookFunctions.getNodeParameter.mockImplementation((parameterName: string) => {
|
||||||
|
const params: { [key: string]: any } = {
|
||||||
|
responseType: 'approval',
|
||||||
|
};
|
||||||
|
return params[parameterName];
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await sendAndWaitWebhook.call(mockWebhookFunctions);
|
||||||
|
|
||||||
|
expect(send).toHaveBeenCalledWith('');
|
||||||
|
expect(result).toEqual({ noWebhookResponse: true });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import isbot from 'isbot';
|
||||||
import {
|
import {
|
||||||
NodeOperationError,
|
NodeOperationError,
|
||||||
SEND_AND_WAIT_OPERATION,
|
SEND_AND_WAIT_OPERATION,
|
||||||
@@ -324,11 +325,18 @@ const getFormResponseCustomizations = (context: IWebhookFunctions) => {
|
|||||||
export async function sendAndWaitWebhook(this: IWebhookFunctions) {
|
export async function sendAndWaitWebhook(this: IWebhookFunctions) {
|
||||||
const method = this.getRequestObject().method;
|
const method = this.getRequestObject().method;
|
||||||
const res = this.getResponseObject();
|
const res = this.getResponseObject();
|
||||||
|
const req = this.getRequestObject();
|
||||||
|
|
||||||
const responseType = this.getNodeParameter('responseType', 'approval') as
|
const responseType = this.getNodeParameter('responseType', 'approval') as
|
||||||
| 'approval'
|
| 'approval'
|
||||||
| 'freeText'
|
| 'freeText'
|
||||||
| 'customForm';
|
| 'customForm';
|
||||||
|
|
||||||
|
if (responseType === 'approval' && isbot(req.headers['user-agent'])) {
|
||||||
|
res.send('');
|
||||||
|
return { noWebhookResponse: true };
|
||||||
|
}
|
||||||
|
|
||||||
if (responseType === 'freeText') {
|
if (responseType === 'freeText') {
|
||||||
if (method === 'GET') {
|
if (method === 'GET') {
|
||||||
const { formTitle, formDescription, buttonLabel } = getFormResponseCustomizations(this);
|
const { formTitle, formDescription, buttonLabel } = getFormResponseCustomizations(this);
|
||||||
@@ -424,7 +432,7 @@ export async function sendAndWaitWebhook(this: IWebhookFunctions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = this.getRequestObject().query as { approved: 'false' | 'true' };
|
const query = req.query as { approved: 'false' | 'true' };
|
||||||
const approved = query.approved === 'true';
|
const approved = query.approved === 'true';
|
||||||
return {
|
return {
|
||||||
webhookResponse: ACTION_RECORDED_PAGE,
|
webhookResponse: ACTION_RECORDED_PAGE,
|
||||||
|
|||||||
Reference in New Issue
Block a user