@@ -561,3 +561,180 @@ export class ActionCTA implements InteractiveAction {
561
561
} ;
562
562
}
563
563
}
564
+
565
+ /**
566
+ * Action API object
567
+ *
568
+ * @group Interactive
569
+ */
570
+ export abstract class ActionFlow implements InteractiveAction {
571
+ /**
572
+ * The name of the component
573
+ */
574
+ readonly name = "flow" ;
575
+ /**
576
+ * The Flow parameters
577
+ *
578
+ * @remarks TSDoc is unable to document this type properly, so most of
579
+ * the documentation is in the subclasses constructors instead.
580
+ */
581
+ readonly parameters : {
582
+ /**
583
+ * The Flow can be in either draft or published mode
584
+ */
585
+ mode : "published" | "draft" ;
586
+ /**
587
+ * The Flow version, must be 3
588
+ */
589
+ flow_message_version : "3" ;
590
+ /**
591
+ * Flow token that is generated by the business to serve as an identifier
592
+ */
593
+ flow_token : string ;
594
+ /**
595
+ * Unique ID of the Flow provided by WhatsApp
596
+ */
597
+ flow_id : string ;
598
+ /**
599
+ * Text on the CTA button, character limit - 20 characters (no emoji)
600
+ */
601
+ flow_cta : string ;
602
+ /**
603
+ * The Flow type, if set to "navigate", flow_action_payload must be provided
604
+ */
605
+ flow_action : "navigate" | "data_exchange" ;
606
+ /**
607
+ * Required if flow_action is "navigate", should be omitted otherwise
608
+ */
609
+ flow_action_payload ?: {
610
+ /**
611
+ * The ID of the first Screen
612
+ */
613
+ screen : string ;
614
+ /**
615
+ * Optional input data for the first Screen of the Flow. If provided, this must be a non-empty object.
616
+ */
617
+ data ?: unknown ;
618
+ } ;
619
+ } & (
620
+ | {
621
+ flow_action : "navigate" ;
622
+ flow_action_payload : {
623
+ screen : string ;
624
+ data ?: unknown ;
625
+ } ;
626
+ }
627
+ | {
628
+ flow_action : "data_exchange" ;
629
+ flow_action_payload ?: never ;
630
+ }
631
+ ) ;
632
+
633
+ /**
634
+ * @override
635
+ * @internal
636
+ */
637
+ get _type ( ) : "flow" {
638
+ return "flow" ;
639
+ }
640
+
641
+ /**
642
+ * Builds a flow component for an Interactive message
643
+ *
644
+ * @param parameters - The Flow parameters
645
+ * @throws If parameters.flow_cta is empty or over 20 characters
646
+ * @throws If parameters.flow_cta contains emojis
647
+ */
648
+ constructor ( parameters : ActionFlow [ "parameters" ] ) {
649
+ if ( ! parameters . flow_cta . length || parameters . flow_cta . length > 20 ) {
650
+ throw new Error ( "Flow CTA must be between 1 and 20 characters" ) ;
651
+ }
652
+
653
+ if ( / \p{ Extended_Pictographic} / u. test ( parameters . flow_cta ) ) {
654
+ throw new Error ( "Flow CTA must not contain emoji" ) ;
655
+ }
656
+
657
+ this . parameters = parameters ;
658
+ }
659
+ }
660
+
661
+ /**
662
+ * Action API object
663
+ *
664
+ * @group Interactive
665
+ */
666
+ export class ActionNavigateFlow extends ActionFlow {
667
+ /**
668
+ * Builds a navigate flow component for an Interactive message
669
+ *
670
+ * @param flow_token - Flow token that is generated by the business to serve as an identifier
671
+ * @param flow_id - ID of the Flow provided by WhatsApp
672
+ * @param flow_cta - Text on the CTA button, character limit - 20 characters (no emoji)
673
+ * @param screen - The ID of the first Screen
674
+ * @param data - Optional input data for the first Screen of the Flow. If provided, this must be a non-empty object.
675
+ * @param mode - The Flow can be in either "draft" or "published" mode
676
+ * @param flow_message_version - The Flow version, must be "3"
677
+ * @throws If flow_cta is empty or over 20 characters
678
+ * @throws If flow_cta contains emojis
679
+ * @throws If data is provided and is an empty object
680
+ */
681
+ constructor (
682
+ flow_token : string ,
683
+ flow_id : string ,
684
+ flow_cta : string ,
685
+ screen : string ,
686
+ data ?: unknown ,
687
+ mode : "published" | "draft" = "published" ,
688
+ flow_message_version : "3" = "3"
689
+ ) {
690
+ super ( {
691
+ mode,
692
+ flow_message_version,
693
+ flow_token,
694
+ flow_id,
695
+ flow_cta,
696
+ flow_action : "navigate" ,
697
+ flow_action_payload : {
698
+ screen,
699
+ data
700
+ }
701
+ } ) ;
702
+
703
+ if ( data && ! Object . keys ( data ) ) {
704
+ throw new Error ( "Flow data must be a non-empty object if provided" ) ;
705
+ }
706
+ }
707
+ }
708
+
709
+ /**
710
+ * Action API object
711
+ *
712
+ * @group Interactive
713
+ */
714
+ export class ActionDataExchangeFlow extends ActionFlow {
715
+ /**
716
+ * Builds a data exchange flow component for an Interactive message
717
+ *
718
+ * @param flow_token - Flow token that is generated by the business to serve as an identifier
719
+ * @param flow_id - ID of the Flow provided by WhatsApp
720
+ * @param flow_cta - Text on the CTA button, character limit - 20 characters (no emoji)
721
+ * @param mode - Must be "published" or "draft"
722
+ * @param flow_message_version - Must be "3"
723
+ */
724
+ constructor (
725
+ flow_token : string ,
726
+ flow_id : string ,
727
+ flow_cta : string ,
728
+ mode : "published" | "draft" = "published" ,
729
+ flow_message_version : "3" = "3"
730
+ ) {
731
+ super ( {
732
+ mode,
733
+ flow_message_version,
734
+ flow_token,
735
+ flow_id,
736
+ flow_cta,
737
+ flow_action : "data_exchange"
738
+ } ) ;
739
+ }
740
+ }
0 commit comments