n8n-nodes-pilot-status 1.0.5 → 1.0.7

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