n8n-nodes-wappflow 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WappflowTrigger = void 0;
4
+ class WappflowTrigger {
5
+ constructor() {
6
+ this.description = {
7
+ displayName: 'Wappflow Trigger',
8
+ name: 'wappflowTrigger',
9
+ icon: 'file:wappflow.png',
10
+ group: ['trigger'],
11
+ version: 1,
12
+ description: 'Starts the workflow when Wappflow events occur',
13
+ defaults: {
14
+ name: 'Wappflow Trigger',
15
+ },
16
+ inputs: [],
17
+ outputs: ['main'],
18
+ credentials: [
19
+ {
20
+ name: 'wappflowApi',
21
+ required: true,
22
+ },
23
+ ],
24
+ webhooks: [
25
+ {
26
+ name: 'default',
27
+ httpMethod: 'POST',
28
+ responseMode: 'onReceived',
29
+ path: 'webhook',
30
+ },
31
+ ],
32
+ properties: [
33
+ {
34
+ displayName: 'Instance Name',
35
+ name: 'instanceName',
36
+ type: 'string',
37
+ default: '',
38
+ required: true,
39
+ description: 'The name of the WhatsApp instance',
40
+ },
41
+ {
42
+ displayName: 'Events',
43
+ name: 'events',
44
+ type: 'multiOptions',
45
+ options: [
46
+ { name: 'Messages Upsert', value: 'MESSAGES_UPSERT' },
47
+ { name: 'Messages Update', value: 'MESSAGES_UPDATE' },
48
+ { name: 'Send Message', value: 'SEND_MESSAGE' },
49
+ { name: 'Connection Update', value: 'CONNECTION_UPDATE' },
50
+ { name: 'Presence Update', value: 'PRESENCE_UPDATE' },
51
+ { name: 'Contacts Upsert', value: 'CONTACTS_UPSERT' },
52
+ { name: 'Groups Upsert', value: 'GROUPS_UPSERT' },
53
+ ],
54
+ default: ['MESSAGES_UPSERT'],
55
+ required: true,
56
+ description: 'The events to listen for',
57
+ },
58
+ ],
59
+ };
60
+ this.webhookMethods = {
61
+ default: {
62
+ async checkExists() {
63
+ // We don't have an easy way to check if *this specific* n8n webhook is the one registered
64
+ // without fetching and comparing URLs. For simplicity, we can assume it doesn't exist
65
+ // and always overwrite on activation, or fetch and check.
66
+ const webhookUrl = this.getNodeWebhookUrl('default');
67
+ const instanceName = this.getNodeParameter('instanceName');
68
+ const credentials = await this.getCredentials('wappflowApi');
69
+ const baseUrl = credentials.baseUrl.replace(/\/$/, '');
70
+ const apiKey = credentials.apiKey;
71
+ const options = {
72
+ headers: {
73
+ 'Accept': 'application/json',
74
+ 'apikey': apiKey,
75
+ },
76
+ method: 'GET',
77
+ uri: `${baseUrl}/v1/instance/webhook/find/${instanceName}`,
78
+ json: true,
79
+ };
80
+ try {
81
+ const response = await this.helpers.request(options);
82
+ if (response && response.webhook && response.webhook.url === webhookUrl && response.webhook.enabled) {
83
+ return true;
84
+ }
85
+ }
86
+ catch (error) {
87
+ // If instance not found or error, assume not existing
88
+ }
89
+ return false;
90
+ },
91
+ async create() {
92
+ const webhookUrl = this.getNodeWebhookUrl('default');
93
+ const instanceName = this.getNodeParameter('instanceName');
94
+ const events = this.getNodeParameter('events');
95
+ const credentials = await this.getCredentials('wappflowApi');
96
+ const baseUrl = credentials.baseUrl.replace(/\/$/, '');
97
+ const apiKey = credentials.apiKey;
98
+ const options = {
99
+ headers: {
100
+ 'Accept': 'application/json',
101
+ 'apikey': apiKey,
102
+ },
103
+ method: 'POST',
104
+ uri: `${baseUrl}/v1/instance/webhook/set/${instanceName}`,
105
+ body: {
106
+ enabled: true,
107
+ url: webhookUrl,
108
+ events: events
109
+ },
110
+ json: true,
111
+ };
112
+ try {
113
+ await this.helpers.request(options);
114
+ return true;
115
+ }
116
+ catch (error) {
117
+ throw error;
118
+ }
119
+ },
120
+ async delete() {
121
+ const instanceName = this.getNodeParameter('instanceName');
122
+ const credentials = await this.getCredentials('wappflowApi');
123
+ const baseUrl = credentials.baseUrl.replace(/\/$/, '');
124
+ const apiKey = credentials.apiKey;
125
+ // We disable the webhook on the instance
126
+ const options = {
127
+ headers: {
128
+ 'Accept': 'application/json',
129
+ 'apikey': apiKey,
130
+ },
131
+ method: 'POST',
132
+ uri: `${baseUrl}/v1/instance/webhook/set/${instanceName}`,
133
+ body: {
134
+ enabled: false,
135
+ },
136
+ json: true,
137
+ };
138
+ try {
139
+ await this.helpers.request(options);
140
+ return true;
141
+ }
142
+ catch (error) {
143
+ return false;
144
+ }
145
+ },
146
+ },
147
+ };
148
+ }
149
+ async webhook() {
150
+ const bodyData = this.getBodyData();
151
+ return {
152
+ workflowData: [
153
+ this.helpers.returnJsonArray(bodyData),
154
+ ],
155
+ };
156
+ }
157
+ }
158
+ exports.WappflowTrigger = WappflowTrigger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-wappflow",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "n8n node for Wappflow API",
5
5
  "keywords": [
6
6
  "n8n-community-node-package"
@@ -24,10 +24,11 @@
24
24
  ],
25
25
  "n8n": {
26
26
  "nodes": [
27
- "dist/WappflowApi.node.js"
27
+ "dist/nodes/WappflowApi/WappflowApi.node.js",
28
+ "dist/nodes/WappflowApi/WappflowTrigger.node.js"
28
29
  ],
29
30
  "credentials": [
30
- "dist/WappflowApi.credentials.js"
31
+ "dist/nodes/WappflowApi/WappflowApi.credentials.js"
31
32
  ]
32
33
  },
33
34
  "devDependencies": {