From f75f406b9f5f6bdb649711527bdae48475f4b10d Mon Sep 17 00:00:00 2001 From: alishaz-polymath Date: Thu, 2 Feb 2023 11:37:46 +0530 Subject: [PATCH 1/2] fixes webhook endpoint --- packages/nodes-base/nodes/Cal/CalTrigger.node.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Cal/CalTrigger.node.ts b/packages/nodes-base/nodes/Cal/CalTrigger.node.ts index 884f5d0cbc1a4..0872d72197aea 100644 --- a/packages/nodes-base/nodes/Cal/CalTrigger.node.ts +++ b/packages/nodes-base/nodes/Cal/CalTrigger.node.ts @@ -59,6 +59,11 @@ export class CalTrigger implements INodeType { value: 'BOOKING_RESCHEDULED', description: 'Receive notifications when a Cal event is rescheduled', }, + { + name: 'Meeting Ended', + value: 'MEETING_ENDED', + description: 'Receive notifications when a Cal event or meeting has ended', + }, ], default: [], required: true, @@ -131,7 +136,7 @@ export class CalTrigger implements INodeType { // Check all the webhooks which exist already if it is identical to the // one that is supposed to get created. - const data = await calApiRequest.call(this, 'GET', '/hooks', {}); + const data = await calApiRequest.call(this, 'GET', '/webhooks', {}); for (const webhook of data.webhooks) { if (webhook.subscriberUrl === webhookUrl) { @@ -161,7 +166,7 @@ export class CalTrigger implements INodeType { ...(options as object), }; - const responseData = await calApiRequest.call(this, 'POST', '/hooks', body); + const responseData = await calApiRequest.call(this, 'POST', '/webhooks', body); if (responseData.webhook.id === undefined) { // Required data is missing so was not successful @@ -174,7 +179,7 @@ export class CalTrigger implements INodeType { async delete(this: IHookFunctions): Promise { const webhookData = this.getWorkflowStaticData('node'); if (webhookData.webhookId !== undefined) { - const endpoint = `/hooks/${webhookData.webhookId}`; + const endpoint = `/webhooks/${webhookData.webhookId}`; try { await calApiRequest.call(this, 'DELETE', endpoint); From 9cf9ee87fdd8fdf733ae38746d96b6e6daa00be7 Mon Sep 17 00:00:00 2001 From: alishaz-polymath Date: Tue, 21 Feb 2023 17:31:23 +0530 Subject: [PATCH 2/2] added light versioning --- .../nodes-base/nodes/Cal/CalTrigger.node.ts | 64 +++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/packages/nodes-base/nodes/Cal/CalTrigger.node.ts b/packages/nodes-base/nodes/Cal/CalTrigger.node.ts index 0872d72197aea..2eb2fa9cb1fc8 100644 --- a/packages/nodes-base/nodes/Cal/CalTrigger.node.ts +++ b/packages/nodes-base/nodes/Cal/CalTrigger.node.ts @@ -16,7 +16,7 @@ export class CalTrigger implements INodeType { name: 'calTrigger', icon: 'file:cal.svg', group: ['trigger'], - version: 1, + version: [1, 2], subtitle: '=Events: {{$parameter["events"].join(", ")}}', description: 'Handle Cal events via webhooks', defaults: { @@ -68,6 +68,50 @@ export class CalTrigger implements INodeType { default: [], required: true, }, + { + displayName: 'API Version', + name: 'version', + type: 'options', + displayOptions: { + show: { + '@version': [1], + }, + }, + isNodeSetting: true, + options: [ + { + name: 'Before v2.0', + value: 1, + }, + { + name: 'v2.0 Onwards', + value: 2, + }, + ], + default: 1, + }, + { + displayName: 'API Version', + name: 'version', + type: 'options', + displayOptions: { + show: { + '@version': [2], + }, + }, + isNodeSetting: true, + options: [ + { + name: 'Before v2.0', + value: 1, + }, + { + name: 'v2.0 Onwards', + value: 2, + }, + ], + default: 2, + }, { displayName: 'Options', name: 'options', @@ -130,13 +174,17 @@ export class CalTrigger implements INodeType { webhookMethods = { default: { async checkExists(this: IHookFunctions): Promise { + const version = this.getNodeParameter('version', 0) as number; const webhookUrl = this.getNodeWebhookUrl('default'); const webhookData = this.getWorkflowStaticData('node'); const events = this.getNodeParameter('events') as string; // Check all the webhooks which exist already if it is identical to the // one that is supposed to get created. - const data = await calApiRequest.call(this, 'GET', '/webhooks', {}); + const data = + version === 2 + ? await calApiRequest.call(this, 'GET', '/webhooks', {}) + : await calApiRequest.call(this, 'GET', '/hooks', {}); for (const webhook of data.webhooks) { if (webhook.subscriberUrl === webhookUrl) { @@ -153,6 +201,7 @@ export class CalTrigger implements INodeType { return false; }, async create(this: IHookFunctions): Promise { + const version = this.getNodeParameter('version', 0) as number; const webhookData = this.getWorkflowStaticData('node'); const subscriberUrl = this.getNodeWebhookUrl('default'); const eventTriggers = this.getNodeParameter('events') as string; @@ -166,7 +215,10 @@ export class CalTrigger implements INodeType { ...(options as object), }; - const responseData = await calApiRequest.call(this, 'POST', '/webhooks', body); + const responseData = + version === 2 + ? await calApiRequest.call(this, 'POST', '/webhooks', body) + : await calApiRequest.call(this, 'POST', '/hooks', body); if (responseData.webhook.id === undefined) { // Required data is missing so was not successful @@ -177,9 +229,13 @@ export class CalTrigger implements INodeType { return true; }, async delete(this: IHookFunctions): Promise { + const version = this.getNodeParameter('version', 0) as number; const webhookData = this.getWorkflowStaticData('node'); if (webhookData.webhookId !== undefined) { - const endpoint = `/webhooks/${webhookData.webhookId}`; + const endpoint = + version === 2 + ? `/webhooks/${webhookData.webhookId}` + : `/hooks/${webhookData.webhookId}`; try { await calApiRequest.call(this, 'DELETE', endpoint);