🔀 Merge branch 'RicardoE105-feature/added-rawBody-webhook'

This commit is contained in:
Jan Oberhauser 2019-12-21 19:04:26 -06:00
commit 8d7341b70a

View file

@ -4,6 +4,7 @@ import {
import {
IDataObject,
INodeExecutionData,
INodeTypeDescription,
INodeType,
IWebhookResponseData,
@ -119,7 +120,6 @@ export class Webhook implements INodeType {
default: 'GET',
description: 'The HTTP method to liste to.',
},
{
displayName: 'Path',
name: 'path',
@ -205,21 +205,10 @@ export class Webhook implements INodeType {
},
description: 'Name of the binary property to return',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
displayOptions: {
show: {
responseData: [
'firstEntryJson',
],
responseMode: [
'lastNode',
],
},
},
placeholder: 'Add Option',
default: {},
options: [
@ -227,6 +216,16 @@ export class Webhook implements INodeType {
displayName: 'Response Content-Type',
name: 'responseContentType',
type: 'string',
displayOptions: {
show: {
'/responseData': [
'firstEntryJson',
],
'/responseMode': [
'lastNode',
],
},
},
default: '',
placeholder: 'application/xml',
description: 'Set a custom content-type to return if another one as the "application/json" should be returned.',
@ -235,18 +234,35 @@ export class Webhook implements INodeType {
displayName: 'Property Name',
name: 'responsePropertyName',
type: 'string',
displayOptions: {
show: {
'/responseData': [
'firstEntryJson',
],
'/responseMode': [
'lastNode',
],
},
},
default: 'data',
description: 'Name of the property to return the data of instead of the whole JSON.',
},
{
displayName: 'Raw Body',
name: 'rawBody',
type: 'boolean',
default: false,
description: 'Raw body (binary)',
},
],
},
],
};
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const authentication = this.getNodeParameter('authentication', 0) as string;
const options = this.getNodeParameter('options', 0) as IDataObject;
const req = this.getRequestObject();
const resp = this.getResponseObject();
const headers = this.getHeaderData();
@ -289,19 +305,31 @@ export class Webhook implements INodeType {
}
}
const returnData: IDataObject[] = [];
// @ts-ignore
const mimeType = headers['content-type'] || 'application/json';
returnData.push(
{
const response: INodeExecutionData = {
json: {
body: this.getBodyData(),
headers,
query: this.getQueryData(),
}
);
},
};
if (options.rawBody) {
response.binary = {
data: {
// @ts-ignore
data: req.rawBody.toString('base64'),
mimeType,
}
};
}
return {
workflowData: [
this.helpers.returnJsonArray(returnData)
[
response,
],
],
};
}