/
TelegramMessage.php
117 lines (101 loc) · 2.08 KB
/
TelegramMessage.php
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
113
114
115
116
117
<?php
namespace NotificationChannels\Telegram;
class TelegramMessage
{
/**
* @var array Params payload.
*/
public $payload = [];
/**
* @var array Inline Keyboard Buttons.
*/
protected $buttons = [];
/**
* @param string $content
*
* @return static
*/
public static function create($content = '')
{
return new static($content);
}
/**
* Message constructor.
*
* @param string $content
*/
public function __construct($content = '')
{
$this->content($content);
$this->payload['parse_mode'] = 'Markdown';
}
/**
* Recipient's Chat ID.
*
* @param $chatId
*
* @return $this
*/
public function to($chatId)
{
$this->payload['chat_id'] = $chatId;
return $this;
}
/**
* Notification message (Supports Markdown).
*
* @param $content
*
* @return $this
*/
public function content($content)
{
$this->payload['text'] = $content;
return $this;
}
/**
* Add an inline button.
*
* @param string $text
* @param string $url
*
* @return $this
*/
public function button($text, $url, $columns = 2)
{
$this->buttons[] = compact('text', 'url');
$replyMarkup['inline_keyboard'] = array_chunk($this->buttons, $columns);
$this->payload['reply_markup'] = json_encode($replyMarkup);
return $this;
}
/**
* Additional options to pass to sendMessage method.
*
* @param array $options
*
* @return $this
*/
public function options(array $options)
{
$this->payload = array_merge($this->payload, $options);
return $this;
}
/**
* Determine if chat id is not given.
*
* @return bool
*/
public function toNotGiven()
{
return !isset($this->payload['chat_id']);
}
/**
* Returns params payload.
*
* @return array
*/
public function toArray()
{
return $this->payload;
}
}