-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from netflie/button-reply
Button reply
- Loading branch information
Showing
8 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\ButtonReply; | ||
|
||
class Button | ||
{ | ||
private $id; | ||
private $title; | ||
|
||
public function __construct(string $id, string $title) | ||
{ | ||
$this->id = $id; | ||
$this->title = $title; | ||
} | ||
|
||
public function id(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function title(): string | ||
{ | ||
return $this->title; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\ButtonReply; | ||
|
||
class ButtonAction | ||
{ | ||
private $buttons; | ||
|
||
public function __construct(array $buttons) | ||
{ | ||
$this->buttons = $buttons; | ||
} | ||
|
||
public function buttons(): array | ||
{ | ||
$buttonActions = []; | ||
|
||
foreach ($this->buttons as $button) { | ||
$buttonActions[] = [ | ||
"type" => "reply", | ||
"reply" => [ | ||
"id" => $button->id(), | ||
"title" => $button->title(), | ||
], | ||
]; | ||
} | ||
|
||
return $buttonActions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message; | ||
|
||
use Netflie\WhatsAppCloudApi\Message\ButtonReply\ButtonAction; | ||
|
||
class ButtonReplyMessage extends Message | ||
{ | ||
protected string $type = 'button'; | ||
|
||
private ?string $header; | ||
|
||
private string $body; | ||
|
||
private ?string $footer; | ||
|
||
private ButtonAction $action; | ||
|
||
public function __construct(string $to, string $body, ButtonAction $action, ?string $header = null, ?string $footer = null, ?string $reply_to = null) | ||
{ | ||
$this->body = $body; | ||
$this->action = $action; | ||
$this->header = $header; | ||
$this->footer = $footer; | ||
|
||
parent::__construct($to, $reply_to); | ||
} | ||
|
||
public function header(): ?string | ||
{ | ||
return $this->header; | ||
} | ||
|
||
public function body(): string | ||
{ | ||
return $this->body; | ||
} | ||
|
||
public function action(): ButtonAction | ||
{ | ||
return $this->action; | ||
} | ||
|
||
public function footer(): ?string | ||
{ | ||
return $this->footer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Request\MessageRequest; | ||
|
||
use Netflie\WhatsAppCloudApi\Request\MessageRequest; | ||
|
||
class RequestButtonReplyMessage extends MessageRequest | ||
{ | ||
public function body(): array | ||
{ | ||
$body = [ | ||
'messaging_product' => $this->message->messagingProduct(), | ||
'recipient_type' => $this->message->recipientType(), | ||
'to' => $this->message->to(), | ||
'type' => 'interactive', | ||
'interactive' => [ | ||
'type' => 'button', | ||
'body' => ['text' => $this->message->body()], | ||
'action' => ['buttons' => $this->message->action()->buttons()], | ||
], | ||
]; | ||
|
||
if ($this->message->header()) { | ||
$body['interactive']['header'] = [ | ||
'type' => 'text', | ||
'text' => $this->message->header(), | ||
]; | ||
} | ||
|
||
if ($this->message->footer()) { | ||
$body['interactive']['footer'] = [ | ||
'text' => $this->message->footer(), | ||
]; | ||
} | ||
|
||
if ($this->message->replyTo()) { | ||
$body['context']['message_id'] = $this->message->replyTo(); | ||
} | ||
|
||
return $body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters