Update README.md and sync files.

This commit is contained in:
Cody Cook 2024-05-06 21:48:35 -07:00
commit da93d643d9
11 changed files with 763 additions and 2 deletions

60
classes/Telegram.php Normal file
View file

@ -0,0 +1,60 @@
<?php
class Telegram
{
private $token = "";
private $chat_id = "";
private $parse_mode = "HTML";
private $disable_web_page_preview = true;
private $disable_notification = false;
private $reply_to_message_id = 0;
private $message = "";
private $url = "https://api.telegram.org/bot";
public function __construct($token, $chat_id, $reply_to_message_id = 0)
{
$this->token = $token;
$this->chat_id = $chat_id;
$this->reply_to_message_id = $reply_to_message_id;
$this->url .= $this->token;
}
public function send_message($message)
{
$this->message = $message;
$result = $this->sendMessage();
if ($result) {
return json_decode($result, true);
}
return false;
}
private function sendMessage()
{
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $this->url . "/sendMessage",
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'chat_id' => $this->chat_id,
'text' => $this->message,
'parse_mode' => $this->parse_mode,
'disable_web_page_preview' => $this->disable_web_page_preview,
'disable_notification' => $this->disable_notification,
'reply_to_message_id' => $this->reply_to_message_id
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_SSL_VERIFYPEER => false
]);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}