Skip to content

Commit

Permalink
make silent button
Browse files Browse the repository at this point in the history
  • Loading branch information
sokil committed May 15, 2020
1 parent 56264d7 commit 6b5aca9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
89 changes: 84 additions & 5 deletions src/Message/RichMediaMessage/Button/AbstractButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,31 @@ abstract class AbstractButton
* Valid color HEX value
* @var string|null
*/
private $bgColor;
private $bgColor = '#FFFFFF';

/**
* @var bool
*/
private $isSilent = false;

/**
* @var int
*/
private $columns = 6;

/**
* @var int
*/
private $rows = 1;

/**
* @param string|null $text
* @param string $actionBody
* @param string|null $bgColor
*/
public function __construct($text, $actionBody, $bgColor = null)
{
public function __construct(
$text,
$actionBody
) {
if (is_string($text)) {
if (mb_strlen($text) > 250) {
throw new \InvalidArgumentException('Text must be null or string with length less then 250 chars');
Expand All @@ -45,7 +61,6 @@ public function __construct($text, $actionBody, $bgColor = null)

$this->text = $text;
$this->actionBody = $actionBody;
$this->bgColor = $bgColor;
}

abstract public function getActionType();
Expand All @@ -66,6 +81,70 @@ public function getActionBody()
return $this->actionBody;
}

/**
* @return int
*/
public function getColumns()
{
return $this->columns;
}

/**
* @param int $columns
*/
public function setColumns($columns)
{
if (!is_numeric($columns) || $columns < 1 || $columns > 6) {
throw new \InvalidArgumentException('Rows count may be from 1 to 6');
}

$this->columns = $columns;
}

/**
* @return int
*/
public function getRows()
{
return $this->rows;
}

/**
* @param int $rows
*/
public function setRows($rows)
{
if (!is_numeric($rows) || $rows < 1 || $rows > 2) {
throw new \InvalidArgumentException('Rows count may be 1 or 2');
}

$this->rows = $rows;
}

/**
* @param bool $isSilent
*/
public function setSilent($isSilent)
{
$this->isSilent = $isSilent;
}

/**
* @return bool
*/
public function isSilent()
{
return $this->isSilent;
}

/**
* @param string $bgColor
*/
public function setBgColor($bgColor)
{
$this->bgColor = $bgColor;
}

/**
* @return string|null
*/
Expand Down
5 changes: 3 additions & 2 deletions src/Message/RichMediaMessage/RichMediaMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ function toApiRequestParams()
"Buttons" => array_map(
function(AbstractButton $button) {
$buttonSettings = [
'Columns' => 6,
'Rows' => 2,
'Columns' => $button->getColumns(),
'Rows' => $button->getRows(),
'Text'=> $button->getText(),
'Silent' => $button->isSilent(),
"ActionType" => $button->getActionType(),
"ActionBody" => $button->getActionBody(),
'TextHAlign' => 'left',
Expand Down

0 comments on commit 6b5aca9

Please sign in to comment.