Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for flow type button #22

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
5 changes: 5 additions & 0 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
22 changes: 22 additions & 0 deletions src/Component/FlowButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace NotificationChannels\WhatsApp\Component;

class FlowButton extends Button
{
public function __construct(?string $token, array $data)
{
$this->parameters[] = [
'type' => 'action',
'action' => [
'flow_token' => $token,
'flow_action_data' => $data,
],
];
}

public function subType(): string
{
return 'flow';
}
}
34 changes: 34 additions & 0 deletions tests/Component/FlowButtonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace NotificationChannels\WhatsApp\Test\Component;

use NotificationChannels\WhatsApp\Component\FlowButton;
use PHPUnit\Framework\TestCase;

final class FlowButtonTest extends TestCase
{
/** @test */
public function flow_button_is_valid()
{
$button = new FlowButton('token', ['test' => '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());
}
}
8 changes: 8 additions & 0 deletions tests/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}