@oficialapi/sdk 7.0.0 → 9.0.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.
- package/README.md +731 -29
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -341,32 +341,35 @@ await sdk.whatsapp.sendDocument({
|
|
|
341
341
|
|
|
342
342
|
#### Enviar Pedido com Opções de Pagamento
|
|
343
343
|
|
|
344
|
+
> **⚠️ Nota Importante:** O status do pedido deve ser `pending` ao usar `sendOrderDetails`. Use `sendOrderStatus` para atualizar o status após o pagamento.
|
|
345
|
+
|
|
346
|
+
**Exemplo 1: Pedido Digital com PIX**
|
|
347
|
+
|
|
344
348
|
```typescript
|
|
345
349
|
await sdk.whatsapp.sendOrderDetails({
|
|
346
|
-
token: '
|
|
350
|
+
token: 'sk_live_9999999999999999999999999',
|
|
347
351
|
sender: '5511999999999',
|
|
348
|
-
headerText: 'Confirmação de Pedido',
|
|
352
|
+
headerText: 'Confirmação de Pedido',
|
|
349
353
|
bodyText: 'Seu pedido #12345 está pronto para pagamento!',
|
|
350
|
-
footerText: 'Obrigado por comprar conosco!',
|
|
351
|
-
reference_id: 'pedido_12345_1704067200',
|
|
352
|
-
type: 'digital-goods',
|
|
354
|
+
footerText: 'Obrigado por comprar conosco!',
|
|
355
|
+
reference_id: 'pedido_12345_1704067200',
|
|
356
|
+
type: 'digital-goods',
|
|
353
357
|
currency: 'BRL',
|
|
354
358
|
total_amount: {
|
|
355
|
-
value: 50000,
|
|
356
|
-
offset: 100
|
|
357
|
-
description: 'Total do pedido' // Opcional
|
|
359
|
+
value: 50000,
|
|
360
|
+
offset: 100
|
|
358
361
|
},
|
|
359
362
|
order: {
|
|
360
|
-
status: 'pending',
|
|
363
|
+
status: 'pending', // OBRIGATÓRIO: deve ser 'pending' para review_and_pay
|
|
361
364
|
items: [
|
|
362
365
|
{
|
|
363
366
|
retailer_id: '1234567',
|
|
364
|
-
name: '
|
|
367
|
+
name: 'Cake',
|
|
365
368
|
amount: {
|
|
366
369
|
value: 50000,
|
|
367
370
|
offset: 100
|
|
368
371
|
},
|
|
369
|
-
quantity:
|
|
372
|
+
quantity: 1
|
|
370
373
|
}
|
|
371
374
|
],
|
|
372
375
|
subtotal: {
|
|
@@ -377,39 +380,248 @@ await sdk.whatsapp.sendOrderDetails({
|
|
|
377
380
|
value: 0,
|
|
378
381
|
offset: 100,
|
|
379
382
|
description: 'Sem impostos'
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
payment_settings: [
|
|
386
|
+
{
|
|
387
|
+
type: 'pix_dynamic_code',
|
|
388
|
+
pix_dynamic_code: {
|
|
389
|
+
code: '00020101021226700014br.gov.bcb.pix2548pix.example.com...',
|
|
390
|
+
merchant_name: 'Minha Empresa Ltda',
|
|
391
|
+
key: '39580525000189',
|
|
392
|
+
key_type: 'CNPJ'
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
]
|
|
396
|
+
}, accessToken);
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
**Exemplo 2: Pedido Digital com Link de Pagamento**
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
await sdk.whatsapp.sendOrderDetails({
|
|
403
|
+
token: 'sk_live_9999999999999999999999999',
|
|
404
|
+
sender: '5511999999999',
|
|
405
|
+
bodyText: 'Sua fatura está disponível para pagamento!',
|
|
406
|
+
reference_id: 'fatura_67890_1704067200',
|
|
407
|
+
type: 'digital-goods',
|
|
408
|
+
currency: 'BRL',
|
|
409
|
+
total_amount: {
|
|
410
|
+
value: 150000,
|
|
411
|
+
offset: 100
|
|
412
|
+
},
|
|
413
|
+
order: {
|
|
414
|
+
status: 'pending',
|
|
415
|
+
items: [
|
|
416
|
+
{
|
|
417
|
+
retailer_id: 'item_001',
|
|
418
|
+
name: 'Serviço Premium',
|
|
419
|
+
amount: {
|
|
420
|
+
value: 150000,
|
|
421
|
+
offset: 100
|
|
422
|
+
},
|
|
423
|
+
quantity: 1
|
|
424
|
+
}
|
|
425
|
+
],
|
|
426
|
+
subtotal: {
|
|
427
|
+
value: 150000,
|
|
428
|
+
offset: 100
|
|
380
429
|
},
|
|
381
|
-
|
|
382
|
-
value:
|
|
383
|
-
offset: 100
|
|
384
|
-
|
|
430
|
+
tax: {
|
|
431
|
+
value: 0,
|
|
432
|
+
offset: 100
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
payment_settings: [
|
|
436
|
+
{
|
|
437
|
+
type: 'payment_link',
|
|
438
|
+
payment_link: {
|
|
439
|
+
uri: 'https://pagamento.exemplo.com/fatura/67890'
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
]
|
|
443
|
+
}, accessToken);
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
**Exemplo 3: Pedido Digital com Boleto**
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
await sdk.whatsapp.sendOrderDetails({
|
|
450
|
+
token: 'sk_live_9999999999999999999999999',
|
|
451
|
+
sender: '5511999999999',
|
|
452
|
+
bodyText: 'Sua inscrição está confirmada! Efetue o pagamento via boleto.',
|
|
453
|
+
reference_id: 'inscricao_11111_1704067200',
|
|
454
|
+
type: 'digital-goods',
|
|
455
|
+
currency: 'BRL',
|
|
456
|
+
total_amount: {
|
|
457
|
+
value: 29900,
|
|
458
|
+
offset: 100
|
|
459
|
+
},
|
|
460
|
+
order: {
|
|
461
|
+
status: 'pending',
|
|
462
|
+
items: [
|
|
463
|
+
{
|
|
464
|
+
retailer_id: 'curso_001',
|
|
465
|
+
name: 'Curso de Programação',
|
|
466
|
+
amount: {
|
|
467
|
+
value: 29900,
|
|
468
|
+
offset: 100
|
|
469
|
+
},
|
|
470
|
+
quantity: 1
|
|
471
|
+
}
|
|
472
|
+
],
|
|
473
|
+
subtotal: {
|
|
474
|
+
value: 29900,
|
|
475
|
+
offset: 100
|
|
385
476
|
},
|
|
386
|
-
|
|
387
|
-
value:
|
|
477
|
+
tax: {
|
|
478
|
+
value: 0,
|
|
479
|
+
offset: 100
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
payment_settings: [
|
|
483
|
+
{
|
|
484
|
+
type: 'boleto',
|
|
485
|
+
boleto: {
|
|
486
|
+
digitable_line: '03399026944140000002628346101018898510000008848'
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
]
|
|
490
|
+
}, accessToken);
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
**Exemplo 4: Pedido Físico com Múltiplas Formas de Pagamento (PIX + Link)**
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
await sdk.whatsapp.sendOrderDetails({
|
|
497
|
+
token: 'sk_live_9999999999999999999999999',
|
|
498
|
+
sender: '5511999999999',
|
|
499
|
+
bodyText: 'Seu pedido está pronto! Escolha a forma de pagamento:',
|
|
500
|
+
reference_id: 'pedido_completo_22222_1704067200',
|
|
501
|
+
type: 'physical-goods',
|
|
502
|
+
currency: 'BRL',
|
|
503
|
+
total_amount: {
|
|
504
|
+
value: 262400, // subtotal (259900) + tax (0) + shipping (2500) - discount (0)
|
|
505
|
+
offset: 100
|
|
506
|
+
},
|
|
507
|
+
order: {
|
|
508
|
+
status: 'pending',
|
|
509
|
+
catalog_id: '1234567890',
|
|
510
|
+
items: [
|
|
511
|
+
{
|
|
512
|
+
retailer_id: 'produto_001',
|
|
513
|
+
name: 'Camiseta Básica',
|
|
514
|
+
amount: {
|
|
515
|
+
value: 79000,
|
|
516
|
+
offset: 100
|
|
517
|
+
},
|
|
518
|
+
quantity: 2
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
retailer_id: 'produto_002',
|
|
522
|
+
name: 'Calça Jeans',
|
|
523
|
+
amount: {
|
|
524
|
+
value: 101900,
|
|
525
|
+
offset: 100
|
|
526
|
+
},
|
|
527
|
+
quantity: 1
|
|
528
|
+
}
|
|
529
|
+
],
|
|
530
|
+
subtotal: {
|
|
531
|
+
value: 259900,
|
|
532
|
+
offset: 100
|
|
533
|
+
},
|
|
534
|
+
tax: {
|
|
535
|
+
value: 0,
|
|
536
|
+
offset: 100
|
|
537
|
+
},
|
|
538
|
+
shipping: {
|
|
539
|
+
value: 2500,
|
|
388
540
|
offset: 100,
|
|
389
|
-
description: '
|
|
390
|
-
discount_program_name: 'Promoção'
|
|
541
|
+
description: 'Frete via SEDEX'
|
|
391
542
|
}
|
|
392
543
|
},
|
|
393
|
-
payment_settings: [
|
|
544
|
+
payment_settings: [
|
|
394
545
|
{
|
|
395
546
|
type: 'pix_dynamic_code',
|
|
396
547
|
pix_dynamic_code: {
|
|
397
548
|
code: '00020101021226700014br.gov.bcb.pix2548pix.example.com...',
|
|
398
|
-
merchant_name: 'Minha
|
|
399
|
-
key: '
|
|
400
|
-
key_type: '
|
|
549
|
+
merchant_name: 'Minha Loja Virtual',
|
|
550
|
+
key: 'minhaloja@email.com',
|
|
551
|
+
key_type: 'EMAIL'
|
|
401
552
|
}
|
|
402
553
|
},
|
|
403
554
|
{
|
|
404
555
|
type: 'payment_link',
|
|
405
556
|
payment_link: {
|
|
406
|
-
uri: 'https://
|
|
557
|
+
uri: 'https://minhaloja.com/pagar/22222'
|
|
407
558
|
}
|
|
408
559
|
}
|
|
409
560
|
]
|
|
410
561
|
}, accessToken);
|
|
411
562
|
```
|
|
412
563
|
|
|
564
|
+
**Exemplo 5: Pedido com Desconto (Black Friday)**
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
await sdk.whatsapp.sendOrderDetails({
|
|
568
|
+
token: 'sk_live_9999999999999999999999999',
|
|
569
|
+
sender: '5511999999999',
|
|
570
|
+
bodyText: 'Black Friday! Seu pedido com desconto especial:',
|
|
571
|
+
reference_id: 'black_friday_33333_1704067200',
|
|
572
|
+
type: 'digital-goods',
|
|
573
|
+
currency: 'BRL',
|
|
574
|
+
total_amount: {
|
|
575
|
+
value: 39900, // subtotal (49900) + tax (0) + shipping (0) - discount (10000)
|
|
576
|
+
offset: 100
|
|
577
|
+
},
|
|
578
|
+
order: {
|
|
579
|
+
status: 'pending',
|
|
580
|
+
items: [
|
|
581
|
+
{
|
|
582
|
+
retailer_id: 'bf_001',
|
|
583
|
+
name: 'Pacote Premium',
|
|
584
|
+
amount: {
|
|
585
|
+
value: 49900,
|
|
586
|
+
offset: 100
|
|
587
|
+
},
|
|
588
|
+
quantity: 1
|
|
589
|
+
}
|
|
590
|
+
],
|
|
591
|
+
subtotal: {
|
|
592
|
+
value: 49900,
|
|
593
|
+
offset: 100
|
|
594
|
+
},
|
|
595
|
+
tax: {
|
|
596
|
+
value: 0,
|
|
597
|
+
offset: 100
|
|
598
|
+
},
|
|
599
|
+
discount: {
|
|
600
|
+
value: 10000,
|
|
601
|
+
offset: 100,
|
|
602
|
+
description: 'Desconto Black Friday 20%',
|
|
603
|
+
discount_program_name: 'Black Friday 2024'
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
payment_settings: [
|
|
607
|
+
{
|
|
608
|
+
type: 'pix_dynamic_code',
|
|
609
|
+
pix_dynamic_code: {
|
|
610
|
+
code: '00020101021226700014br.gov.bcb.pix2548pix.example.com...',
|
|
611
|
+
merchant_name: 'Black Friday Loja',
|
|
612
|
+
key: '5511999999999',
|
|
613
|
+
key_type: 'PHONE'
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
]
|
|
617
|
+
}, accessToken);
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
**Importante:**
|
|
621
|
+
- O `total_amount.value` deve ser igual a: `subtotal + tax + shipping - discount`
|
|
622
|
+
- O status do pedido deve ser `pending` ao usar `sendOrderDetails`
|
|
623
|
+
- Use `sendOrderStatus` para atualizar o status após o pagamento
|
|
624
|
+
|
|
413
625
|
#### Atualizar Status do Pedido
|
|
414
626
|
|
|
415
627
|
```typescript
|
|
@@ -556,16 +768,506 @@ await sdk.whatsapp.createTemplate({
|
|
|
556
768
|
]
|
|
557
769
|
}, accessToken);
|
|
558
770
|
|
|
559
|
-
|
|
560
|
-
|
|
771
|
+
#### Upload de Mídia
|
|
772
|
+
|
|
773
|
+
O método `uploadMedia` é usado para fazer upload de arquivos (imagens, vídeos, áudios, documentos) que serão usados em templates ou enviados via `sendAudio`, `sendVideo`, `sendDocument` ou `sendSticker`.
|
|
774
|
+
|
|
775
|
+
**Exemplo 1: Upload de imagem sem filename (opcional)**
|
|
776
|
+
|
|
777
|
+
```typescript
|
|
778
|
+
// Em ambiente Node.js
|
|
779
|
+
import fs from 'fs';
|
|
780
|
+
|
|
781
|
+
const fileBuffer = fs.readFileSync('./imagem.jpg');
|
|
782
|
+
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
783
|
+
token: 'sk_live_...',
|
|
784
|
+
file: fileBuffer
|
|
785
|
+
// filename é opcional - não será enviado se não fornecido
|
|
786
|
+
}, accessToken);
|
|
787
|
+
|
|
788
|
+
const mediaId = uploadResult.data.handle; // "4::aW1hZ2UtMTIzNDU2Nzg5MGCE..."
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
**Exemplo 2: Upload de imagem com filename**
|
|
792
|
+
|
|
793
|
+
```typescript
|
|
794
|
+
// Em ambiente Node.js
|
|
795
|
+
import fs from 'fs';
|
|
796
|
+
|
|
797
|
+
const fileBuffer = fs.readFileSync('./imagem.jpg');
|
|
798
|
+
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
799
|
+
token: 'sk_live_...',
|
|
800
|
+
file: fileBuffer,
|
|
801
|
+
filename: 'minha_imagem.jpg' // Opcional: nome do arquivo
|
|
802
|
+
}, accessToken);
|
|
803
|
+
|
|
804
|
+
const mediaId = uploadResult.data.handle;
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
**Exemplo 3: Upload de vídeo (Node.js)**
|
|
808
|
+
|
|
809
|
+
```typescript
|
|
810
|
+
import fs from 'fs';
|
|
811
|
+
|
|
812
|
+
const videoBuffer = fs.readFileSync('./video.mp4');
|
|
813
|
+
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
814
|
+
token: 'sk_live_...',
|
|
815
|
+
file: videoBuffer,
|
|
816
|
+
filename: 'meu_video.mp4'
|
|
817
|
+
}, accessToken);
|
|
818
|
+
|
|
819
|
+
// Use o mediaId para enviar o vídeo
|
|
820
|
+
await sdk.whatsapp.sendVideo({
|
|
821
|
+
token: 'sk_live_...',
|
|
822
|
+
sender: '5511999999999',
|
|
823
|
+
mediaId: uploadResult.data.handle,
|
|
824
|
+
caption: 'Confira este vídeo!'
|
|
825
|
+
}, accessToken);
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
**Exemplo 4: Upload de documento PDF (Node.js)**
|
|
829
|
+
|
|
830
|
+
```typescript
|
|
831
|
+
import fs from 'fs';
|
|
832
|
+
|
|
833
|
+
const pdfBuffer = fs.readFileSync('./documento.pdf');
|
|
834
|
+
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
835
|
+
token: 'sk_live_...',
|
|
836
|
+
file: pdfBuffer,
|
|
837
|
+
filename: 'documento_importante.pdf'
|
|
838
|
+
}, accessToken);
|
|
839
|
+
|
|
840
|
+
// Use o mediaId para enviar o documento
|
|
841
|
+
await sdk.whatsapp.sendDocument({
|
|
842
|
+
token: 'sk_live_...',
|
|
843
|
+
sender: '5511999999999',
|
|
844
|
+
mediaId: uploadResult.data.handle,
|
|
845
|
+
filename: 'documento_importante.pdf',
|
|
846
|
+
caption: 'Aqui está o documento solicitado'
|
|
847
|
+
}, accessToken);
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
**Exemplo 5: Upload de áudio (Node.js)**
|
|
851
|
+
|
|
852
|
+
```typescript
|
|
853
|
+
import fs from 'fs';
|
|
854
|
+
|
|
855
|
+
const audioBuffer = fs.readFileSync('./audio.ogg');
|
|
856
|
+
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
857
|
+
token: 'sk_live_...',
|
|
858
|
+
file: audioBuffer,
|
|
859
|
+
filename: 'mensagem_audio.ogg'
|
|
860
|
+
}, accessToken);
|
|
861
|
+
|
|
862
|
+
// Use o mediaId para enviar o áudio
|
|
863
|
+
await sdk.whatsapp.sendAudio({
|
|
864
|
+
token: 'sk_live_...',
|
|
865
|
+
sender: '5511999999999',
|
|
866
|
+
mediaId: uploadResult.data.handle,
|
|
867
|
+
voice: true // true para mensagem de voz
|
|
868
|
+
}, accessToken);
|
|
869
|
+
```
|
|
870
|
+
|
|
871
|
+
**Exemplo 6: Upload de sticker (Node.js)**
|
|
872
|
+
|
|
873
|
+
```typescript
|
|
874
|
+
import fs from 'fs';
|
|
875
|
+
|
|
876
|
+
const stickerBuffer = fs.readFileSync('./sticker.webp');
|
|
877
|
+
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
878
|
+
token: 'sk_live_...',
|
|
879
|
+
file: stickerBuffer,
|
|
880
|
+
filename: 'sticker.webp'
|
|
881
|
+
}, accessToken);
|
|
882
|
+
|
|
883
|
+
// Use o mediaId para enviar o sticker
|
|
884
|
+
await sdk.whatsapp.sendSticker({
|
|
885
|
+
token: 'sk_live_...',
|
|
886
|
+
sender: '5511999999999',
|
|
887
|
+
mediaId: uploadResult.data.handle
|
|
888
|
+
}, accessToken);
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
**Exemplo 7: Upload em ambiente Browser (Frontend)**
|
|
892
|
+
|
|
893
|
+
```typescript
|
|
894
|
+
// Em ambiente Browser
|
|
895
|
+
const fileInput = document.querySelector('input[type="file"]');
|
|
896
|
+
const file = fileInput.files[0];
|
|
897
|
+
|
|
561
898
|
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
562
899
|
token: 'sk_live_...',
|
|
563
900
|
file: file,
|
|
564
|
-
filename:
|
|
901
|
+
filename: file.name // Opcional
|
|
902
|
+
}, accessToken);
|
|
903
|
+
|
|
904
|
+
const mediaId = uploadResult.data.handle;
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
**Exemplo 8: Upload usando Blob (Browser)**
|
|
908
|
+
|
|
909
|
+
```typescript
|
|
910
|
+
// Criar um Blob a partir de dados
|
|
911
|
+
const blob = new Blob(['conteúdo do arquivo'], { type: 'text/plain' });
|
|
912
|
+
|
|
913
|
+
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
914
|
+
token: 'sk_live_...',
|
|
915
|
+
file: blob,
|
|
916
|
+
filename: 'arquivo.txt'
|
|
917
|
+
}, accessToken);
|
|
918
|
+
|
|
919
|
+
const mediaId = uploadResult.data.handle;
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
**Exemplo 9: Upload para usar em template**
|
|
923
|
+
|
|
924
|
+
```typescript
|
|
925
|
+
import fs from 'fs';
|
|
926
|
+
|
|
927
|
+
// Upload da imagem para usar no header do template
|
|
928
|
+
const imageBuffer = fs.readFileSync('./logo.jpg');
|
|
929
|
+
const uploadResult = await sdk.whatsapp.uploadMedia({
|
|
930
|
+
token: 'sk_live_...',
|
|
931
|
+
file: imageBuffer
|
|
932
|
+
// filename não é necessário para templates
|
|
933
|
+
}, accessToken);
|
|
934
|
+
|
|
935
|
+
// Use o handle no template
|
|
936
|
+
await sdk.whatsapp.createTemplate({
|
|
937
|
+
token: 'sk_live_...',
|
|
938
|
+
name: 'product_launch',
|
|
939
|
+
category: 'MARKETING',
|
|
940
|
+
language: 'pt_BR',
|
|
941
|
+
components: [
|
|
942
|
+
{
|
|
943
|
+
type: 'HEADER',
|
|
944
|
+
format: 'IMAGE',
|
|
945
|
+
example: {
|
|
946
|
+
header_handle: [uploadResult.data.handle] // Use o handle aqui
|
|
947
|
+
}
|
|
948
|
+
},
|
|
949
|
+
{
|
|
950
|
+
type: 'BODY',
|
|
951
|
+
text: 'Confira nosso novo produto!'
|
|
952
|
+
}
|
|
953
|
+
]
|
|
954
|
+
}, accessToken);
|
|
955
|
+
```
|
|
956
|
+
|
|
957
|
+
**Notas importantes:**
|
|
958
|
+
- O parâmetro `filename` é **opcional**. Se não fornecido, não será enviado ao servidor (a API da OficialAPI rejeita campos vazios).
|
|
959
|
+
- O `mediaId` retornado está no formato `"4::aW1hZ2UtMTIzNDU2Nzg5MGCE..."` e deve ser usado diretamente nos métodos `sendAudio`, `sendVideo`, `sendDocument` ou `sendSticker`.
|
|
960
|
+
- Para templates, use o `handle` retornado no campo `header_handle` ou `example.header_handle`.
|
|
961
|
+
- Formatos suportados:
|
|
962
|
+
- **Imagens**: JPG, PNG, GIF, WEBP
|
|
963
|
+
- **Vídeos**: MP4, 3GP
|
|
964
|
+
- **Áudios**: OGG (codec OPUS para voz), MP3, M4A
|
|
965
|
+
- **Documentos**: PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX
|
|
966
|
+
- **Stickers**: WEBP (até 500KB para animado, 100KB para estático)
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
**Mais exemplos de templates:**
|
|
970
|
+
|
|
971
|
+
```typescript
|
|
972
|
+
// Template de atualização de envio (UTILITY)
|
|
973
|
+
await sdk.whatsapp.createTemplate({
|
|
974
|
+
token: 'sk_live_01JABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
975
|
+
name: 'shipping_update',
|
|
976
|
+
category: 'UTILITY',
|
|
977
|
+
language: 'pt_BR',
|
|
978
|
+
components: [
|
|
979
|
+
{
|
|
980
|
+
type: 'BODY',
|
|
981
|
+
text: 'Ótima notícia! Seu pedido com código #{{1}} já está a caminho. Use o código de rastreio {{2}} para acompanhar.',
|
|
982
|
+
example: {
|
|
983
|
+
body_text: [
|
|
984
|
+
['ORD12345', 'BR123456789']
|
|
985
|
+
]
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
{
|
|
989
|
+
type: 'BUTTONS',
|
|
990
|
+
buttons: [
|
|
991
|
+
{
|
|
992
|
+
type: 'URL',
|
|
993
|
+
text: 'Rastrear',
|
|
994
|
+
url: 'https://rastreio.com/track/{{1}}',
|
|
995
|
+
example: ['ORD12345']
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
type: 'QUICK_REPLY',
|
|
999
|
+
text: 'Entendido'
|
|
1000
|
+
}
|
|
1001
|
+
]
|
|
1002
|
+
}
|
|
1003
|
+
],
|
|
1004
|
+
allow_category_change: false
|
|
1005
|
+
}, accessToken);
|
|
1006
|
+
|
|
1007
|
+
// Template de promoção sazonal (MARKETING)
|
|
1008
|
+
await sdk.whatsapp.createTemplate({
|
|
1009
|
+
token: 'sk_live_01JABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
1010
|
+
name: 'seasonal_promotion',
|
|
1011
|
+
category: 'MARKETING',
|
|
1012
|
+
language: 'en_US',
|
|
1013
|
+
components: [
|
|
1014
|
+
{
|
|
1015
|
+
type: 'HEADER',
|
|
1016
|
+
format: 'TEXT',
|
|
1017
|
+
text: 'Our {{1}} is on!',
|
|
1018
|
+
example: {
|
|
1019
|
+
header_text: ['Summer Sale']
|
|
1020
|
+
}
|
|
1021
|
+
},
|
|
1022
|
+
{
|
|
1023
|
+
type: 'BODY',
|
|
1024
|
+
text: 'Shop now through {{1}} and use code {{2}} to get {{3}} off all merchandise.',
|
|
1025
|
+
example: {
|
|
1026
|
+
body_text: [
|
|
1027
|
+
['the end of August', '25OFF', '25%']
|
|
1028
|
+
]
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
type: 'FOOTER',
|
|
1033
|
+
text: 'Use the buttons below to manage your marketing subscriptions'
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
type: 'BUTTONS',
|
|
1037
|
+
buttons: [
|
|
1038
|
+
{
|
|
1039
|
+
type: 'QUICK_REPLY',
|
|
1040
|
+
text: 'Unsubscribe from Promos'
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
type: 'QUICK_REPLY',
|
|
1044
|
+
text: 'Unsubscribe from All'
|
|
1045
|
+
}
|
|
1046
|
+
]
|
|
1047
|
+
}
|
|
1048
|
+
],
|
|
1049
|
+
allow_category_change: true
|
|
1050
|
+
}, accessToken);
|
|
1051
|
+
|
|
1052
|
+
// Template com documento PDF (UTILITY)
|
|
1053
|
+
await sdk.whatsapp.createTemplate({
|
|
1054
|
+
token: 'sk_live_01JABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
1055
|
+
name: 'order_confirmation_pdf',
|
|
1056
|
+
category: 'UTILITY',
|
|
1057
|
+
language: 'en_US',
|
|
1058
|
+
components: [
|
|
1059
|
+
{
|
|
1060
|
+
type: 'HEADER',
|
|
1061
|
+
format: 'DOCUMENT',
|
|
1062
|
+
example: {
|
|
1063
|
+
header_handle: ['4::aW1hZ2UtMTIzNDU2Nzg5MGCE...'],
|
|
1064
|
+
header_text: ['order_receipt.pdf']
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
{
|
|
1068
|
+
type: 'BODY',
|
|
1069
|
+
text: 'Thank you for your order, {{1}}! Your order number is {{2}}. Tap the PDF linked above to view your receipt.',
|
|
1070
|
+
example: {
|
|
1071
|
+
body_text: [
|
|
1072
|
+
['Pablo', '860198-230332']
|
|
1073
|
+
]
|
|
1074
|
+
}
|
|
1075
|
+
},
|
|
1076
|
+
{
|
|
1077
|
+
type: 'BUTTONS',
|
|
1078
|
+
buttons: [
|
|
1079
|
+
{
|
|
1080
|
+
type: 'PHONE_NUMBER',
|
|
1081
|
+
text: 'Call Support',
|
|
1082
|
+
phone_number: '15550051310'
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
type: 'URL',
|
|
1086
|
+
text: 'Contact Support',
|
|
1087
|
+
url: 'https://www.luckyshrub.com/support'
|
|
1088
|
+
}
|
|
1089
|
+
]
|
|
1090
|
+
}
|
|
1091
|
+
],
|
|
1092
|
+
allow_category_change: false
|
|
565
1093
|
}, accessToken);
|
|
566
1094
|
|
|
567
|
-
//
|
|
568
|
-
|
|
1095
|
+
// Template de lançamento de produto com imagem (MARKETING)
|
|
1096
|
+
await sdk.whatsapp.createTemplate({
|
|
1097
|
+
token: 'sk_live_01JABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
1098
|
+
name: 'product_launch',
|
|
1099
|
+
category: 'MARKETING',
|
|
1100
|
+
language: 'pt_BR',
|
|
1101
|
+
components: [
|
|
1102
|
+
{
|
|
1103
|
+
type: 'HEADER',
|
|
1104
|
+
format: 'IMAGE',
|
|
1105
|
+
example: {
|
|
1106
|
+
header_handle: ['4::aW1hZ2UtMTIzNDU2Nzg5MGCE...']
|
|
1107
|
+
}
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
type: 'BODY',
|
|
1111
|
+
text: 'Olá {{1}}! Nossa nova coleção {{2}} já está disponível!',
|
|
1112
|
+
example: {
|
|
1113
|
+
body_text: [
|
|
1114
|
+
['Maria', 'Verão 2025']
|
|
1115
|
+
]
|
|
1116
|
+
}
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
type: 'BUTTONS',
|
|
1120
|
+
buttons: [
|
|
1121
|
+
{
|
|
1122
|
+
type: 'URL',
|
|
1123
|
+
text: 'Ver coleção',
|
|
1124
|
+
url: 'https://loja.com/colecao'
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
type: 'QUICK_REPLY',
|
|
1128
|
+
text: 'Compartilhar'
|
|
1129
|
+
}
|
|
1130
|
+
]
|
|
1131
|
+
}
|
|
1132
|
+
],
|
|
1133
|
+
allow_category_change: true
|
|
1134
|
+
}, accessToken);
|
|
1135
|
+
|
|
1136
|
+
// Template de cupom promocional (MARKETING)
|
|
1137
|
+
await sdk.whatsapp.createTemplate({
|
|
1138
|
+
token: 'sk_live_01JABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
1139
|
+
name: 'coupon_promo',
|
|
1140
|
+
category: 'MARKETING',
|
|
1141
|
+
language: 'pt_BR',
|
|
1142
|
+
components: [
|
|
1143
|
+
{
|
|
1144
|
+
type: 'HEADER',
|
|
1145
|
+
format: 'TEXT',
|
|
1146
|
+
text: '🎉 Oferta Especial!'
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
type: 'BODY',
|
|
1150
|
+
text: 'Olá {{1}}! Use o código abaixo para get {{2}} de desconto em toda a loja.',
|
|
1151
|
+
example: {
|
|
1152
|
+
body_text: [
|
|
1153
|
+
['Maria', '25%']
|
|
1154
|
+
]
|
|
1155
|
+
}
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
type: 'BUTTONS',
|
|
1159
|
+
buttons: [
|
|
1160
|
+
{
|
|
1161
|
+
type: 'COPY_CODE',
|
|
1162
|
+
text: 'Copiar código',
|
|
1163
|
+
example: 'SUMMER25'
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
type: 'URL',
|
|
1167
|
+
text: 'Ver loja',
|
|
1168
|
+
url: 'https://loja.com'
|
|
1169
|
+
}
|
|
1170
|
+
]
|
|
1171
|
+
}
|
|
1172
|
+
],
|
|
1173
|
+
allow_category_change: true
|
|
1174
|
+
}, accessToken);
|
|
1175
|
+
|
|
1176
|
+
// Template com parâmetros nomeados (UTILITY)
|
|
1177
|
+
await sdk.whatsapp.createTemplate({
|
|
1178
|
+
token: 'sk_live_01JABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
1179
|
+
name: 'order_confirmation',
|
|
1180
|
+
category: 'UTILITY',
|
|
1181
|
+
language: 'en_US',
|
|
1182
|
+
components: [
|
|
1183
|
+
{
|
|
1184
|
+
type: 'BODY',
|
|
1185
|
+
text: 'Thank you, {{first_name}}! Your order number is {{order_number}}.',
|
|
1186
|
+
example: {
|
|
1187
|
+
body_text_named_params: [
|
|
1188
|
+
{
|
|
1189
|
+
param_name: 'first_name',
|
|
1190
|
+
example: 'Pablo'
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
param_name: 'order_number',
|
|
1194
|
+
example: '860198-230332'
|
|
1195
|
+
}
|
|
1196
|
+
]
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
],
|
|
1200
|
+
allow_category_change: false
|
|
1201
|
+
}, accessToken);
|
|
1202
|
+
|
|
1203
|
+
// Template de atualização de entrega com localização (UTILITY)
|
|
1204
|
+
await sdk.whatsapp.createTemplate({
|
|
1205
|
+
token: 'sk_live_01JABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
1206
|
+
name: 'order_delivery_update',
|
|
1207
|
+
category: 'UTILITY',
|
|
1208
|
+
language: 'en_US',
|
|
1209
|
+
components: [
|
|
1210
|
+
{
|
|
1211
|
+
type: 'HEADER',
|
|
1212
|
+
format: 'LOCATION'
|
|
1213
|
+
},
|
|
1214
|
+
{
|
|
1215
|
+
type: 'BODY',
|
|
1216
|
+
text: 'Good news {{1}}! Your order #{{2}} is on its way to the location above.',
|
|
1217
|
+
example: {
|
|
1218
|
+
body_text: [
|
|
1219
|
+
['Mark', '566701']
|
|
1220
|
+
]
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
{
|
|
1224
|
+
type: 'FOOTER',
|
|
1225
|
+
text: 'To stop receiving delivery updates, tap the button below.'
|
|
1226
|
+
},
|
|
1227
|
+
{
|
|
1228
|
+
type: 'BUTTONS',
|
|
1229
|
+
buttons: [
|
|
1230
|
+
{
|
|
1231
|
+
type: 'QUICK_REPLY',
|
|
1232
|
+
text: 'Stop Delivery Updates'
|
|
1233
|
+
}
|
|
1234
|
+
]
|
|
1235
|
+
}
|
|
1236
|
+
],
|
|
1237
|
+
allow_category_change: false
|
|
1238
|
+
}, accessToken);
|
|
1239
|
+
|
|
1240
|
+
// Template de mensagem de boas-vindas simples (MARKETING)
|
|
1241
|
+
await sdk.whatsapp.createTemplate({
|
|
1242
|
+
token: 'sk_live_01JABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
1243
|
+
name: 'welcome_message',
|
|
1244
|
+
category: 'MARKETING',
|
|
1245
|
+
language: 'pt_BR',
|
|
1246
|
+
components: [
|
|
1247
|
+
{
|
|
1248
|
+
type: 'BODY',
|
|
1249
|
+
text: 'Bem-vindo à nossa loja! Estamos felizes em ter você conosco.'
|
|
1250
|
+
},
|
|
1251
|
+
{
|
|
1252
|
+
type: 'FOOTER',
|
|
1253
|
+
text: 'Equipe da Loja'
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
type: 'BUTTONS',
|
|
1257
|
+
buttons: [
|
|
1258
|
+
{
|
|
1259
|
+
type: 'QUICK_REPLY',
|
|
1260
|
+
text: 'Ver ofertas'
|
|
1261
|
+
},
|
|
1262
|
+
{
|
|
1263
|
+
type: 'QUICK_REPLY',
|
|
1264
|
+
text: 'Falar no chat'
|
|
1265
|
+
}
|
|
1266
|
+
]
|
|
1267
|
+
}
|
|
1268
|
+
],
|
|
1269
|
+
allow_category_change: true
|
|
1270
|
+
}, accessToken);
|
|
569
1271
|
```
|
|
570
1272
|
|
|
571
1273
|
### Telegram
|