Skip to content

Commit

Permalink
Merge pull request #22 from Aldoggutierrez/main
Browse files Browse the repository at this point in the history
feat: added support for flow type button
  • Loading branch information
aalbarca authored Apr 29, 2024
2 parents c5d93b6 + ff14821 commit c2e6dd6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
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);
}
}

0 comments on commit c2e6dd6

Please sign in to comment.