HEX
Server: Apache/2.4.59 (Debian)
System: Linux skycube.cz 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
User: ilya (534)
PHP: 7.3.31-1~deb10u7
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/ilya/data/www/povoleni.ru/includes/telegram.php
<?php

class TG {
  
    public $token = '';
  
    public function __construct($token) {
        $this->token = $token; 
    }
      
    public function send($id, $message, $kb) {
        $data = array(
            'chat_id' => $id,
            'text'  => $message,
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => false,
            //'reply_markup' => json_encode(array('inline_keyboard' => $kb, 'resize_keyboard' => true))
            'reply_markup' => json_encode(array('keyboard' => $kb, 'one_time_keyboard' => true, 'resize_keyboard' => true))
        );
        $this->request('sendMessage', $data);
    }  

    public function editMessageText($id, $m_id, $m_text, $kb=''){
        $data=array(
             'chat_id' => $id,
             'message_id' => $m_id,
             'parse_mode' => 'HTML',
             'text' => $m_text
        );
        if($kb)
            $data['reply_markup']=json_encode(array('inline_keyboard' => $kb));

        $this->request('editMessageText', $data); 
    }


    public function editMessageReplyMarkup($id, $m_id, $kb){
        $data=array(
             'chat_id' => $id,
             'message_id' => $m_id,
            'reply_markup' => json_encode(array('inline_keyboard' => $kb))
        );
        $this->request('editMessageReplyMarkup', $data); 
    }
    
    public function answerCallbackQuery($cb_id, $message) {
        $data = array(
            'callback_query_id'      => $cb_id,
            'text'     => $message
        );
        $this->request('answerCallbackQuery', $data);
    } 

    public function sendChatAction($id,$action='typing') {
        $data = array(
            'chat_id' => $id,
            'action'     => $action
        );
        $this->request('sendChatAction', $data);
    }


    public  function request($method, $data = array()) {
        $curl = curl_init();
          
        curl_setopt($curl, CURLOPT_URL, 'https://api.telegram.org/bot' . $this->token .  '/' . $method);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); 
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
          
        $out = json_decode(curl_exec($curl), true);
          
        curl_close($curl);
        return $out;
    }
}

function send_telegram($tg_id,$message) {

	$body = file_get_contents('php://input');
	$arr = json_decode($body, true); 

	$tg = new tg(TELEGRAM_KEY);

	$rez_kb = array();

	$message = str_replace('\n',PHP_EOL,$message);
	$message = str_replace('\r',PHP_EOL,$message);
	$message = str_replace("\n",PHP_EOL,$message);
	$message = str_replace("\r",PHP_EOL,$message);

	$tg->sendChatAction($tg_id);

	$tg->send($tg_id, $message, $rez_kb);
}


?>