n8n-nodes-aivencerealtycrm 1.1.0 → 1.2.0
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,12 @@
|
|
|
1
|
+
import { IHookFunctions, IWebhookFunctions, INodeType, INodeTypeDescription, IWebhookResponseData } from 'n8n-workflow';
|
|
2
|
+
export declare class AivenceRealtyTrigger implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
webhookMethods: {
|
|
5
|
+
default: {
|
|
6
|
+
checkExists(this: IHookFunctions): Promise<boolean>;
|
|
7
|
+
create(this: IHookFunctions): Promise<boolean>;
|
|
8
|
+
delete(this: IHookFunctions): Promise<boolean>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AivenceRealtyTrigger = void 0;
|
|
4
|
+
class AivenceRealtyTrigger {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.description = {
|
|
7
|
+
displayName: 'AivenceRealty Trigger',
|
|
8
|
+
name: 'aivenceRealtyTrigger',
|
|
9
|
+
icon: 'file:aivencerealty.png',
|
|
10
|
+
group: ['trigger'],
|
|
11
|
+
version: 1,
|
|
12
|
+
subtitle: '={{$parameter["event"]}}',
|
|
13
|
+
description: 'Trigger de eventos desde AivenceRealty CRM',
|
|
14
|
+
defaults: {
|
|
15
|
+
name: 'AivenceRealty Trigger',
|
|
16
|
+
},
|
|
17
|
+
inputs: [],
|
|
18
|
+
outputs: ['main'],
|
|
19
|
+
credentials: [
|
|
20
|
+
{
|
|
21
|
+
name: 'aivenceRealtyApi',
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
webhooks: [
|
|
26
|
+
{
|
|
27
|
+
name: 'default',
|
|
28
|
+
httpMethod: 'POST',
|
|
29
|
+
responseMode: 'onReceived',
|
|
30
|
+
path: 'webhook',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
properties: [
|
|
34
|
+
{
|
|
35
|
+
displayName: 'Evento',
|
|
36
|
+
name: 'event',
|
|
37
|
+
type: 'options',
|
|
38
|
+
options: [
|
|
39
|
+
{
|
|
40
|
+
name: 'Propiedad Creada',
|
|
41
|
+
value: 'property.created',
|
|
42
|
+
description: 'Se dispara cuando se crea una nueva propiedad',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'Propiedad Actualizada',
|
|
46
|
+
value: 'property.updated',
|
|
47
|
+
description: 'Se dispara cuando se actualiza una propiedad',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'Lead Creado',
|
|
51
|
+
value: 'lead.created',
|
|
52
|
+
description: 'Se dispara cuando se crea un nuevo lead',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'Lead Actualizado',
|
|
56
|
+
value: 'lead.updated',
|
|
57
|
+
description: 'Se dispara cuando se actualiza un lead',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'Email Recibido',
|
|
61
|
+
value: 'email.received',
|
|
62
|
+
description: 'Se dispara cuando se recibe un nuevo email',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'Maintenance Request Creada',
|
|
66
|
+
value: 'maintenance.created',
|
|
67
|
+
description: 'Se dispara cuando se crea una solicitud de mantenimiento',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'Appointment Creado',
|
|
71
|
+
value: 'appointment.created',
|
|
72
|
+
description: 'Se dispara cuando se crea una cita',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
default: 'property.created',
|
|
76
|
+
description: 'El evento que disparará el webhook',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
displayName: 'Filtros Adicionales',
|
|
80
|
+
name: 'filters',
|
|
81
|
+
type: 'collection',
|
|
82
|
+
placeholder: 'Agregar Filtro',
|
|
83
|
+
default: {},
|
|
84
|
+
options: [
|
|
85
|
+
{
|
|
86
|
+
displayName: 'Property Type',
|
|
87
|
+
name: 'property_type',
|
|
88
|
+
type: 'options',
|
|
89
|
+
options: [
|
|
90
|
+
{
|
|
91
|
+
name: 'Apartamento',
|
|
92
|
+
value: 'apartamento',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'Casa',
|
|
96
|
+
value: 'casa',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'Loft',
|
|
100
|
+
value: 'loft',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'Terreno',
|
|
104
|
+
value: 'terreno',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'Oficina',
|
|
108
|
+
value: 'oficina',
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
default: '',
|
|
112
|
+
description: 'Filtrar solo propiedades de este tipo',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
displayName: 'Precio Mínimo',
|
|
116
|
+
name: 'price_min',
|
|
117
|
+
type: 'number',
|
|
118
|
+
default: 0,
|
|
119
|
+
description: 'Filtrar propiedades con precio mayor a este valor',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
displayName: 'Precio Máximo',
|
|
123
|
+
name: 'price_max',
|
|
124
|
+
type: 'number',
|
|
125
|
+
default: 0,
|
|
126
|
+
description: 'Filtrar propiedades con precio menor a este valor',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
displayName: 'Ciudad',
|
|
130
|
+
name: 'city',
|
|
131
|
+
type: 'string',
|
|
132
|
+
default: '',
|
|
133
|
+
description: 'Filtrar propiedades de esta ciudad',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
this.webhookMethods = {
|
|
140
|
+
default: {
|
|
141
|
+
async checkExists() {
|
|
142
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
143
|
+
if (webhookData.webhookId === undefined) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const credentials = await this.getCredentials('aivenceRealtyApi');
|
|
147
|
+
const baseUrl = credentials.baseUrl;
|
|
148
|
+
const webhookId = webhookData.webhookId;
|
|
149
|
+
try {
|
|
150
|
+
const response = await this.helpers.request({
|
|
151
|
+
method: 'GET',
|
|
152
|
+
url: `${baseUrl}/api/v1/webhooks/${webhookId}`,
|
|
153
|
+
json: true,
|
|
154
|
+
});
|
|
155
|
+
return response.active === true;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
async create() {
|
|
162
|
+
const webhookUrl = this.getNodeWebhookUrl('default');
|
|
163
|
+
const event = this.getNodeParameter('event');
|
|
164
|
+
const filters = this.getNodeParameter('filters', {});
|
|
165
|
+
const credentials = await this.getCredentials('aivenceRealtyApi');
|
|
166
|
+
const baseUrl = credentials.baseUrl;
|
|
167
|
+
const body = {
|
|
168
|
+
url: webhookUrl,
|
|
169
|
+
event,
|
|
170
|
+
active: true,
|
|
171
|
+
filters,
|
|
172
|
+
};
|
|
173
|
+
try {
|
|
174
|
+
const response = await this.helpers.request({
|
|
175
|
+
method: 'POST',
|
|
176
|
+
url: `${baseUrl}/api/v1/webhooks`,
|
|
177
|
+
body,
|
|
178
|
+
json: true,
|
|
179
|
+
});
|
|
180
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
181
|
+
webhookData.webhookId = response.data.id;
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
async delete() {
|
|
189
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
190
|
+
if (webhookData.webhookId === undefined) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
const credentials = await this.getCredentials('aivenceRealtyApi');
|
|
194
|
+
const baseUrl = credentials.baseUrl;
|
|
195
|
+
const webhookId = webhookData.webhookId;
|
|
196
|
+
try {
|
|
197
|
+
await this.helpers.request({
|
|
198
|
+
method: 'DELETE',
|
|
199
|
+
url: `${baseUrl}/api/v1/webhooks/${webhookId}`,
|
|
200
|
+
json: true,
|
|
201
|
+
});
|
|
202
|
+
delete webhookData.webhookId;
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
async webhook() {
|
|
213
|
+
const bodyData = this.getBodyData();
|
|
214
|
+
const event = this.getNodeParameter('event');
|
|
215
|
+
const filters = this.getNodeParameter('filters', {});
|
|
216
|
+
// Validar que el evento recibido coincida con el configurado
|
|
217
|
+
const receivedEvent = bodyData.event;
|
|
218
|
+
if (receivedEvent !== event) {
|
|
219
|
+
return {
|
|
220
|
+
webhookResponse: {
|
|
221
|
+
success: false,
|
|
222
|
+
message: 'Event mismatch',
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
// Aplicar filtros si existen
|
|
227
|
+
if (Object.keys(filters).length > 0) {
|
|
228
|
+
const payload = bodyData.data;
|
|
229
|
+
// Filtro por tipo de propiedad
|
|
230
|
+
if (filters.property_type && payload.property_type !== filters.property_type) {
|
|
231
|
+
return {
|
|
232
|
+
webhookResponse: {
|
|
233
|
+
success: true,
|
|
234
|
+
message: 'Filtered out by property_type',
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// Filtro por precio mínimo
|
|
239
|
+
if (filters.price_min && Number(payload.price) < Number(filters.price_min)) {
|
|
240
|
+
return {
|
|
241
|
+
webhookResponse: {
|
|
242
|
+
success: true,
|
|
243
|
+
message: 'Filtered out by price_min',
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
// Filtro por precio máximo
|
|
248
|
+
if (filters.price_max && Number(payload.price) > Number(filters.price_max)) {
|
|
249
|
+
return {
|
|
250
|
+
webhookResponse: {
|
|
251
|
+
success: true,
|
|
252
|
+
message: 'Filtered out by price_max',
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
// Filtro por ciudad
|
|
257
|
+
if (filters.city && payload.city !== filters.city) {
|
|
258
|
+
return {
|
|
259
|
+
webhookResponse: {
|
|
260
|
+
success: true,
|
|
261
|
+
message: 'Filtered out by city',
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
workflowData: [this.helpers.returnJsonArray(bodyData)],
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.AivenceRealtyTrigger = AivenceRealtyTrigger;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-aivencerealtycrm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Nodo n8n para integrar el CRM inmobiliario AivenceRealty",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n8n-community-node-package",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"dist/credentials/AivenceRealtyApi.credentials.js"
|
|
40
40
|
],
|
|
41
41
|
"nodes": [
|
|
42
|
-
"dist/nodes/AivenceRealty/AivenceRealty.node.js"
|
|
42
|
+
"dist/nodes/AivenceRealty/AivenceRealty.node.js",
|
|
43
|
+
"dist/nodes/AivenceRealtyTrigger/AivenceRealtyTrigger.node.js"
|
|
43
44
|
]
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|