|
16 | 16 | class TelegramBot
|
17 | 17 | {
|
18 | 18 | /** @var string */
|
19 |
| - private $token; |
| 19 | + protected $token; |
20 | 20 |
|
21 | 21 | /** @var string */
|
22 |
| - private $baseUrl; |
| 22 | + protected $baseUrl; |
23 | 23 |
|
24 | 24 | /** @var array */
|
25 |
| - private $requestOptions; |
| 25 | + protected $requestOptions; |
26 | 26 |
|
27 | 27 | /**
|
28 | 28 | * TelegramBot constructor.
|
@@ -52,7 +52,7 @@ public function __construct($token, $proxyConfig = null, $ipResolve = null)
|
52 | 52 | * @param bool $returnContent
|
53 | 53 | * @return bool|string
|
54 | 54 | */
|
55 |
| - private function makeRequest($url, $data = null, $files = null, $returnContent = false) |
| 55 | + protected function makeRequest($url, $data = null, $files = null, $returnContent = false) |
56 | 56 | {
|
57 | 57 | try {
|
58 | 58 | $client = new Client();
|
@@ -149,6 +149,39 @@ public function sendPhoto($chat_id, $photo, $caption = null, $parse_mode = null,
|
149 | 149 | return $this->makeRequest($this->baseUrl . '/sendPhoto', $data, ['photo' => $photo]);
|
150 | 150 | }
|
151 | 151 |
|
| 152 | + /** |
| 153 | + * Official docs: https://core.telegram.org/bots/api#senddocument |
| 154 | + * Max size document is 50 MB |
| 155 | + * @param integer|string $chat_id |
| 156 | + * @param string $document Path to file |
| 157 | + * @param string $thumb Path to file |
| 158 | + * @param null $caption |
| 159 | + * @param string $parse_mode |
| 160 | + * @param bool $disable_notification |
| 161 | + * @param integer $reply_to_message_id |
| 162 | + * @param $reply_markup |
| 163 | + * @return bool |
| 164 | + */ |
| 165 | + public function sendDocument($chat_id, $document, $thumb = null, $caption = null, $parse_mode = null, $disable_notification = null, $reply_to_message_id = null, $reply_markup = null) |
| 166 | + { |
| 167 | + if (!in_array(strtolower($parse_mode), ['markdown', 'html', null])) { |
| 168 | + throw new \InvalidArgumentException('Invalid parse_mode argument'); |
| 169 | + } |
| 170 | + $data = [ |
| 171 | + 'chat_id' => $chat_id, |
| 172 | + 'caption' => $caption, |
| 173 | + 'parse_mode' => $parse_mode, |
| 174 | + 'disable_notification' => $disable_notification, |
| 175 | + 'reply_to_message_id' => $reply_to_message_id, |
| 176 | + 'reply_markup' => $reply_markup, |
| 177 | + ]; |
| 178 | + $files['document'] = $document; |
| 179 | + if (!is_null($thumb)) { |
| 180 | + $files['thumb'] = $thumb; |
| 181 | + } |
| 182 | + return $this->makeRequest($this->baseUrl . '/sendDocument', $data, $files); |
| 183 | + } |
| 184 | + |
152 | 185 | /**
|
153 | 186 | * @param $url
|
154 | 187 | * @param null $certificate
|
|
0 commit comments