-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
Added support for Interactive reply buttons media header #212
Open
derrickobedgiu1
wants to merge
6
commits into
netflie:main
Choose a base branch
from
derrickobedgiu1:button-reply-media-header
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+796
−19
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e19a9eb
Added support for media header
derrickobedgiu1 a628e43
Added sample support files
derrickobedgiu1 3493c6a
Added tests
derrickobedgiu1 1ae0691
Updated README
derrickobedgiu1 3acbc19
Fixed code style issues
derrickobedgiu1 e186cb3
Minor fix
derrickobedgiu1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,29 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\ButtonReply; | ||
|
||
use Netflie\WhatsAppCloudApi\Message\Media\MediaID; | ||
|
||
final class DocumentHeader extends Header | ||
{ | ||
protected string $type = 'document'; | ||
private MediaID $id; | ||
private string $filename; | ||
|
||
public function __construct(MediaID $id, string $filename) | ||
{ | ||
$this->id = $id; | ||
$this->filename = $filename; | ||
} | ||
|
||
public function getBody(): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'document' => [ | ||
$this->id->type() => $this->id->value(), | ||
'filename' => $this->filename, | ||
], | ||
]; | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\ButtonReply; | ||
|
||
abstract class Header | ||
{ | ||
protected string $type; | ||
|
||
abstract public function getBody(): array; | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\ButtonReply; | ||
|
||
use Netflie\WhatsAppCloudApi\Message\Media\MediaID; | ||
|
||
final class ImageHeader extends Header | ||
{ | ||
protected string $type = 'image'; | ||
private MediaID $id; | ||
|
||
public function __construct(MediaID $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getBody(): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'image' => [ | ||
$this->id->type() => $this->id->value(), | ||
], | ||
]; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\ButtonReply; | ||
|
||
final class TextHeader extends Header | ||
{ | ||
protected string $type = 'text'; | ||
private string $text; | ||
|
||
public function __construct(string $text) | ||
{ | ||
$this->text = $text; | ||
} | ||
|
||
public function getBody(): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'text' => $this->text, | ||
]; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\ButtonReply; | ||
|
||
use Netflie\WhatsAppCloudApi\Message\Media\MediaID; | ||
|
||
final class VideoHeader extends Header | ||
{ | ||
protected string $type = 'video'; | ||
private MediaID $id; | ||
|
||
public function __construct(MediaID $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getBody(): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'video' => [ | ||
$this->id->type() => $this->id->value(), | ||
], | ||
]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ | |
namespace Netflie\WhatsAppCloudApi; | ||
|
||
use Netflie\WhatsAppCloudApi\Message\ButtonReply\ButtonAction; | ||
use Netflie\WhatsAppCloudApi\Message\ButtonReply\Header as ButtonHeader; | ||
use Netflie\WhatsAppCloudApi\Message\ButtonReply\TextHeader; | ||
use Netflie\WhatsAppCloudApi\Message\Contact\ContactName; | ||
use Netflie\WhatsAppCloudApi\Message\Contact\Phone; | ||
use Netflie\WhatsAppCloudApi\Message\CtaUrl\Header; | ||
use Netflie\WhatsAppCloudApi\Message\Error\InvalidMessage; | ||
use Netflie\WhatsAppCloudApi\Message\Media\MediaID; | ||
use Netflie\WhatsAppCloudApi\Message\MultiProduct\Action as MultiProductAction; | ||
use Netflie\WhatsAppCloudApi\Message\OptionsList\Action; | ||
|
@@ -235,7 +238,7 @@ public function sendSticker(string $to, MediaID $sticker_id): Response | |
* @param float $longitude Longitude position. | ||
* @param float $latitude Latitude position. | ||
* @param string $name Name of location sent. | ||
* @param address $address Address of location sent. | ||
* @param string $address Address of location sent. | ||
* | ||
* @return Response | ||
* | ||
|
@@ -354,8 +357,15 @@ public function sendCtaUrl(string $to, string $displayText, string $url, ?Header | |
return $this->client->sendMessage($request); | ||
} | ||
|
||
public function sendButton(string $to, string $body, ButtonAction $action, ?string $header = null, ?string $footer = null): Response | ||
public function sendButton(string $to, string $body, ButtonAction $action, $header = null, ?string $footer = null): Response | ||
{ | ||
if (is_string($header)) { | ||
$header = new TextHeader($header); | ||
} | ||
|
||
if (!$header instanceof ButtonHeader && $header !== null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this if is not necessary, should you use type hinting in the function:
derrickobedgiu1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new InvalidMessage('Header must be instance of Netflie\WhatsAppCloudApi\Message\ButtonReply\Header if not left null'); | ||
} | ||
$message = new Message\ButtonReplyMessage( | ||
$to, | ||
$body, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class
ButtonReplyMEssage
yet exists in previous versions so you cannot convert it to final class because this is a breaking change (if anyone extended this class in our code you'll be breaking it)