n8n-nodes-pilot-status 1.0.5 → 1.0.6

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.
@@ -72,26 +72,11 @@ class PilotStatus {
72
72
  type: 'options',
73
73
  noDataExpression: true,
74
74
  options: [
75
- {
76
- name: 'Message',
77
- value: 'message',
78
- },
79
- {
80
- name: 'Project',
81
- value: 'project',
82
- },
83
- {
84
- name: 'API Key',
85
- value: 'apiKey',
86
- },
87
- {
88
- name: 'Number',
89
- value: 'number',
90
- },
91
- {
92
- name: 'Analytics',
93
- value: 'analytics',
94
- },
75
+ { name: 'Message', value: 'message' },
76
+ { name: 'Project', value: 'project' },
77
+ { name: 'API Key', value: 'apiKey' },
78
+ { name: 'Number', value: 'number' },
79
+ { name: 'Analytics', value: 'analytics' },
95
80
  ],
96
81
  default: 'message',
97
82
  },
@@ -103,11 +88,7 @@ class PilotStatus {
103
88
  name: 'operation',
104
89
  type: 'options',
105
90
  noDataExpression: true,
106
- displayOptions: {
107
- show: {
108
- resource: ['message'],
109
- },
110
- },
91
+ displayOptions: { show: { resource: ['message'] } },
111
92
  options: [
112
93
  {
113
94
  name: 'Send',
@@ -115,9 +96,40 @@ class PilotStatus {
115
96
  description: 'Send a message',
116
97
  action: 'Send a message',
117
98
  routing: {
118
- request: {
119
- method: 'POST',
120
- url: '/messages/send',
99
+ request: { method: 'POST', url: '/messages/send' },
100
+ // ✅ preSend hook: monta o campo "variables" como objeto antes de enviar
101
+ send: {
102
+ preSend: [
103
+ async function (requestOptions) {
104
+ var _a;
105
+ const mode = this.getNodeParameter('variablesMode');
106
+ let variables = {};
107
+ if (mode === 'json') {
108
+ const raw = this.getNodeParameter('variablesJson');
109
+ try {
110
+ const parsed = typeof raw === 'string' ? JSON.parse(raw) : raw;
111
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
112
+ variables = parsed;
113
+ }
114
+ }
115
+ catch {
116
+ throw new Error(`Pilot Status: "Variables (JSON)" contém JSON inválido.\nValor recebido: ${raw}`);
117
+ }
118
+ }
119
+ else {
120
+ const ui = this.getNodeParameter('variablesUi');
121
+ for (const entry of (_a = ui === null || ui === void 0 ? void 0 : ui.values) !== null && _a !== void 0 ? _a : []) {
122
+ variables[entry.name] = entry.value;
123
+ }
124
+ }
125
+ // Garante que o body é um objeto e injeta "variables" como objeto
126
+ if (!requestOptions.body || typeof requestOptions.body !== 'object') {
127
+ requestOptions.body = {};
128
+ }
129
+ requestOptions.body['variables'] = variables;
130
+ return requestOptions;
131
+ },
132
+ ],
121
133
  },
122
134
  },
123
135
  },
@@ -127,10 +139,7 @@ class PilotStatus {
127
139
  description: 'Get the status of a message',
128
140
  action: 'Get status of a message',
129
141
  routing: {
130
- request: {
131
- method: 'GET',
132
- url: '=/messages/{{$parameter.messageId}}',
133
- },
142
+ request: { method: 'GET', url: '=/messages/{{$parameter.messageId}}' },
134
143
  },
135
144
  },
136
145
  {
@@ -142,57 +151,33 @@ class PilotStatus {
142
151
  request: {
143
152
  method: 'GET',
144
153
  url: '/messages/opt-in',
145
- qs: {
146
- destinationNumber: '={{$parameter.destinationNumber}}',
147
- },
154
+ qs: { destinationNumber: '={{$parameter.destinationNumber}}' },
148
155
  },
149
156
  },
150
157
  },
151
158
  ],
152
159
  default: 'send',
153
160
  },
154
- // Message: Send
161
+ // Message: Send — campos
155
162
  {
156
163
  displayName: 'Template ID',
157
164
  name: 'templateId',
158
165
  type: 'options',
159
- typeOptions: {
160
- loadOptionsMethod: 'getTemplates',
161
- },
162
- displayOptions: {
163
- show: {
164
- resource: ['message'],
165
- operation: ['send'],
166
- },
167
- },
166
+ typeOptions: { loadOptionsMethod: 'getTemplates' },
167
+ displayOptions: { show: { resource: ['message'], operation: ['send'] } },
168
168
  default: '',
169
169
  required: true,
170
- routing: {
171
- send: {
172
- type: 'body',
173
- property: 'templateId',
174
- },
175
- },
170
+ routing: { send: { type: 'body', property: 'templateId' } },
176
171
  },
177
172
  {
178
173
  displayName: 'Destination Number',
179
174
  name: 'destinationNumber',
180
175
  type: 'string',
181
176
  description: 'E.164 format (e.g. +5511999999999)',
182
- displayOptions: {
183
- show: {
184
- resource: ['message'],
185
- operation: ['send', 'checkOptIn'],
186
- },
187
- },
177
+ displayOptions: { show: { resource: ['message'], operation: ['send', 'checkOptIn'] } },
188
178
  default: '',
189
179
  required: true,
190
- routing: {
191
- send: {
192
- type: 'body',
193
- property: 'destinationNumber',
194
- },
195
- },
180
+ routing: { send: { type: 'body', property: 'destinationNumber' } },
196
181
  },
197
182
  {
198
183
  displayName: 'Variables Mode',
@@ -200,24 +185,11 @@ class PilotStatus {
200
185
  type: 'options',
201
186
  noDataExpression: true,
202
187
  options: [
203
- {
204
- name: 'UI Collection',
205
- value: 'collection',
206
- description: 'Add variables one by one in the UI',
207
- },
208
- {
209
- name: 'JSON Object',
210
- value: 'json',
211
- description: 'Provide an object with key-value pairs',
212
- },
188
+ { name: 'UI Collection', value: 'collection', description: 'Add variables one by one in the UI' },
189
+ { name: 'JSON Object', value: 'json', description: 'Provide an object with key-value pairs' },
213
190
  ],
214
191
  default: 'collection',
215
- displayOptions: {
216
- show: {
217
- resource: ['message'],
218
- operation: ['send'],
219
- },
220
- },
192
+ displayOptions: { show: { resource: ['message'], operation: ['send'] } },
221
193
  },
222
194
  {
223
195
  displayName: 'Variables (JSON)',
@@ -225,27 +197,18 @@ class PilotStatus {
225
197
  type: 'string',
226
198
  default: '{}',
227
199
  displayOptions: {
228
- show: {
229
- resource: ['message'],
230
- operation: ['send'],
231
- variablesMode: ['json'],
232
- },
200
+ show: { resource: ['message'], operation: ['send'], variablesMode: ['json'] },
233
201
  },
234
202
  description: 'A JSON object containing key-value pairs for variables',
203
+ // ✅ Sem routing aqui — o preSend cuida do envio como objeto
235
204
  },
236
205
  {
237
206
  displayName: 'Variables',
238
207
  name: 'variablesUi',
239
208
  type: 'fixedCollection',
240
- typeOptions: {
241
- multipleValues: true,
242
- },
209
+ typeOptions: { multipleValues: true },
243
210
  displayOptions: {
244
- show: {
245
- resource: ['message'],
246
- operation: ['send'],
247
- variablesMode: ['collection'],
248
- },
211
+ show: { resource: ['message'], operation: ['send'], variablesMode: ['collection'] },
249
212
  },
250
213
  default: {},
251
214
  description: 'Preencha as variáveis do template selecionado',
@@ -275,24 +238,7 @@ class PilotStatus {
275
238
  ],
276
239
  },
277
240
  ],
278
- },
279
- {
280
- displayName: 'Variables',
281
- name: 'variables',
282
- type: 'hidden',
283
- displayOptions: {
284
- show: {
285
- resource: ['message'],
286
- operation: ['send'],
287
- },
288
- },
289
- default: '={{ $parameter.variablesMode === "json" ? (typeof $parameter.variablesJson === "string" ? JSON.parse($parameter.variablesJson) : $parameter.variablesJson) : ($parameter.variablesUi?.values || []).reduce((acc, cur) => { acc[cur.name] = cur.value; return acc; }, {}) }}',
290
- routing: {
291
- send: {
292
- type: 'body',
293
- property: 'variables',
294
- },
295
- },
241
+ // ✅ Sem routing aqui — o preSend cuida do envio como objeto
296
242
  },
297
243
  {
298
244
  displayName: 'Additional Fields',
@@ -300,12 +246,7 @@ class PilotStatus {
300
246
  type: 'collection',
301
247
  placeholder: 'Add Field',
302
248
  default: {},
303
- displayOptions: {
304
- show: {
305
- resource: ['message'],
306
- operation: ['send'],
307
- },
308
- },
249
+ displayOptions: { show: { resource: ['message'], operation: ['send'] } },
309
250
  options: [
310
251
  {
311
252
  displayName: 'Deliver At',
@@ -323,41 +264,22 @@ class PilotStatus {
323
264
  },
324
265
  ],
325
266
  },
267
+ // Hidden fields para deliverAt / deliverUntil normalizados
326
268
  {
327
269
  displayName: 'Deliver At',
328
270
  name: 'deliverAtNormalized',
329
271
  type: 'hidden',
330
- displayOptions: {
331
- show: {
332
- resource: ['message'],
333
- operation: ['send'],
334
- },
335
- },
272
+ displayOptions: { show: { resource: ['message'], operation: ['send'] } },
336
273
  default: '={{ $parameter.additionalFields?.deliverAt ? new Date($parameter.additionalFields.deliverAt).toISOString() : undefined }}',
337
- routing: {
338
- send: {
339
- type: 'body',
340
- property: 'deliverAt',
341
- },
342
- },
274
+ routing: { send: { type: 'body', property: 'deliverAt' } },
343
275
  },
344
276
  {
345
277
  displayName: 'Deliver Until',
346
278
  name: 'deliverUntilNormalized',
347
279
  type: 'hidden',
348
- displayOptions: {
349
- show: {
350
- resource: ['message'],
351
- operation: ['send'],
352
- },
353
- },
280
+ displayOptions: { show: { resource: ['message'], operation: ['send'] } },
354
281
  default: '={{ $parameter.additionalFields?.deliverUntil ? new Date($parameter.additionalFields.deliverUntil).toISOString() : undefined }}',
355
- routing: {
356
- send: {
357
- type: 'body',
358
- property: 'deliverUntil',
359
- },
360
- },
282
+ routing: { send: { type: 'body', property: 'deliverUntil' } },
361
283
  },
362
284
  // Message: Get Status
363
285
  {
@@ -365,12 +287,7 @@ class PilotStatus {
365
287
  name: 'messageId',
366
288
  type: 'string',
367
289
  description: 'Pilot Status message id or WhatsApp provider id (from customer webhooks messageId)',
368
- displayOptions: {
369
- show: {
370
- resource: ['message'],
371
- operation: ['getStatus'],
372
- },
373
- },
290
+ displayOptions: { show: { resource: ['message'], operation: ['getStatus'] } },
374
291
  default: '',
375
292
  required: true,
376
293
  },
@@ -382,76 +299,41 @@ class PilotStatus {
382
299
  name: 'operation',
383
300
  type: 'options',
384
301
  noDataExpression: true,
385
- displayOptions: {
386
- show: {
387
- resource: ['project'],
388
- },
389
- },
302
+ displayOptions: { show: { resource: ['project'] } },
390
303
  options: [
391
304
  {
392
305
  name: 'Create',
393
306
  value: 'create',
394
307
  description: 'Create a new project',
395
308
  action: 'Create a project',
396
- routing: {
397
- request: {
398
- method: 'POST',
399
- url: '/projects',
400
- },
401
- },
309
+ routing: { request: { method: 'POST', url: '/projects' } },
402
310
  },
403
311
  {
404
312
  name: 'Get Many',
405
313
  value: 'getAll',
406
314
  description: 'Get many projects',
407
315
  action: 'Get many projects',
408
- routing: {
409
- request: {
410
- method: 'GET',
411
- url: '/projects',
412
- },
413
- },
316
+ routing: { request: { method: 'GET', url: '/projects' } },
414
317
  },
415
318
  ],
416
319
  default: 'getAll',
417
320
  },
418
- // Project: Create
419
321
  {
420
322
  displayName: 'Name',
421
323
  name: 'name',
422
324
  type: 'string',
423
- displayOptions: {
424
- show: {
425
- resource: ['project'],
426
- operation: ['create'],
427
- },
428
- },
325
+ displayOptions: { show: { resource: ['project'], operation: ['create'] } },
429
326
  default: '',
430
327
  required: true,
431
- routing: {
432
- send: {
433
- type: 'body',
434
- property: 'name',
435
- },
436
- },
328
+ routing: { send: { type: 'body', property: 'name' } },
437
329
  },
438
330
  {
439
331
  displayName: 'Description',
440
332
  name: 'description',
441
333
  type: 'string',
442
- displayOptions: {
443
- show: {
444
- resource: ['project'],
445
- operation: ['create'],
446
- },
447
- },
334
+ displayOptions: { show: { resource: ['project'], operation: ['create'] } },
448
335
  default: '',
449
- routing: {
450
- send: {
451
- type: 'body',
452
- property: 'description',
453
- },
454
- },
336
+ routing: { send: { type: 'body', property: 'description' } },
455
337
  },
456
338
  // ----------------------------------
457
339
  // API Key Operations
@@ -461,76 +343,41 @@ class PilotStatus {
461
343
  name: 'operation',
462
344
  type: 'options',
463
345
  noDataExpression: true,
464
- displayOptions: {
465
- show: {
466
- resource: ['apiKey'],
467
- },
468
- },
346
+ displayOptions: { show: { resource: ['apiKey'] } },
469
347
  options: [
470
348
  {
471
349
  name: 'Create',
472
350
  value: 'create',
473
351
  description: 'Create a new API Key',
474
352
  action: 'Create an api key',
475
- routing: {
476
- request: {
477
- method: 'POST',
478
- url: '/api-keys',
479
- },
480
- },
353
+ routing: { request: { method: 'POST', url: '/api-keys' } },
481
354
  },
482
355
  {
483
356
  name: 'Get Many',
484
357
  value: 'getAll',
485
358
  description: 'Get many API Keys',
486
359
  action: 'Get many api keys',
487
- routing: {
488
- request: {
489
- method: 'GET',
490
- url: '/api-keys',
491
- },
492
- },
360
+ routing: { request: { method: 'GET', url: '/api-keys' } },
493
361
  },
494
362
  ],
495
363
  default: 'getAll',
496
364
  },
497
- // API Key: Create
498
365
  {
499
366
  displayName: 'Name',
500
367
  name: 'name',
501
368
  type: 'string',
502
- displayOptions: {
503
- show: {
504
- resource: ['apiKey'],
505
- operation: ['create'],
506
- },
507
- },
369
+ displayOptions: { show: { resource: ['apiKey'], operation: ['create'] } },
508
370
  default: '',
509
371
  required: true,
510
- routing: {
511
- send: {
512
- type: 'body',
513
- property: 'name',
514
- },
515
- },
372
+ routing: { send: { type: 'body', property: 'name' } },
516
373
  },
517
374
  {
518
375
  displayName: 'Retention Days',
519
376
  name: 'retentionDays',
520
377
  type: 'number',
521
- displayOptions: {
522
- show: {
523
- resource: ['apiKey'],
524
- operation: ['create'],
525
- },
526
- },
378
+ displayOptions: { show: { resource: ['apiKey'], operation: ['create'] } },
527
379
  default: 3650,
528
- routing: {
529
- send: {
530
- type: 'body',
531
- property: 'retentionDays',
532
- },
533
- },
380
+ routing: { send: { type: 'body', property: 'retentionDays' } },
534
381
  },
535
382
  // ----------------------------------
536
383
  // Number Operations
@@ -540,120 +387,64 @@ class PilotStatus {
540
387
  name: 'operation',
541
388
  type: 'options',
542
389
  noDataExpression: true,
543
- displayOptions: {
544
- show: {
545
- resource: ['number'],
546
- },
547
- },
390
+ displayOptions: { show: { resource: ['number'] } },
548
391
  options: [
549
392
  {
550
393
  name: 'Create',
551
394
  value: 'create',
552
395
  description: 'Create/Connect a WhatsApp Number',
553
396
  action: 'Create a number',
554
- routing: {
555
- request: {
556
- method: 'POST',
557
- url: '/numbers',
558
- },
559
- },
397
+ routing: { request: { method: 'POST', url: '/numbers' } },
560
398
  },
561
399
  {
562
400
  name: 'Get Status',
563
401
  value: 'getStatus',
564
402
  description: 'Get connection status of a number',
565
403
  action: 'Get status of a number',
566
- routing: {
567
- request: {
568
- method: 'GET',
569
- url: '=/numbers/{{$parameter.numberId}}/status',
570
- },
571
- },
404
+ routing: { request: { method: 'GET', url: '=/numbers/{{$parameter.numberId}}/status' } },
572
405
  },
573
406
  {
574
407
  name: 'Connect (QR + pairing code)',
575
408
  value: 'connect',
576
409
  description: 'Generate a new QR code and optional letter pairing code (only when instance is not OPEN)',
577
410
  action: 'Connect a number',
578
- routing: {
579
- request: {
580
- method: 'GET',
581
- url: '=/numbers/{{$parameter.numberId}}/connect',
582
- },
583
- },
411
+ routing: { request: { method: 'GET', url: '=/numbers/{{$parameter.numberId}}/connect' } },
584
412
  },
585
413
  ],
586
414
  default: 'create',
587
415
  },
588
- // Number: Create
589
416
  {
590
417
  displayName: 'Name',
591
418
  name: 'name',
592
419
  type: 'string',
593
- displayOptions: {
594
- show: {
595
- resource: ['number'],
596
- operation: ['create'],
597
- },
598
- },
420
+ displayOptions: { show: { resource: ['number'], operation: ['create'] } },
599
421
  default: '',
600
422
  required: true,
601
- routing: {
602
- send: {
603
- type: 'body',
604
- property: 'name',
605
- },
606
- },
423
+ routing: { send: { type: 'body', property: 'name' } },
607
424
  },
608
425
  {
609
426
  displayName: 'Number',
610
427
  name: 'number',
611
428
  type: 'string',
612
- displayOptions: {
613
- show: {
614
- resource: ['number'],
615
- operation: ['create'],
616
- },
617
- },
429
+ displayOptions: { show: { resource: ['number'], operation: ['create'] } },
618
430
  default: '',
619
431
  required: true,
620
432
  description: 'E.164 format (e.g. +5511999999999)',
621
- routing: {
622
- send: {
623
- type: 'body',
624
- property: 'number',
625
- },
626
- },
433
+ routing: { send: { type: 'body', property: 'number' } },
627
434
  },
628
435
  {
629
436
  displayName: 'Link to API Key',
630
437
  name: 'linkToApiKey',
631
438
  type: 'boolean',
632
- displayOptions: {
633
- show: {
634
- resource: ['number'],
635
- operation: ['create'],
636
- },
637
- },
439
+ displayOptions: { show: { resource: ['number'], operation: ['create'] } },
638
440
  default: true,
639
- routing: {
640
- send: {
641
- type: 'body',
642
- property: 'linkToApiKey',
643
- },
644
- },
441
+ routing: { send: { type: 'body', property: 'linkToApiKey' } },
645
442
  },
646
- // Number: Get Status / Connect
647
443
  {
648
444
  displayName: 'Number Instance ID',
649
445
  name: 'numberId',
650
446
  type: 'string',
651
- displayOptions: {
652
- show: {
653
- resource: ['number'],
654
- operation: ['getStatus', 'connect'],
655
- },
656
- },
447
+ displayOptions: { show: { resource: ['number'], operation: ['getStatus', 'connect'] } },
657
448
  default: '',
658
449
  required: true,
659
450
  },
@@ -665,46 +456,26 @@ class PilotStatus {
665
456
  name: 'operation',
666
457
  type: 'options',
667
458
  noDataExpression: true,
668
- displayOptions: {
669
- show: {
670
- resource: ['analytics'],
671
- },
672
- },
459
+ displayOptions: { show: { resource: ['analytics'] } },
673
460
  options: [
674
461
  {
675
462
  name: 'Get Dashboard',
676
463
  value: 'getDashboard',
677
464
  description: 'Get dashboard analytics stats',
678
465
  action: 'Get dashboard analytics',
679
- routing: {
680
- request: {
681
- method: 'GET',
682
- url: '/analytics/dashboard',
683
- },
684
- },
466
+ routing: { request: { method: 'GET', url: '/analytics/dashboard' } },
685
467
  },
686
468
  ],
687
469
  default: 'getDashboard',
688
470
  },
689
- // Analytics: Get Dashboard
690
471
  {
691
472
  displayName: 'Timezone (TZ)',
692
473
  name: 'tz',
693
474
  type: 'string',
694
- displayOptions: {
695
- show: {
696
- resource: ['analytics'],
697
- operation: ['getDashboard'],
698
- },
699
- },
475
+ displayOptions: { show: { resource: ['analytics'], operation: ['getDashboard'] } },
700
476
  default: 'America/Sao_Paulo',
701
477
  description: 'IANA timezone (e.g. America/Sao_Paulo)',
702
- routing: {
703
- send: {
704
- type: 'query',
705
- property: 'tz',
706
- },
707
- },
478
+ routing: { send: { type: 'query', property: 'tz' } },
708
479
  },
709
480
  ],
710
481
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-pilot-status",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "n8n node for Pilot Status API",
5
5
  "keywords": [
6
6
  "n8ncommunity",