<?php require('medoo.php'); set_time_limit(0); define('BOT_TOKEN', '************************'); define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/'); function sendKeyboard($db, $message, $chatID) { $replyMarkup = array( 'keyboard' => array_chunk($db, 2)); $keyboard = json_encode($replyMarkup); file_get_contents(API_URL."/sendmessage?chat_id=".$chatID."&text=".$message."&reply_markup=".$keyboard); } $content = file_get_contents("php://input"); $update = json_decode($content, true); $chatID = $update["message"]["chat"]["id"]; $chatText = $update["message"]["text"]; $database = new medoo(array( 'database_type' => 'mysql', 'database_name' => 'polls', 'server' => 'localhost', 'username' => 'root', 'password' => '****************' )); $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $redis->select(3); $key_name = "user:".$chatID; $getKey = $redis->get($key_name); if ($getKey) { // verify answer $getAnswer = $database->get('answers', '*', ["AND"=>['id_poll_answer' =>$getKey, 'description_answer'=>$chatText]]); if ($getAnswer) { // insert result $insAnswer = $database->insert('records', ['r_poll_id'=> $getKey, 'r_answer_id'=>$getAnswer['id_answer'], 'user_id'=>$chatID]); // delete key $redis->del($key_name); // show question keyboard $getAllPoll = $database->select('polls', 'name_poll'); sendKeyboard($getAllPoll, "Спасибо, Ваш ответ засчитан!", $chatID); } else { // oww, wrong answer $getAllAnsw = $database->select('answers' ,'description_answer', ['id_poll_answer'=> $getKey]); sendKeyboard($getAllAnsw, "Такого ответа нет! Попробуйте ещё раз.", $chatID); } } else { // verify answer //TODO: show question keyboard $getAllPoll = $database->select('polls', 'name_poll'); sendKeyboard($getAllPoll,"Выберите опрос", $chatID); $getPoll = $database->get('polls', '*', ['name_poll'=> $chatText]); if($getPoll){ $redis->set($key_name, $getPoll['id_poll']); $getAllAnsw = $database->select('answers' ,'description_answer', ['id_poll_answer'=> $getKey]); sendKeyboard($getAllAnsw, "Выберите ответ", $chatID); } else { } } 
  • The comments contain a string that for some reason is not executed. - Yegor Podolyak
  • And everything else is done? In the same condition, the line above or another line with the same function? - MasterAlex
  • yes, the string $ redis-> set ($ key_name, $ getPoll ['id_poll']); is executed, and then sendKeyboard works again ($ getAllPoll, "Select a poll", $ chatID); - Yegor Podolyak
  • Error output enabled? - rjhdby
  • I look at /var/log/nginx/error.log and there are no errors - Yegor Podolyak

0