Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.exchange1c/lib/ |
Upload File : |
<?php namespace Wbs24\Exchange1c; class Telegram { use Exception; public function setParam($token, $chatId) { $this->token = $token; $this->chatId = $chatId; } public function sendMessage($message) { $fields = [ 'chat_id' => (int) $this->chatId, 'text' => $message, ]; if ($this->isHtml($message)) $fields['parse_mode'] = 'html'; $url = 'https://api.telegram.org/bot'. $this->token .'/sendMessage'; $json = $this->postRequest($url, $fields); $result = json_decode($json, true); $success = $result['ok'] ?? false; if (!$success) { $this->createReport( 'telegrem_error.log', 'message for send: '.$message."; \r\n".'telegram response: '.$json ); } } protected function isHtml($message) { return true; } protected function postRequest($url, $fields) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); $res = curl_exec($ch); curl_close($ch); return $res; } }