From 710f6ed3b4d1d621a3b69fe0f52a8297809a43fa Mon Sep 17 00:00:00 2001 From: Aldoggutierrez Date: Thu, 14 Mar 2024 10:34:56 -0600 Subject: [PATCH] feat: added support for flow type button --- README.md | 1 + src/Component.php | 5 +++++ src/Component/FlowButton.php | 25 +++++++++++++++++++++ tests/Component/FlowButtonTest.php | 35 ++++++++++++++++++++++++++++++ tests/ComponentTest.php | 8 +++++++ 5 files changed, 74 insertions(+) create mode 100644 src/Component/FlowButton.php create mode 100644 tests/Component/FlowButtonTest.php diff --git a/README.md b/README.md index da6a13c..9e9e6db 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Component::video($link); Component::text($text); Component::urlButton($array_of_urls); Component::quickReplyButton($array_of_payloads); +Component::flowButton($flow_token, $array_of_data); ``` Components supported by Whatsapp template sections: diff --git a/src/Component.php b/src/Component.php index 1c0f936..dc341a0 100644 --- a/src/Component.php +++ b/src/Component.php @@ -46,4 +46,9 @@ public static function quickReplyButton(array $payloads): Component\QuickReplyBu { return new Component\QuickReplyButton($payloads); } + + public static function flowButton(string $token, array $data): Component\FlowButton + { + return new Component\FlowButton($token,$data); + } } diff --git a/src/Component/FlowButton.php b/src/Component/FlowButton.php new file mode 100644 index 0000000..3b71d7f --- /dev/null +++ b/src/Component/FlowButton.php @@ -0,0 +1,25 @@ +parameters[] = [ + 'type' => 'action', + 'action' => [ + 'flow_token' => $token, + 'flow_action_data' => $data + ], + ]; + } + + public function subType(): string + { + return 'flow'; + } +} diff --git a/tests/Component/FlowButtonTest.php b/tests/Component/FlowButtonTest.php new file mode 100644 index 0000000..6afe451 --- /dev/null +++ b/tests/Component/FlowButtonTest.php @@ -0,0 +1,35 @@ + 'example']); + + $expectedValue = [ + 'type' => 'button', + 'sub_type' => 'flow', + 'index' => '0', + 'parameters' => [ + [ + 'type' => 'action', + 'action' => [ + 'flow_token' => 'token', + 'flow_action_data' => [ + 'test' => 'example' + ] + ] + ] + ], + ]; + + $this->assertEquals($expectedValue, $button->toArray()); + } +} diff --git a/tests/ComponentTest.php b/tests/ComponentTest.php index 033ca4e..5d75b63 100644 --- a/tests/ComponentTest.php +++ b/tests/ComponentTest.php @@ -70,4 +70,12 @@ public function it_can_return_a_quick_reply_button_component() $this->assertInstanceOf(Component\QuickReplyButton::class, $component); } + + /** @test */ + public function it_can_return_a_flow_reply_button_component() + { + $component = Component::flowButton('token',['example' => "test"]); + + $this->assertInstanceOf(Component\FlowButton::class, $component); + } }