mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
✨ Add collection events to Webflow Trigger Node (#1735)
This commit is contained in:
parent
abe1ee144a
commit
8b11eb6332
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue