dj_mix_hosting_software/classes/Telegram.php
Cody Cook 74f1d6e193
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 53s
PHPUnit stuff.
2024-05-14 17:54:06 -07:00

62 lines
1.7 KiB
PHP

<?php
namespace DJMixHosting;
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;
}
}