fridge_bites/includes/TelegramBot.php
2025-06-02 13:34:17 +02:00

48 lines
1.0 KiB
PHP

<?php
namespace Lycoreco\Includes;
class TelegramBot
{
private $chatId;
private $telegramBotToken;
public function __construct($token, $chatId)
{
$this->telegramBotToken = $token;
$this->chatId = $chatId;
}
private function get_api_url()
{
return "https://api.telegram.org/bot" . $this->telegramBotToken . "/";
}
public function sendMessage($message)
{
$url = $this->get_api_url() . "sendMessage";
$data = [
'chat_id' => $this->chatId,
'text' => $message,
'parse_mode' => 'HTML'
];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
return false;
}
return true;
}
}