Skip to content

Commit 31872fb

Browse files
authored
Merge pull request #1 from ethsdev/update/add_type_param
update: add type param to the webhook
2 parents 06d2d7e + 24f2471 commit 31872fb

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

nodes/Lowcoder/Lowcoder.node.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
import {
42
INodeType,
53
INodeTypeDescription,
@@ -50,10 +48,9 @@ export class Lowcoder implements INodeType {
5048
name: 'default',
5149
httpMethod: '={{$parameter["httpMethod"]}}',
5250
isFullPath: true,
53-
responseCode: '200',
5451
responseMode: 'onReceived',
55-
responseData: 'allEntries',
56-
responseContentType: '={{$parameter["options"]["responseContentType"]}}',
52+
responseData: '={{$parameter["options"]["responseData"] || "Workflow Resumed!"}}',
53+
responseContentType: '={{$parameter["options"]["responseContentType"] || "application/json"}}',
5754
responsePropertyName: '={{$parameter["options"]["responsePropertyName"]}}',
5855
responseHeaders: '={{$parameter["options"]["responseHeaders"]}}',
5956
path: '={{$parameter["appId"] || ""}}',
@@ -75,7 +72,14 @@ export class Lowcoder implements INodeType {
7572
default: '',
7673
},
7774
httpMethodsProperty,
78-
optionsProperty
75+
optionsProperty,
76+
{
77+
displayName: 'Response Code',
78+
name: 'responseCode',
79+
type: 'number',
80+
default: 200,
81+
description: 'The HTTP response code to return',
82+
},
7983
],
8084
};
8185

@@ -113,6 +117,7 @@ export class Lowcoder implements INodeType {
113117
ignoreBots: boolean;
114118
rawBody: Buffer;
115119
responseData?: string;
120+
responseCode?: number;
116121
};
117122
const req = this.getRequestObject();
118123
const resp = this.getResponseObject();
@@ -122,27 +127,43 @@ export class Lowcoder implements INodeType {
122127
throw new NodeApiError(this.getNode(), {}, { message: 'Authorization data is wrong!' });
123128
}
124129
} catch (error) {
125-
resp.writeHead(error.responseCode, { 'WWW-Authenticate': 'Basic realm="Webhook"' });
130+
resp.writeHead(error.responseCode || 401, { 'WWW-Authenticate': 'Basic realm="Webhook"' });
126131
resp.end(error.message);
127132
return { noWebhookResponse: true };
128133
}
129-
const body = typeof req.body != 'undefined' ? req.body : {};
130-
const returnItem: INodeExecutionData = {
131-
binary: {},
132-
json: {
133-
headers: req.headers,
134-
params: req.params,
135-
query: req.query,
136-
body: body,
137-
},
138-
};
139-
return { workflowData: [[returnItem]] };
134+
135+
const type = req.query.type;
136+
if (type === 'resume') {
137+
// Resume workflow as before
138+
const body = typeof req.body != 'undefined' ? req.body : {};
139+
const returnItem: INodeExecutionData = {
140+
binary: {},
141+
json: {
142+
headers: req.headers,
143+
params: req.params,
144+
query: req.query,
145+
body: body,
146+
},
147+
};
148+
const responseCode = options.responseCode || 200;
149+
resp.statusCode = responseCode;
150+
return { workflowData: [[returnItem]] };
151+
} else {
152+
// Return input data, and don't resume
153+
const staticData = this.getWorkflowStaticData('node');
154+
const previousData = staticData.previousNodeData || [];
155+
resp.statusCode = 200;
156+
resp.setHeader('Content-Type', 'application/json');
157+
resp.end(JSON.stringify({ message: 'Static response: workflow not resumed', type, previousData }));
158+
return { noWebhookResponse: true };
159+
}
140160
}
141161

142162
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
143163

144164
let waitTill = new Date(WAIT_TIME_UNLIMITED);
145-
165+
const staticData = this.getWorkflowStaticData('node');
166+
staticData.previousNodeData = this.getInputData().map(item => item.json);
146167
await this.putExecutionToWait(waitTill);
147168
return [this.getInputData()];
148169
}

0 commit comments

Comments
 (0)