mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
🔀 Merge branch 'RicardoE105-features/typeform'
This commit is contained in:
commit
d783900614
|
@ -18,7 +18,6 @@ import {
|
|||
ITypeformDefinition,
|
||||
} from './GenericFunctions';
|
||||
|
||||
|
||||
export class TypeformTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Typeform Trigger',
|
||||
|
@ -89,24 +88,23 @@ export class TypeformTrigger implements INodeType {
|
|||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
|
||||
if (webhookData.webhookId === undefined) {
|
||||
// No webhook id is set so no webhook can exist
|
||||
return false;
|
||||
}
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
|
||||
const formId = this.getNodeParameter('formId') as string;
|
||||
|
||||
const endpoint = `forms/${formId}/webhooks/${webhookData.webhookId}`;
|
||||
const endpoint = `forms/${formId}/webhooks`;
|
||||
|
||||
try {
|
||||
const body = {};
|
||||
await apiRequest.call(this, 'POST', endpoint, body);
|
||||
} catch (e) {
|
||||
return false;
|
||||
const { items } = await apiRequest.call(this, 'GET', endpoint, {});
|
||||
|
||||
for (const item of items) {
|
||||
if (item.form_id === formId
|
||||
&& item.url === webhookUrl) {
|
||||
webhookData.webhookId = item.tag;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
async create(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
|
@ -138,14 +136,12 @@ export class TypeformTrigger implements INodeType {
|
|||
if (webhookData.webhookId !== undefined) {
|
||||
const endpoint = `forms/${formId}/webhooks/${webhookData.webhookId}`;
|
||||
|
||||
|
||||
try {
|
||||
const body = {};
|
||||
await apiRequest.call(this, 'DELETE', endpoint, body);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove from the static workflow data so that it is clear
|
||||
// that no webhooks are registred anymore
|
||||
delete webhookData.webhookId;
|
||||
|
|
Loading…
Reference in a new issue