-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathKeyboard.php
More file actions
112 lines (94 loc) · 2.07 KB
/
Copy pathKeyboard.php
File metadata and controls
112 lines (94 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace BotMan\Drivers\Telegram\Extensions;
use Illuminate\Support\Collection;
/**
* Class Keyboard.
*/
class Keyboard
{
const TYPE_KEYBOARD = 'keyboard';
const TYPE_INLINE = 'inline_keyboard';
protected $parseMode = 'Markdown';
protected $oneTimeKeyboard = false;
protected $resizeKeyboard = false;
/**
* @var array
*/
protected $rows = [];
/**
* @param string $type
* @return Keyboard
*/
public static function create($type = self::TYPE_INLINE)
{
return new self($type);
}
/**
* Keyboard constructor.
* @param string $type
*/
public function __construct($type = self::TYPE_INLINE)
{
$this->type = $type;
}
/**
* @param $type
* @return $this
*/
public function type($type)
{
$this->type = $type;
return $this;
}
/**
* @param bool $active
* @return $this
*/
public function oneTimeKeyboard($active = true)
{
$this->oneTimeKeyboard = $active;
return $this;
}
/**
* @param $mode
* @return $this
*/
public function conParseMode($mode = 'Markdown')
{
$this->parseMode = $mode;
return $this;
}
/**
* @param bool $active
* @return $this
*/
public function resizeKeyboard($active = true)
{
$this->resizeKeyboard = $active;
return $this;
}
/**
* Add a new row to the Keyboard.
* @param KeyboardButton[] $buttons
* @return Keyboard
*/
public function addRow(KeyboardButton ...$buttons)
{
$this->rows[] = $buttons;
return $this;
}
/**
* @return array
*/
public function toArray()
{
return [
'parse_mode' => $this->parseMode,
'reply_markup' => json_encode(Collection::make([
$this->type => $this->rows,
'one_time_keyboard' => $this->oneTimeKeyboard,
'resize_keyboard' => $this->resizeKeyboard,
])->filter()),
];
}
}