-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleTelegramBot.php
More file actions
46 lines (41 loc) · 917 Bytes
/
SimpleTelegramBot.php
File metadata and controls
46 lines (41 loc) · 917 Bytes
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
<?php
/**
* @property $id;
* @property $secretKey;
*/
class SimpleTelegramBot
{
protected int $id;
protected string $secretKey;
/**
* Telegram bot id
* @param $botId
*
* Telegram secret key
* @param $secretKey
*/
public function __construct($botId, $secretKey)
{
$this->id = $botId;
$this->secretKey = $secretKey;
}
/**
* @param int $chatId
* @param $message
*/
public function sendMessage(int $chatId, $message): void
{
$url = sprintf('%s/%s?%s', $this->getBaseUrl(), __FUNCTION__, http_build_query([
'chat_id' => $chatId,
'text' => $message
]));
file_get_contents($url);
}
/**
* @return string
*/
protected function getBaseUrl(): string
{
return sprintf('https://api.telegram.org/bot%d:%s', $this->id, $this->secretKey);
}
}