n8n-nodes-whaapy 0.2.3 → 0.2.4
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.
|
@@ -91,16 +91,8 @@ class WhaapyTrigger {
|
|
|
91
91
|
type: 'collection',
|
|
92
92
|
placeholder: 'Add Option',
|
|
93
93
|
default: {},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
displayName: 'Webhook Secret',
|
|
97
|
-
name: 'webhookSecret',
|
|
98
|
-
type: 'string',
|
|
99
|
-
typeOptions: { password: true },
|
|
100
|
-
default: '',
|
|
101
|
-
description: 'Secret to verify webhook signatures (optional)',
|
|
102
|
-
},
|
|
103
|
-
],
|
|
94
|
+
description: 'The webhook secret is automatically generated by Whaapy and returned in the X-Webhook-Signature header',
|
|
95
|
+
options: [],
|
|
104
96
|
},
|
|
105
97
|
],
|
|
106
98
|
};
|
|
@@ -113,13 +105,13 @@ class WhaapyTrigger {
|
|
|
113
105
|
try {
|
|
114
106
|
const response = await this.helpers.request({
|
|
115
107
|
method: 'GET',
|
|
116
|
-
url: `${credentials.baseUrl}/webhooks
|
|
108
|
+
url: `${credentials.baseUrl}/user-webhooks`,
|
|
117
109
|
headers: {
|
|
118
110
|
Authorization: `Bearer ${credentials.apiKey}`,
|
|
119
111
|
},
|
|
120
112
|
json: true,
|
|
121
113
|
});
|
|
122
|
-
const webhooks = response.
|
|
114
|
+
const webhooks = response.data || response.webhooks || [];
|
|
123
115
|
return webhooks.some((webhook) => {
|
|
124
116
|
var _a;
|
|
125
117
|
return webhook.url === webhookUrl &&
|
|
@@ -131,22 +123,21 @@ class WhaapyTrigger {
|
|
|
131
123
|
}
|
|
132
124
|
},
|
|
133
125
|
async create() {
|
|
134
|
-
var _a;
|
|
126
|
+
var _a, _b;
|
|
135
127
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
|
136
128
|
const event = this.getNodeParameter('event');
|
|
137
|
-
const options = this.getNodeParameter('options');
|
|
138
129
|
const credentials = await this.getCredentials('whaapyApi');
|
|
130
|
+
// Generate a unique name for the webhook
|
|
131
|
+
const eventName = event === '*' ? 'all-events' : event.replace('.', '-');
|
|
139
132
|
const body = {
|
|
133
|
+
name: `n8n-${eventName}-${Date.now()}`,
|
|
140
134
|
url: webhookUrl,
|
|
141
135
|
events: event === '*' ? ['*'] : [event],
|
|
142
136
|
};
|
|
143
|
-
if (options.webhookSecret) {
|
|
144
|
-
body.secret = options.webhookSecret;
|
|
145
|
-
}
|
|
146
137
|
try {
|
|
147
138
|
const response = await this.helpers.request({
|
|
148
139
|
method: 'POST',
|
|
149
|
-
url: `${credentials.baseUrl}/webhooks
|
|
140
|
+
url: `${credentials.baseUrl}/user-webhooks`,
|
|
150
141
|
headers: {
|
|
151
142
|
Authorization: `Bearer ${credentials.apiKey}`,
|
|
152
143
|
'Content-Type': 'application/json',
|
|
@@ -155,7 +146,7 @@ class WhaapyTrigger {
|
|
|
155
146
|
json: true,
|
|
156
147
|
});
|
|
157
148
|
const webhookData = this.getWorkflowStaticData('node');
|
|
158
|
-
webhookData.webhookId = response.id || ((
|
|
149
|
+
webhookData.webhookId = ((_a = response.data) === null || _a === void 0 ? void 0 : _a.id) || response.id || ((_b = response.webhook) === null || _b === void 0 ? void 0 : _b.id);
|
|
159
150
|
return true;
|
|
160
151
|
}
|
|
161
152
|
catch (error) {
|
|
@@ -171,7 +162,7 @@ class WhaapyTrigger {
|
|
|
171
162
|
try {
|
|
172
163
|
await this.helpers.request({
|
|
173
164
|
method: 'DELETE',
|
|
174
|
-
url: `${credentials.baseUrl}/webhooks
|
|
165
|
+
url: `${credentials.baseUrl}/user-webhooks/${webhookData.webhookId}`,
|
|
175
166
|
headers: {
|
|
176
167
|
Authorization: `Bearer ${credentials.apiKey}`,
|
|
177
168
|
},
|