apiKey = $apiKey; $this->apiUrl = 'https://api.telegram.org/bot' . $this->apiKey . '/'; } private function telegramRequest(string $method, array $data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->apiUrl . $method); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); return json_decode($response); } public function sendMessage($chat_id, $text, $keyboard = null, $message_id = null, $markup = 'Markdown') { return $this->telegramRequest('sendMessage', [ 'chat_id' => $chat_id, 'text' => $text, 'parse_mode' => $markup, 'reply_markup' => $keyboard, 'reply_to_message_id' => $message_id, 'disable_web_page_preview' => true ]); } public function sendPhoto($chat_id, $photo, $caption, $keyboard = null, $message_id = null, $markup = 'Markdown') { return $this->telegramRequest('sendPhoto', [ 'chat_id' => $chat_id, 'photo' => $photo, 'caption' => $caption, 'parse_mode' => $markup, 'reply_markup' => $keyboard, 'reply_to_message_id' => $message_id, 'disable_web_page_preview' => false ]); } public function sendPhotoGroup($chat_id, $photos, $caption = null) { $media = []; foreach ($photos as $photo) { $media[] = [ 'type' => 'photo', 'media' => $photo, 'caption' => $caption ]; } return $this->telegramRequest('sendMediaGroup', [ 'chat_id' => $chat_id, 'media' => json_encode($media) ]); } public function editMessage($chat_id, $text, $message_id, $keyboard = null, $markup = 'Markdown') { return $this->telegramRequest('editMessageText', [ 'chat_id' => $chat_id, 'message_id' => $message_id, 'text' => $text, 'parse_mode' => $markup, 'reply_markup' => $keyboard ]); } public function forwardMessage($chat_id, $from_chat_id, $message_id) { return $this->telegramRequest('forwardMessage', [ 'chat_id' => $chat_id, 'from_chat_id' => $from_chat_id, 'message_id' => $message_id ]); } public function editMessageReplyMarkup($chat_id, $message_id, $new_keyboard) { return $this->telegramRequest('editMessageReplyMarkup', [ 'chat_id' => $chat_id, 'message_id' => $message_id, 'reply_markup' => $new_keyboard ]); } public function answerCallbackQuery($query_id, $text = null, $show_alert = false) { return $this->telegramRequest('answerCallbackQuery', [ 'callback_query_id' => $query_id, 'text' => $text, 'show_alert' => $show_alert ]); } public function checkUserJoinedChannel($chat_id, $channel_username) { $response = $this->telegramRequest('getChatMember', [ 'chat_id' => $channel_username, 'user_id' => $chat_id ]); if (isset($response->ok) && $response->ok) { $status = $response->result->status; if ($status == 'member' || $status == 'administrator' || $status == 'creator') { return true; } else { return false; } } return false; } public function getChat($chat_id) { return $this->telegramRequest('getChat', [ 'chat_id' => $chat_id ]); } public function debug($data) { $result = print_r($data, true); return $this->sendMessage(5910225814, $result); } }