Skip to content

Commit

Permalink
add none button
Browse files Browse the repository at this point in the history
  • Loading branch information
sokil committed May 15, 2020
1 parent 0b63f84 commit 56264d7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/Message/RichMediaMessage/Button/AbstractButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
abstract class AbstractButton
{
/**
* @var string
* Text to be displayed on the button. Can contain some HTML tags.
* Valid and allowed HTML tags Max 250 characters.
* If the text is too long to display on the button it will be cropped and ended with “…”
*
* @var string|null
*/
private $text;

Expand All @@ -25,12 +29,20 @@ abstract class AbstractButton
private $bgColor;

/**
* @param string $text
* @param string|null $text
* @param string $actionBody
* @param string|null $bgColor
*/
public function __construct($text, $actionBody, $bgColor = null)
{
if (is_string($text)) {
if (mb_strlen($text) > 250) {
throw new \InvalidArgumentException('Text must be null or string with length less then 250 chars');
}
} elseif ($text !== null) {
throw new \InvalidArgumentException('Text must be null or string with length less then 250 chars');
}

$this->text = $text;
$this->actionBody = $actionBody;
$this->bgColor = $bgColor;
Expand Down
14 changes: 14 additions & 0 deletions src/Message/RichMediaMessage/Button/InformativeButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Sokil\Viber\Notifier\Message\RichMediaMessage\Button;

/**
* @link https://viber.github.io/docs/tools/keyboards/#replyLogic
*/
class InformativeButton extends AbstractButton
{
public function getActionType()
{
return 'none';
}
}
7 changes: 7 additions & 0 deletions src/Message/RichMediaMessage/Button/OpenUrlButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

namespace Sokil\Viber\Notifier\Message\RichMediaMessage\Button;

/**
* @link https://viber.github.io/docs/tools/keyboards/#replyLogic
*
* The value of ActionBody is sent as a text message to account (via message event)
* The value of ActionBody is opened in the browser
* The value of ActionBody appears in the chat thread as message from the user.
*/
class OpenUrlButton extends AbstractButton
{
public function getActionType()
Expand Down
3 changes: 3 additions & 0 deletions src/Message/RichMediaMessage/Button/ReplyButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

/**
* @link https://viber.github.io/docs/tools/keyboards/#replyLogic
*
* The value of ActionBody is sent as a text message to account (via message event)
* The value of text appears in the chat thread as message from the user.
*/
class ReplyButton extends AbstractButton
{
Expand Down
4 changes: 2 additions & 2 deletions src/Message/RichMediaMessage/RichMediaMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function toApiRequestParams()
return [
'rich_media' => [
"Type" => "rich_media",
"ButtonsGroupColumns" => 6,
"ButtonsGroupRows" => count($this->buttons),
"ButtonsGroupColumns" => 1,
"ButtonsGroupRows" => 1,
"BgColor" => "#FFFFFF",
"Buttons" => array_map(
function(AbstractButton $button) {
Expand Down

0 comments on commit 56264d7

Please sign in to comment.