@astervia/n8n-nodes-wacraft 0.1.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,1043 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Wacraft = void 0;
4
+ const GenericFunctions_1 = require("./GenericFunctions");
5
+ class Wacraft {
6
+ constructor() {
7
+ this.description = {
8
+ displayName: "Wacraft",
9
+ name: "wacraft",
10
+ icon: "file:wacraft.svg",
11
+ group: ["transform"],
12
+ version: 1,
13
+ subtitle: '={{$parameter["resource"] + ": " + $parameter["operation"]}}',
14
+ description: "Interact with the wacraft WhatsApp Cloud API server",
15
+ defaults: {
16
+ name: "Wacraft",
17
+ },
18
+ inputs: ["main"],
19
+ outputs: ["main"],
20
+ credentials: [
21
+ {
22
+ name: "wacraftApi",
23
+ required: true,
24
+ },
25
+ ],
26
+ properties: [
27
+ // ------------------------------------------------------------------
28
+ // Resource selector
29
+ // ------------------------------------------------------------------
30
+ {
31
+ displayName: "Resource",
32
+ name: "resource",
33
+ type: "options",
34
+ noDataExpression: true,
35
+ options: [
36
+ { name: "Contact", value: "contact" },
37
+ { name: "Media", value: "media" },
38
+ { name: "Message", value: "message" },
39
+ { name: "Messaging Product", value: "messagingProduct" },
40
+ { name: "Messaging Product Contact", value: "messagingProductContact" },
41
+ { name: "Template", value: "template" },
42
+ ],
43
+ default: "contact",
44
+ },
45
+ // ==================================================================
46
+ // CONTACT operations
47
+ // ==================================================================
48
+ {
49
+ displayName: "Operation",
50
+ name: "operation",
51
+ type: "options",
52
+ noDataExpression: true,
53
+ displayOptions: { show: { resource: ["contact"] } },
54
+ options: [
55
+ {
56
+ name: "Create",
57
+ value: "create",
58
+ action: "Create a contact",
59
+ description: "Create a new contact",
60
+ },
61
+ {
62
+ name: "Delete",
63
+ value: "delete",
64
+ action: "Delete a contact",
65
+ description: "Delete a contact by ID",
66
+ },
67
+ {
68
+ name: "Get Many",
69
+ value: "getMany",
70
+ action: "Get many contacts",
71
+ description: "Retrieve a paginated list of contacts",
72
+ },
73
+ {
74
+ name: "Update",
75
+ value: "update",
76
+ action: "Update a contact",
77
+ description: "Update an existing contact",
78
+ },
79
+ ],
80
+ default: "getMany",
81
+ },
82
+ // ==================================================================
83
+ // MESSAGE operations
84
+ // ==================================================================
85
+ {
86
+ displayName: "Operation",
87
+ name: "operation",
88
+ type: "options",
89
+ noDataExpression: true,
90
+ displayOptions: { show: { resource: ["message"] } },
91
+ options: [
92
+ {
93
+ name: "Get Many",
94
+ value: "getMany",
95
+ action: "Get many messages",
96
+ description: "Retrieve a paginated list of messages",
97
+ },
98
+ {
99
+ name: "Mark as Read",
100
+ value: "markAsRead",
101
+ action: "Mark as read",
102
+ description: "Mark last message as read",
103
+ },
104
+ {
105
+ name: "Search by Content",
106
+ value: "searchByContent",
107
+ action: "Search messages by content",
108
+ description: "Search messages by content text",
109
+ },
110
+ {
111
+ name: "Send WhatsApp Message",
112
+ value: "sendWhatsApp",
113
+ action: "Send a WhatsApp message",
114
+ description: "Send a WhatsApp message",
115
+ },
116
+ {
117
+ name: "Send Typing",
118
+ value: "sendTyping",
119
+ action: "Send typing indicator",
120
+ description: "Mark as read and show typing indicator",
121
+ },
122
+ ],
123
+ default: "getMany",
124
+ },
125
+ // ==================================================================
126
+ // MESSAGING PRODUCT operations
127
+ // ==================================================================
128
+ {
129
+ displayName: "Operation",
130
+ name: "operation",
131
+ type: "options",
132
+ noDataExpression: true,
133
+ displayOptions: { show: { resource: ["messagingProduct"] } },
134
+ options: [
135
+ {
136
+ name: "Get Many",
137
+ value: "getMany",
138
+ action: "Get many messaging products",
139
+ description: "Retrieve messaging products",
140
+ },
141
+ ],
142
+ default: "getMany",
143
+ },
144
+ // ==================================================================
145
+ // MESSAGING PRODUCT CONTACT operations
146
+ // ==================================================================
147
+ {
148
+ displayName: "Operation",
149
+ name: "operation",
150
+ type: "options",
151
+ noDataExpression: true,
152
+ displayOptions: { show: { resource: ["messagingProductContact"] } },
153
+ options: [
154
+ {
155
+ name: "Block",
156
+ value: "block",
157
+ action: "Block a contact",
158
+ description: "Block a messaging product contact",
159
+ },
160
+ {
161
+ name: "Create",
162
+ value: "create",
163
+ action: "Create a messaging product contact",
164
+ description: "Create a messaging product contact",
165
+ },
166
+ {
167
+ name: "Create WhatsApp",
168
+ value: "createWhatsApp",
169
+ action: "Create a WhatsApp contact",
170
+ description: "Create a WhatsApp messaging product contact",
171
+ },
172
+ {
173
+ name: "Delete",
174
+ value: "delete",
175
+ action: "Delete a messaging product contact",
176
+ description: "Delete a messaging product contact",
177
+ },
178
+ {
179
+ name: "Get Many",
180
+ value: "getMany",
181
+ action: "Get many messaging product contacts",
182
+ description: "Retrieve messaging product contacts",
183
+ },
184
+ {
185
+ name: "Get WhatsApp Contacts",
186
+ value: "getWhatsApp",
187
+ action: "Get WhatsApp contacts",
188
+ description: "Retrieve WhatsApp messaging product contacts",
189
+ },
190
+ {
191
+ name: "Search by Content",
192
+ value: "searchByContent",
193
+ action: "Search contacts by content",
194
+ description: "Search messaging product contacts by content text",
195
+ },
196
+ {
197
+ name: "Unblock",
198
+ value: "unblock",
199
+ action: "Unblock a contact",
200
+ description: "Unblock a messaging product contact",
201
+ },
202
+ ],
203
+ default: "getMany",
204
+ },
205
+ // ==================================================================
206
+ // MEDIA operations
207
+ // ==================================================================
208
+ {
209
+ displayName: "Operation",
210
+ name: "operation",
211
+ type: "options",
212
+ noDataExpression: true,
213
+ displayOptions: { show: { resource: ["media"] } },
214
+ options: [
215
+ {
216
+ name: "Download",
217
+ value: "download",
218
+ action: "Download media",
219
+ description: "Download WhatsApp media by ID",
220
+ },
221
+ {
222
+ name: "Get Info",
223
+ value: "getInfo",
224
+ action: "Get media info",
225
+ description: "Get media info / temporary URL",
226
+ },
227
+ {
228
+ name: "Upload",
229
+ value: "upload",
230
+ action: "Upload media",
231
+ description: "Upload a media file to WhatsApp",
232
+ },
233
+ ],
234
+ default: "getInfo",
235
+ },
236
+ // ==================================================================
237
+ // TEMPLATE operations
238
+ // ==================================================================
239
+ {
240
+ displayName: "Operation",
241
+ name: "operation",
242
+ type: "options",
243
+ noDataExpression: true,
244
+ displayOptions: { show: { resource: ["template"] } },
245
+ options: [
246
+ {
247
+ name: "Get Many",
248
+ value: "getMany",
249
+ action: "Get many templates",
250
+ description: "Retrieve WhatsApp templates",
251
+ },
252
+ ],
253
+ default: "getMany",
254
+ },
255
+ // ==================================================================
256
+ // SHARED: Workspace ID override
257
+ // ==================================================================
258
+ {
259
+ displayName: "Workspace ID Override",
260
+ name: "workspaceIdOverride",
261
+ type: "string",
262
+ default: "",
263
+ description: "Override the default workspace ID for this operation. Leave empty to use the credential default.",
264
+ },
265
+ // ==================================================================
266
+ // CONTACT fields
267
+ // ==================================================================
268
+ // --- Create ---
269
+ {
270
+ displayName: "Name",
271
+ name: "name",
272
+ type: "string",
273
+ default: "",
274
+ displayOptions: { show: { resource: ["contact"], operation: ["create"] } },
275
+ description: "Contact name",
276
+ },
277
+ {
278
+ displayName: "Email",
279
+ name: "email",
280
+ type: "string",
281
+ placeholder: "name@email.com",
282
+ default: "",
283
+ displayOptions: { show: { resource: ["contact"], operation: ["create"] } },
284
+ description: "Contact email",
285
+ },
286
+ {
287
+ displayName: "Photo Path",
288
+ name: "photoPath",
289
+ type: "string",
290
+ default: "",
291
+ displayOptions: { show: { resource: ["contact"], operation: ["create"] } },
292
+ description: "Contact photo path",
293
+ },
294
+ // --- Update ---
295
+ {
296
+ displayName: "Contact ID",
297
+ name: "contactId",
298
+ type: "string",
299
+ required: true,
300
+ default: "",
301
+ displayOptions: { show: { resource: ["contact"], operation: ["update"] } },
302
+ description: "ID of the contact to update",
303
+ },
304
+ {
305
+ displayName: "Update Fields",
306
+ name: "updateFields",
307
+ type: "collection",
308
+ placeholder: "Add Field",
309
+ default: {},
310
+ displayOptions: { show: { resource: ["contact"], operation: ["update"] } },
311
+ options: [
312
+ {
313
+ displayName: "Email",
314
+ name: "email",
315
+ type: "string",
316
+ default: "",
317
+ placeholder: "name@email.com",
318
+ },
319
+ { displayName: "Name", name: "name", type: "string", default: "" },
320
+ { displayName: "Photo Path", name: "photo_path", type: "string", default: "" },
321
+ ],
322
+ },
323
+ // --- Delete ---
324
+ {
325
+ displayName: "Contact ID",
326
+ name: "contactId",
327
+ type: "string",
328
+ required: true,
329
+ default: "",
330
+ displayOptions: { show: { resource: ["contact"], operation: ["delete"] } },
331
+ description: "ID of the contact to delete",
332
+ },
333
+ // --- Get Many ---
334
+ {
335
+ displayName: "Additional Filters",
336
+ name: "filters",
337
+ type: "collection",
338
+ placeholder: "Add Filter",
339
+ default: {},
340
+ displayOptions: { show: { resource: ["contact"], operation: ["getMany"] } },
341
+ options: [
342
+ {
343
+ displayName: "Created At Order",
344
+ name: "created_at",
345
+ type: "options",
346
+ options: [
347
+ { name: "Ascending", value: "asc" },
348
+ { name: "Descending", value: "desc" },
349
+ ],
350
+ default: "desc",
351
+ },
352
+ { displayName: "Email", name: "email", type: "string", default: "" },
353
+ { displayName: "ID", name: "id", type: "string", default: "" },
354
+ {
355
+ displayName: "Limit",
356
+ name: "limit",
357
+ type: "number",
358
+ default: 10,
359
+ typeOptions: { minValue: 1 },
360
+ },
361
+ { displayName: "Name", name: "name", type: "string", default: "" },
362
+ { displayName: "Offset", name: "offset", type: "number", default: 0 },
363
+ ],
364
+ },
365
+ // ==================================================================
366
+ // MESSAGE fields
367
+ // ==================================================================
368
+ // --- Get Many ---
369
+ {
370
+ displayName: "Additional Filters",
371
+ name: "filters",
372
+ type: "collection",
373
+ placeholder: "Add Filter",
374
+ default: {},
375
+ displayOptions: { show: { resource: ["message"], operation: ["getMany"] } },
376
+ options: [
377
+ {
378
+ displayName: "Created At Order",
379
+ name: "created_at",
380
+ type: "options",
381
+ options: [
382
+ { name: "Ascending", value: "asc" },
383
+ { name: "Descending", value: "desc" },
384
+ ],
385
+ default: "desc",
386
+ },
387
+ { displayName: "From ID", name: "from_id", type: "string", default: "" },
388
+ { displayName: "ID", name: "id", type: "string", default: "" },
389
+ {
390
+ displayName: "Limit",
391
+ name: "limit",
392
+ type: "number",
393
+ default: 10,
394
+ typeOptions: { minValue: 1 },
395
+ },
396
+ {
397
+ displayName: "Messaging Product ID",
398
+ name: "messaging_product_id",
399
+ type: "string",
400
+ default: "",
401
+ },
402
+ { displayName: "Offset", name: "offset", type: "number", default: 0 },
403
+ { displayName: "To ID", name: "to_id", type: "string", default: "" },
404
+ ],
405
+ },
406
+ // --- Search by Content ---
407
+ {
408
+ displayName: "Search Text",
409
+ name: "likeText",
410
+ type: "string",
411
+ required: true,
412
+ default: "",
413
+ displayOptions: { show: { resource: ["message"], operation: ["searchByContent"] } },
414
+ description: "Text to search using ILIKE against message content fields",
415
+ },
416
+ {
417
+ displayName: "Additional Filters",
418
+ name: "filters",
419
+ type: "collection",
420
+ placeholder: "Add Filter",
421
+ default: {},
422
+ displayOptions: { show: { resource: ["message"], operation: ["searchByContent"] } },
423
+ options: [
424
+ {
425
+ displayName: "Limit",
426
+ name: "limit",
427
+ type: "number",
428
+ default: 10,
429
+ typeOptions: { minValue: 1 },
430
+ },
431
+ { displayName: "Offset", name: "offset", type: "number", default: 0 },
432
+ ],
433
+ },
434
+ // --- Send WhatsApp ---
435
+ {
436
+ displayName: "To ID (Messaging Product Contact ID)",
437
+ name: "toId",
438
+ type: "string",
439
+ required: true,
440
+ default: "",
441
+ displayOptions: { show: { resource: ["message"], operation: ["sendWhatsApp"] } },
442
+ description: "Messaging product contact ID to send the message to",
443
+ },
444
+ {
445
+ displayName: "Sender Data (JSON)",
446
+ name: "senderData",
447
+ type: "json",
448
+ required: true,
449
+ default: "{}",
450
+ displayOptions: { show: { resource: ["message"], operation: ["sendWhatsApp"] } },
451
+ description: "The WhatsApp message payload as JSON (follows the WhatsApp Cloud API message format)",
452
+ },
453
+ // --- Mark as Read ---
454
+ {
455
+ displayName: "Additional Filters",
456
+ name: "filters",
457
+ type: "collection",
458
+ placeholder: "Add Filter",
459
+ default: {},
460
+ displayOptions: {
461
+ show: { resource: ["message"], operation: ["markAsRead", "sendTyping"] },
462
+ },
463
+ options: [
464
+ { displayName: "From ID", name: "from_id", type: "string", default: "" },
465
+ { displayName: "ID", name: "id", type: "string", default: "" },
466
+ {
467
+ displayName: "Limit",
468
+ name: "limit",
469
+ type: "number",
470
+ default: 10,
471
+ typeOptions: { minValue: 1 },
472
+ },
473
+ {
474
+ displayName: "Messaging Product ID",
475
+ name: "messaging_product_id",
476
+ type: "string",
477
+ default: "",
478
+ },
479
+ { displayName: "Offset", name: "offset", type: "number", default: 0 },
480
+ { displayName: "To ID", name: "to_id", type: "string", default: "" },
481
+ ],
482
+ },
483
+ // ==================================================================
484
+ // MESSAGING PRODUCT fields
485
+ // ==================================================================
486
+ {
487
+ displayName: "Additional Filters",
488
+ name: "filters",
489
+ type: "collection",
490
+ placeholder: "Add Filter",
491
+ default: {},
492
+ displayOptions: {
493
+ show: { resource: ["messagingProduct"], operation: ["getMany"] },
494
+ },
495
+ options: [
496
+ { displayName: "ID", name: "id", type: "string", default: "" },
497
+ {
498
+ displayName: "Limit",
499
+ name: "limit",
500
+ type: "number",
501
+ default: 10,
502
+ typeOptions: { minValue: 1 },
503
+ },
504
+ {
505
+ displayName: "Name",
506
+ name: "name",
507
+ type: "options",
508
+ options: [{ name: "WhatsApp", value: "WhatsApp" }],
509
+ default: "WhatsApp",
510
+ },
511
+ { displayName: "Offset", name: "offset", type: "number", default: 0 },
512
+ ],
513
+ },
514
+ // ==================================================================
515
+ // MESSAGING PRODUCT CONTACT fields
516
+ // ==================================================================
517
+ // --- Get Many ---
518
+ {
519
+ displayName: "Additional Filters",
520
+ name: "filters",
521
+ type: "collection",
522
+ placeholder: "Add Filter",
523
+ default: {},
524
+ displayOptions: {
525
+ show: { resource: ["messagingProductContact"], operation: ["getMany"] },
526
+ },
527
+ options: [
528
+ { displayName: "Blocked", name: "blocked", type: "boolean", default: false },
529
+ { displayName: "Contact ID", name: "contact_id", type: "string", default: "" },
530
+ { displayName: "ID", name: "id", type: "string", default: "" },
531
+ {
532
+ displayName: "Limit",
533
+ name: "limit",
534
+ type: "number",
535
+ default: 10,
536
+ typeOptions: { minValue: 1 },
537
+ },
538
+ {
539
+ displayName: "Messaging Product ID",
540
+ name: "messaging_product_id",
541
+ type: "string",
542
+ default: "",
543
+ },
544
+ { displayName: "Offset", name: "offset", type: "number", default: 0 },
545
+ ],
546
+ },
547
+ // --- Get WhatsApp ---
548
+ {
549
+ displayName: "Additional Filters",
550
+ name: "filters",
551
+ type: "collection",
552
+ placeholder: "Add Filter",
553
+ default: {},
554
+ displayOptions: {
555
+ show: { resource: ["messagingProductContact"], operation: ["getWhatsApp"] },
556
+ },
557
+ options: [
558
+ { displayName: "Contact ID", name: "contact_id", type: "string", default: "" },
559
+ { displayName: "ID", name: "id", type: "string", default: "" },
560
+ {
561
+ displayName: "Limit",
562
+ name: "limit",
563
+ type: "number",
564
+ default: 10,
565
+ typeOptions: { minValue: 1 },
566
+ },
567
+ { displayName: "Offset", name: "offset", type: "number", default: 0 },
568
+ {
569
+ displayName: "Phone Number",
570
+ name: "phone_number",
571
+ type: "string",
572
+ default: "",
573
+ },
574
+ { displayName: "WA ID", name: "wa_id", type: "string", default: "" },
575
+ ],
576
+ },
577
+ // --- Search by Content ---
578
+ {
579
+ displayName: "Search Text",
580
+ name: "likeText",
581
+ type: "string",
582
+ required: true,
583
+ default: "",
584
+ displayOptions: {
585
+ show: { resource: ["messagingProductContact"], operation: ["searchByContent"] },
586
+ },
587
+ description: "Text to search using ILIKE against contact fields",
588
+ },
589
+ {
590
+ displayName: "Additional Filters",
591
+ name: "filters",
592
+ type: "collection",
593
+ placeholder: "Add Filter",
594
+ default: {},
595
+ displayOptions: {
596
+ show: { resource: ["messagingProductContact"], operation: ["searchByContent"] },
597
+ },
598
+ options: [
599
+ { displayName: "Blocked", name: "blocked", type: "boolean", default: false },
600
+ {
601
+ displayName: "Limit",
602
+ name: "limit",
603
+ type: "number",
604
+ default: 10,
605
+ typeOptions: { minValue: 1 },
606
+ },
607
+ { displayName: "Offset", name: "offset", type: "number", default: 0 },
608
+ ],
609
+ },
610
+ // --- Create ---
611
+ {
612
+ displayName: "Contact ID",
613
+ name: "contactId",
614
+ type: "string",
615
+ required: true,
616
+ default: "",
617
+ displayOptions: {
618
+ show: { resource: ["messagingProductContact"], operation: ["create"] },
619
+ },
620
+ description: "The contact ID to link",
621
+ },
622
+ {
623
+ displayName: "Messaging Product ID",
624
+ name: "messagingProductId",
625
+ type: "string",
626
+ required: true,
627
+ default: "",
628
+ displayOptions: {
629
+ show: { resource: ["messagingProductContact"], operation: ["create"] },
630
+ },
631
+ description: "The messaging product ID to associate with",
632
+ },
633
+ {
634
+ displayName: "Product Details (JSON)",
635
+ name: "productDetails",
636
+ type: "json",
637
+ default: "{}",
638
+ displayOptions: {
639
+ show: { resource: ["messagingProductContact"], operation: ["create"] },
640
+ },
641
+ description: "Product-specific details (phone_number, wa_id)",
642
+ },
643
+ // --- Create WhatsApp ---
644
+ {
645
+ displayName: "Contact ID",
646
+ name: "contactId",
647
+ type: "string",
648
+ required: true,
649
+ default: "",
650
+ displayOptions: {
651
+ show: { resource: ["messagingProductContact"], operation: ["createWhatsApp"] },
652
+ },
653
+ description: "The contact ID to link",
654
+ },
655
+ {
656
+ displayName: "Phone Number",
657
+ name: "phoneNumber",
658
+ type: "string",
659
+ default: "",
660
+ displayOptions: {
661
+ show: { resource: ["messagingProductContact"], operation: ["createWhatsApp"] },
662
+ },
663
+ description: "WhatsApp phone number",
664
+ },
665
+ {
666
+ displayName: "WA ID",
667
+ name: "waId",
668
+ type: "string",
669
+ default: "",
670
+ displayOptions: {
671
+ show: { resource: ["messagingProductContact"], operation: ["createWhatsApp"] },
672
+ },
673
+ description: "WhatsApp ID",
674
+ },
675
+ // --- Delete / Block / Unblock ---
676
+ {
677
+ displayName: "Messaging Product Contact ID",
678
+ name: "messagingProductContactId",
679
+ type: "string",
680
+ required: true,
681
+ default: "",
682
+ displayOptions: {
683
+ show: {
684
+ resource: ["messagingProductContact"],
685
+ operation: ["delete", "block", "unblock"],
686
+ },
687
+ },
688
+ description: "ID of the messaging product contact",
689
+ },
690
+ // ==================================================================
691
+ // MEDIA fields
692
+ // ==================================================================
693
+ {
694
+ displayName: "Media ID",
695
+ name: "mediaId",
696
+ type: "string",
697
+ required: true,
698
+ default: "",
699
+ displayOptions: {
700
+ show: { resource: ["media"], operation: ["download", "getInfo"] },
701
+ },
702
+ description: "The WhatsApp media ID",
703
+ },
704
+ // --- Upload ---
705
+ {
706
+ displayName: "Binary Property",
707
+ name: "binaryProperty",
708
+ type: "string",
709
+ required: true,
710
+ default: "data",
711
+ displayOptions: { show: { resource: ["media"], operation: ["upload"] } },
712
+ description: "Name of the binary property containing the file to upload",
713
+ },
714
+ {
715
+ displayName: "MIME Type",
716
+ name: "mimeType",
717
+ type: "string",
718
+ required: true,
719
+ default: "",
720
+ placeholder: "image/jpeg",
721
+ displayOptions: { show: { resource: ["media"], operation: ["upload"] } },
722
+ description: "MIME type of the media file",
723
+ },
724
+ // ==================================================================
725
+ // TEMPLATE fields
726
+ // ==================================================================
727
+ {
728
+ displayName: "Additional Filters",
729
+ name: "filters",
730
+ type: "collection",
731
+ placeholder: "Add Filter",
732
+ default: {},
733
+ displayOptions: { show: { resource: ["template"], operation: ["getMany"] } },
734
+ options: [
735
+ { displayName: "After (Cursor)", name: "after", type: "string", default: "" },
736
+ { displayName: "Before (Cursor)", name: "before", type: "string", default: "" },
737
+ {
738
+ displayName: "Category",
739
+ name: "category",
740
+ type: "options",
741
+ options: [
742
+ { name: "Account Update", value: "ACCOUNT_UPDATE" },
743
+ { name: "Alert Update", value: "ALERT_UPDATE" },
744
+ { name: "Appointment Update", value: "APPOINTMENT_UPDATE" },
745
+ { name: "Authentication", value: "AUTHENTICATION" },
746
+ { name: "Auto Reply", value: "AUTO_REPLY" },
747
+ { name: "Free Service", value: "FREE_SERVICE" },
748
+ { name: "Issue Resolution", value: "ISSUE_RESOLUTION" },
749
+ { name: "Marketing", value: "MARKETING" },
750
+ { name: "OTP", value: "OTP" },
751
+ { name: "Payment Update", value: "PAYMENT_UPDATE" },
752
+ { name: "Personal Finance Update", value: "PERSONAL_FINANCE_UPDATE" },
753
+ { name: "Reservation Update", value: "RESERVATION_UPDATE" },
754
+ { name: "Shipping Update", value: "SHIPPING_UPDATE" },
755
+ { name: "Ticket Update", value: "TICKET_UPDATE" },
756
+ { name: "Transactional", value: "TRANSACTIONAL" },
757
+ { name: "Transportation Update", value: "TRANSPORTATION_UPDATE" },
758
+ { name: "Utility", value: "UTILITY" },
759
+ ],
760
+ default: "MARKETING",
761
+ },
762
+ { displayName: "Content", name: "content", type: "string", default: "" },
763
+ { displayName: "Language", name: "language", type: "string", default: "" },
764
+ { displayName: "Limit", name: "limit", type: "number", default: 10 },
765
+ { displayName: "Name", name: "name", type: "string", default: "" },
766
+ {
767
+ displayName: "Name or Content",
768
+ name: "name_or_content",
769
+ type: "string",
770
+ default: "",
771
+ },
772
+ {
773
+ displayName: "Quality Score",
774
+ name: "quality_score",
775
+ type: "options",
776
+ options: [
777
+ { name: "Green", value: "GREEN" },
778
+ { name: "Red", value: "RED" },
779
+ { name: "Unknown", value: "UNKNOWN" },
780
+ { name: "Yellow", value: "YELLOW" },
781
+ ],
782
+ default: "GREEN",
783
+ },
784
+ {
785
+ displayName: "Status",
786
+ name: "status",
787
+ type: "options",
788
+ options: [
789
+ { name: "Approved", value: "APPROVED" },
790
+ { name: "Archived", value: "ARCHIVED" },
791
+ { name: "Deleted", value: "DELETED" },
792
+ { name: "Disabled", value: "DISABLED" },
793
+ { name: "In Appeal", value: "IN_APPEAL" },
794
+ { name: "Limit Exceeded", value: "LIMIT_EXCEEDED" },
795
+ { name: "Paused", value: "PAUSED" },
796
+ { name: "Pending", value: "PENDING" },
797
+ { name: "Pending Deletion", value: "PENDING_DELETION" },
798
+ { name: "Rejected", value: "REJECTED" },
799
+ ],
800
+ default: "APPROVED",
801
+ },
802
+ ],
803
+ },
804
+ ],
805
+ };
806
+ }
807
+ async execute() {
808
+ var _a;
809
+ const items = this.getInputData();
810
+ const returnData = [];
811
+ const resource = this.getNodeParameter("resource", 0);
812
+ const operation = this.getNodeParameter("operation", 0);
813
+ for (let i = 0; i < items.length; i++) {
814
+ try {
815
+ const workspaceIdOverride = this.getNodeParameter("workspaceIdOverride", i, "");
816
+ const wsId = workspaceIdOverride || undefined;
817
+ let responseData;
818
+ // ==============================================================
819
+ // CONTACT
820
+ // ==============================================================
821
+ if (resource === "contact") {
822
+ if (operation === "getMany") {
823
+ const filters = this.getNodeParameter("filters", i, {});
824
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", "/contact", undefined, filters, wsId);
825
+ }
826
+ else if (operation === "create") {
827
+ const body = {};
828
+ const name = this.getNodeParameter("name", i, "");
829
+ const email = this.getNodeParameter("email", i, "");
830
+ const photoPath = this.getNodeParameter("photoPath", i, "");
831
+ if (name)
832
+ body.name = name;
833
+ if (email)
834
+ body.email = email;
835
+ if (photoPath)
836
+ body.photo_path = photoPath;
837
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "POST", "/contact", body, {}, wsId);
838
+ }
839
+ else if (operation === "update") {
840
+ const contactId = this.getNodeParameter("contactId", i);
841
+ const updateFields = this.getNodeParameter("updateFields", i, {});
842
+ const body = { id: contactId, ...updateFields };
843
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "PUT", "/contact", body, {}, wsId);
844
+ }
845
+ else if (operation === "delete") {
846
+ const contactId = this.getNodeParameter("contactId", i);
847
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "DELETE", "/contact", { id: contactId }, {}, wsId);
848
+ }
849
+ }
850
+ // ==============================================================
851
+ // MESSAGE
852
+ // ==============================================================
853
+ else if (resource === "message") {
854
+ if (operation === "getMany") {
855
+ const filters = this.getNodeParameter("filters", i, {});
856
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", "/message", undefined, filters, wsId);
857
+ }
858
+ else if (operation === "searchByContent") {
859
+ const likeText = this.getNodeParameter("likeText", i);
860
+ const filters = this.getNodeParameter("filters", i, {});
861
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", `/message/content/like/${encodeURIComponent(likeText)}`, undefined, filters, wsId);
862
+ }
863
+ else if (operation === "sendWhatsApp") {
864
+ const toId = this.getNodeParameter("toId", i);
865
+ const senderDataRaw = this.getNodeParameter("senderData", i);
866
+ const senderData = typeof senderDataRaw === "string"
867
+ ? JSON.parse(senderDataRaw)
868
+ : senderDataRaw;
869
+ const body = {
870
+ to_id: toId,
871
+ sender_data: senderData,
872
+ };
873
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "POST", "/message/whatsapp", body, {}, wsId);
874
+ }
875
+ else if (operation === "markAsRead") {
876
+ const filters = this.getNodeParameter("filters", i, {});
877
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "POST", "/message/whatsapp/mark-as-read", undefined, filters, wsId);
878
+ }
879
+ else if (operation === "sendTyping") {
880
+ const filters = this.getNodeParameter("filters", i, {});
881
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "POST", "/message/whatsapp/send-typing", undefined, filters, wsId);
882
+ }
883
+ }
884
+ // ==============================================================
885
+ // MESSAGING PRODUCT
886
+ // ==============================================================
887
+ else if (resource === "messagingProduct") {
888
+ if (operation === "getMany") {
889
+ const filters = this.getNodeParameter("filters", i, {});
890
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", "/messaging-product", undefined, filters, wsId);
891
+ }
892
+ }
893
+ // ==============================================================
894
+ // MESSAGING PRODUCT CONTACT
895
+ // ==============================================================
896
+ else if (resource === "messagingProductContact") {
897
+ if (operation === "getMany") {
898
+ const filters = this.getNodeParameter("filters", i, {});
899
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", "/messaging-product/contact", undefined, filters, wsId);
900
+ }
901
+ else if (operation === "getWhatsApp") {
902
+ const filters = this.getNodeParameter("filters", i, {});
903
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", "/messaging-product/contact/whatsapp", undefined, filters, wsId);
904
+ }
905
+ else if (operation === "searchByContent") {
906
+ const likeText = this.getNodeParameter("likeText", i);
907
+ const filters = this.getNodeParameter("filters", i, {});
908
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", `/messaging-product/contact/content/like/${encodeURIComponent(likeText)}`, undefined, filters, wsId);
909
+ }
910
+ else if (operation === "create") {
911
+ const contactId = this.getNodeParameter("contactId", i);
912
+ const messagingProductId = this.getNodeParameter("messagingProductId", i);
913
+ const productDetailsRaw = this.getNodeParameter("productDetails", i, "{}");
914
+ const productDetails = typeof productDetailsRaw === "string"
915
+ ? JSON.parse(productDetailsRaw)
916
+ : productDetailsRaw;
917
+ const body = {
918
+ contact_id: contactId,
919
+ messaging_product_id: messagingProductId,
920
+ product_details: productDetails,
921
+ };
922
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "POST", "/messaging-product/contact", body, {}, wsId);
923
+ }
924
+ else if (operation === "createWhatsApp") {
925
+ const contactId = this.getNodeParameter("contactId", i);
926
+ const phoneNumber = this.getNodeParameter("phoneNumber", i, "");
927
+ const waId = this.getNodeParameter("waId", i, "");
928
+ const productDetails = {};
929
+ if (phoneNumber)
930
+ productDetails.phone_number = phoneNumber;
931
+ if (waId)
932
+ productDetails.wa_id = waId;
933
+ const body = {
934
+ contact_id: contactId,
935
+ product_details: productDetails,
936
+ };
937
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "POST", "/messaging-product/contact/whatsapp", body, {}, wsId);
938
+ }
939
+ else if (operation === "delete") {
940
+ const id = this.getNodeParameter("messagingProductContactId", i);
941
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "DELETE", "/messaging-product/contact", { id }, {}, wsId);
942
+ }
943
+ else if (operation === "block") {
944
+ const id = this.getNodeParameter("messagingProductContactId", i);
945
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "PATCH", "/messaging-product/contact/block", { id }, {}, wsId);
946
+ }
947
+ else if (operation === "unblock") {
948
+ const id = this.getNodeParameter("messagingProductContactId", i);
949
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "DELETE", "/messaging-product/contact/block", { id }, {}, wsId);
950
+ }
951
+ }
952
+ // ==============================================================
953
+ // MEDIA
954
+ // ==============================================================
955
+ else if (resource === "media") {
956
+ if (operation === "getInfo") {
957
+ const mediaId = this.getNodeParameter("mediaId", i);
958
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", `/media/whatsapp/${encodeURIComponent(mediaId)}`, undefined, {}, wsId);
959
+ }
960
+ else if (operation === "download") {
961
+ const mediaId = this.getNodeParameter("mediaId", i);
962
+ const credentials = await this.getCredentials("wacraftApi");
963
+ const baseUrl = credentials.baseUrl.replace(/\/+$/, "");
964
+ // We request the binary data directly
965
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, "wacraftApi", {
966
+ method: "GET",
967
+ url: `${baseUrl}/media/whatsapp/download/${encodeURIComponent(mediaId)}`,
968
+ encoding: "arraybuffer",
969
+ returnFullResponse: true,
970
+ json: false,
971
+ });
972
+ const binaryData = await this.helpers.prepareBinaryData(Buffer.from(response.body), undefined, (_a = response.headers) === null || _a === void 0 ? void 0 : _a["content-type"]);
973
+ returnData.push({
974
+ json: { mediaId },
975
+ binary: { data: binaryData },
976
+ });
977
+ continue;
978
+ }
979
+ else if (operation === "upload") {
980
+ const binaryProperty = this.getNodeParameter("binaryProperty", i);
981
+ const mimeType = this.getNodeParameter("mimeType", i);
982
+ const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
983
+ const credentials = await this.getCredentials("wacraftApi");
984
+ const baseUrl = credentials.baseUrl.replace(/\/+$/, "");
985
+ const workspaceId = wsId || credentials.workspaceId;
986
+ // Get a fresh token via a simple helper call
987
+ const tokenResponse = await this.helpers.httpRequest({
988
+ method: "POST",
989
+ url: `${baseUrl}/user/oauth/token`,
990
+ body: {
991
+ grant_type: "password",
992
+ username: credentials.username,
993
+ password: credentials.password,
994
+ },
995
+ json: true,
996
+ });
997
+ const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
998
+ const formData = new FormData();
999
+ formData.append("file", new Blob([dataBuffer], { type: mimeType }), binaryData.fileName || "file");
1000
+ formData.append("type", mimeType);
1001
+ responseData = await this.helpers.httpRequest({
1002
+ method: "POST",
1003
+ url: `${baseUrl}/media/whatsapp/upload`,
1004
+ body: formData,
1005
+ headers: {
1006
+ Authorization: `Bearer ${tokenResponse.access_token}`,
1007
+ ...(workspaceId ? { "X-Workspace-ID": workspaceId } : {}),
1008
+ },
1009
+ });
1010
+ }
1011
+ }
1012
+ // ==============================================================
1013
+ // TEMPLATE
1014
+ // ==============================================================
1015
+ else if (resource === "template") {
1016
+ if (operation === "getMany") {
1017
+ const filters = this.getNodeParameter("filters", i, {});
1018
+ responseData = await GenericFunctions_1.wacraftApiRequest.call(this, "GET", "/whatsapp-template", undefined, filters, wsId);
1019
+ }
1020
+ }
1021
+ // Normalize output
1022
+ if (responseData !== undefined) {
1023
+ if (Array.isArray(responseData)) {
1024
+ returnData.push(...responseData.map((item) => ({ json: item })));
1025
+ }
1026
+ else {
1027
+ returnData.push({ json: responseData });
1028
+ }
1029
+ }
1030
+ }
1031
+ catch (error) {
1032
+ if (this.continueOnFail()) {
1033
+ returnData.push({ json: { error: error.message } });
1034
+ continue;
1035
+ }
1036
+ throw error;
1037
+ }
1038
+ }
1039
+ return [returnData];
1040
+ }
1041
+ }
1042
+ exports.Wacraft = Wacraft;
1043
+ //# sourceMappingURL=Wacraft.node.js.map