This commit is contained in:
Ricardo Espinoza 2019-12-21 15:36:08 -05:00
parent 700ca5c85a
commit f1bb1f10f3

View file

@ -119,7 +119,6 @@ export class Webhook implements INodeType {
default: 'GET',
description: 'The HTTP method to liste to.',
},
{
displayName: 'Path',
name: 'path',
@ -205,7 +204,6 @@ export class Webhook implements INodeType {
},
description: 'Name of the binary property to return',
},
{
displayName: 'Options',
name: 'options',
@ -238,15 +236,45 @@ 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',
default: false,
description: 'Raw body (binary)',
},
],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
displayOptions: {
show: {
responseMode: [
'onReceived',
],
},
},
placeholder: 'Add Option',
default: {},
options: [
{
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 string;
const req = this.getRequestObject();
const resp = this.getResponseObject();
const headers = this.getHeaderData();
@ -288,21 +316,27 @@ export class Webhook implements INodeType {
return authorizationError(resp, realm, 403);
}
}
const returnData: IDataObject[] = [];
returnData.push(
{
const response = {
json: {
body: this.getBodyData(),
headers,
query: this.getQueryData(),
},
};
// @ts-ignore
if (options.rawBody) {
// @ts-ignore
response.binary = {
// @ts-ignore
rawBody: req.rawBody,
}
);
data: req.rawBody.toString('base64'),
};
}
return {
workflowData: [
this.helpers.returnJsonArray(returnData)
[
response,
],
],
};
}