🔀 Merge branch 'Jhalter5Stones-feat/webhook-node/response-mode'

This commit is contained in:
Jan Oberhauser 2022-02-19 12:39:39 +01:00
commit 064f88cadb
3 changed files with 66 additions and 26 deletions

View file

@ -204,6 +204,14 @@ export async function executeWebhook(
200,
) as number;
const responseData = workflow.expression.getSimpleParameterValue(
workflowStartNode,
webhookData.webhookDescription.responseData,
executionMode,
additionalKeys,
'firstEntryJson',
);
if (!['onReceived', 'lastNode', 'responseNode'].includes(responseMode as string)) {
// If the mode is not known we error. Is probably best like that instead of using
// the default that people know as early as possible (probably already testing phase)
@ -331,7 +339,12 @@ export async function executeWebhook(
// directly if responseMode it set to "onReceived" and a respone should be sent
if (responseMode === 'onReceived' && !didSendResponse) {
// Return response directly and do not wait for the workflow to finish
if (webhookResultData.webhookResponse !== undefined) {
if (responseData === 'noData') {
// Return without data
responseCallback(null, {
responseCode,
});
} else if (webhookResultData.webhookResponse !== undefined) {
// Data to respond with is given
responseCallback(null, {
data: webhookResultData.webhookResponse,
@ -508,16 +521,8 @@ export async function executeWebhook(
$executionId: executionId,
};
const responseData = workflow.expression.getSimpleParameterValue(
workflowStartNode,
webhookData.webhookDescription.responseData,
executionMode,
additionalKeys,
'firstEntryJson',
);
if (!didSendResponse) {
let data: IDataObject | IDataObject[];
let data: IDataObject | IDataObject[] | undefined;
if (responseData === 'firstEntryJson') {
// Return the JSON data of the first entry
@ -621,6 +626,9 @@ export async function executeWebhook(
noWebhookResponse: true,
});
}
} else if (responseData === 'noData') {
// Return without data
data = undefined;
} else {
// Return the JSON data of all the entries
data = [];

View file

@ -85,7 +85,7 @@ export class Webhook implements INodeType {
isFullPath: true,
responseCode: '={{$parameter["responseCode"]}}',
responseMode: '={{$parameter["responseMode"]}}',
responseData: '={{$parameter["responseData"]}}',
responseData: '={{$parameter["responseData"] || ($parameter.options.noResponseBody ? "noData" : undefined) }}',
responseBinaryPropertyName: '={{$parameter["responseBinaryPropertyName"]}}',
responseContentType: '={{$parameter["options"]["responseContentType"]}}',
responsePropertyName: '={{$parameter["options"]["responsePropertyName"]}}',
@ -227,6 +227,11 @@ export class Webhook implements INodeType {
value: 'firstEntryBinary',
description: 'Returns the binary data of the first entry of the last node. Always returns a binary file.',
},
{
name: 'No Response Body',
value: 'noData',
description: 'Returns without a body.',
},
],
default: 'firstEntryJson',
description: 'What data should be returned. If it should return all items as an array or only the first item as object.',
@ -291,6 +296,42 @@ export class Webhook implements INodeType {
default: false,
description: 'Set to true to ignore requests from bots like link previewers and web crawlers',
},
{
displayName: 'No Response Body',
name: 'noResponseBody',
type: 'boolean',
default: false,
description: 'Do not send any body in the response',
displayOptions: {
hide: {
'rawBody': [
true,
],
},
show: {
'/responseMode': [
'onReceived',
],
},
},
},
{
displayName: 'Raw Body',
name: 'rawBody',
type: 'boolean',
displayOptions: {
hide: {
binaryData: [
true,
],
'noResponseBody': [
true,
],
},
},
default: false,
description: 'Raw body (binary)',
},
{
displayName: 'Response Data',
name: 'responseData',
@ -301,6 +342,11 @@ export class Webhook implements INodeType {
'onReceived',
],
},
hide: {
'noResponseBody': [
true,
],
},
},
default: '',
placeholder: 'success',
@ -374,20 +420,6 @@ export class Webhook implements INodeType {
default: 'data',
description: 'Name of the property to return the data of instead of the whole JSON.',
},
{
displayName: 'Raw Body',
name: 'rawBody',
type: 'boolean',
displayOptions: {
hide: {
binaryData: [
true,
],
},
},
default: false,
description: 'Raw body (binary)',
},
],
},
],

View file

@ -1186,7 +1186,7 @@ export interface IWebhookResponseData {
noWebhookResponse?: boolean;
}
export type WebhookResponseData = 'allEntries' | 'firstEntryJson' | 'firstEntryBinary';
export type WebhookResponseData = 'allEntries' | 'firstEntryJson' | 'firstEntryBinary' | 'noData';
export type WebhookResponseMode = 'onReceived' | 'lastNode';
export interface INodeTypes {