diff --git a/README.md b/README.md index 9eb0368..2d3e33a 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..b63459e 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..e31cb2b --- /dev/null +++ b/src/Component/FlowButton.php @@ -0,0 +1,22 @@ +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..4cbe029 --- /dev/null +++ b/tests/Component/FlowButtonTest.php @@ -0,0 +1,34 @@ + '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..383f8fc 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); + } }