Add collection events to Webflow Trigger Node (#1735)

This commit is contained in:
Nikita 2021-05-08 12:32:00 +08:00 committed by GitHub
parent abe1ee144a
commit 8b11eb6332
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -117,9 +117,57 @@ export class WebflowTrigger implements INodeType {
name: 'Site Publish',
value: 'site_publish',
},
{
name: 'Collection Item Created',
value: 'collection_item_created',
},
{
name: 'Collection Item Updated',
value: 'collection_item_changed',
},
{
name: 'Collection Item Deleted',
value: 'collection_item_deleted',
},
],
default: 'form_submission',
},
{
displayName: 'All collections',
name: 'allCollections',
type: 'boolean',
required: false,
default: true,
description: 'Receive events from all collections',
},
{
displayName: 'Collection',
name: 'collection',
type: 'options',
required: false,
default: '',
typeOptions: {
loadOptionsMethod: 'getCollections',
loadOptionsDependsOn: [
'site',
],
},
description: 'Collection that will trigger the events',
displayOptions: {
show: {
event: [
'collection_item_created',
'collection_item_changed',
'collection_item_deleted',
],
},
hide: {
allCollections: [
true,
],
},
},
},
],
};
@ -140,6 +188,18 @@ export class WebflowTrigger implements INodeType {
}
return returnData;
},
async getCollections(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const siteId = this.getCurrentNodeParameter('site');
const collections = await webflowApiRequest.call(this, 'GET', `/sites/${siteId}/collections`);
for (const collection of collections) {
returnData.push({
name: collection.name,
value: collection._id,
});
}
return returnData;
},
},
};
@ -165,6 +225,8 @@ export class WebflowTrigger implements INodeType {
const webhookData = this.getWorkflowStaticData('node');
const siteId = this.getNodeParameter('site') as string;
const event = this.getNodeParameter('event') as string;
const collection = this.getNodeParameter('collection') as string;
const allCollections = this.getNodeParameter('allCollections') as boolean;
const endpoint = `/sites/${siteId}/webhooks`;
const body: IDataObject = {
site_id: siteId,
@ -172,6 +234,11 @@ export class WebflowTrigger implements INodeType {
url: webhookUrl,
};
if(event.startsWith('collection') && !allCollections) {
body.filter = {
'_cid': collection,
};
}
const { _id } = await webflowApiRequest.call(this, 'POST', endpoint, body);
webhookData.webhookId = _id;
return true;