-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
40 lines (28 loc) · 1.15 KB
/
example.php
File metadata and controls
40 lines (28 loc) · 1.15 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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client as HttpClient;
use TelegramClient\Exceptions\TelegramException;
use TelegramClient\TelegramClient;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$logger = new Logger('api-logger');
$logger->pushHandler(new StreamHandler($_ENV['LOG_PATH'] ?: __DIR__ . '/logs/api-telegram.log'));
$httpClient = new HttpClient([
'timeout' => (float)($_ENV['TIMEOUT'] ?: 5.0),
]);
$token = $_ENV['TELEGRAM_BOT_TOKEN'] ?? null;
if (!$token) {
die("❌ Токен не загружен! Проверь файл .env\n");
}
$client = new TelegramClient($token, $httpClient, $logger);
try {
$chatId = 5302145640;
$text = "Привет! Это сообщение из собственного Telegram клиента.";
$response = $client->sendMessage($chatId, $text);
echo "Сообщение отправлено успешно. ID сообщения: " . $response['message_id'] . PHP_EOL;
} catch (TelegramException $e) {
echo "Ошибка Telegram API: " . $e->getMessage() . PHP_EOL;
}