The bottom line is that if a person who does not have a username in the Telegram settings, that is, he is empty, then when the user logs into the bot, after pressing the / start button, nothing happens to the user, and the bot administrator receives an error
Error working with API. Details:
{"ok":false,"error_code":400,"description":"Bad Request: chat_id is empty"}
The bot has a database where information about users is recorded.
Here is the code for checking and recording user data:
// Функция-обработчик, отвечающая на команды $bot->addHandler(function($update, Telegram &$bot) { if (!isset($update->{"message"}->{"text"})) { $update->{"message"}->{"text"} = " "; } if (empty($update->{"message"}->{"chat"}->{"username"})) { $bot->sendMessage($chatId, "Уважаемый пользователь. У Вас не установлен username. Пожалуйста, установите его в настройках. После этого выполните команду /start еще раз. Спасибо за понимание"); return; } $chatId = $update->{"message"}->{"chat"}->{"id"}; $messageIn = $update->{"message"}->{"text"}; $firstname = ""; $lastname = ""; if (isset($update->{"message"}->{"chat"}->{"first_name"})) { $firstname = $update->{"message"}->{"chat"}->{"first_name"}; } if (isset($update->{"message"}->{"chat"}->{"last_name"})) { $lastname = $update->{"message"}->{"chat"}->{"last_name"}; } //Проверка на пользователя if(DB::uCountColumns("SELECT * FROM `Users` WHERE `chat_id` = '".$chatId."'")){ // обновление DB::uQuery("UPDATE `Users` SET `username`='".$update->{"message"}->{"chat"}->{"username"}."', `lastname`='".$lastname."', `firstname`='".$firstname."' WHERE `chat_id` = '".$chatId."'"); }else{ // запись DB::uQuery("INSERT INTO `Users`(`chat_id`, `username`, `lastname`, `firstname`, `regDate`) VALUES ('".$chatId."','".$update->{"message"}->{"chat"}->{"username"}."','".$lastname."','".$firstname."',NOW())"); } $userInfo = DB::uFetch("SELECT * FROM `Users` WHERE `chat_id` = '$chatId'"); $rMessage = explode(' ', $messageIn); switch ($rMessage[0]) { case '/start': { // Открываем файл для получения существующего содержимого if ($rMessage[1] > 0 AND ($rMessage[1]!=$chatId)){ // проверка есть ли такой пользователь if(DB::uCountColumns("SELECT * FROM `Users` WHERE `chat_id` = '".$rMessage[1]."'") AND !DB::uCountColumns("SELECT * FROM `Reffer` WHERE `chat_id` = '".$rMessage[1]."'")){ DB::uQuery("INSERT INTO `Reffer`(`chat_id`, `reffers_id`, `money`) VALUES ('".$chatId."','".$rMessage[1]."','". REF_MONEY ."')"); DB::uQuery("UPDATE `Users` SET `balanse`= `balanse` + '". REF_MONEY ."' WHERE `chat_id` = '".$rMessage[1]."'"); } } $welcomeMsg = "Текст приветствия"; $buttons = []; $buttons[] = [['text' => "\xF0\x9F\x92\xB5 Получить бонус"],['text' => "\xF0\x9F\x92\xB0 Кошелек"]]; $buttons[] = [['text' => "\xF0\x9F\x91\xAB Друзья"],['text' => "\xF0\x9F\x93\x88 Статистика"]]; $buttons[] = [['text' => "\xF0\x9F\x8C\x8D Язык"],['text' => "\xE2\x84\xB9 Помощь"]]; $bot->sendMessage($chatId, $welcomeMsg, array('keyboard' => $buttons, 'resize_keyboard' => true)); break; } // Помощь case "\xE2\x84\xB9": { help($bot, $chatId); break; } What is wrong here?
Reffer(chat_id,reffers_id,money) VALUES ('". $ ChatId. "', '". $ RMessage [1]. "' , '". REF_MONEY."') "); DB :: uQuery ("UPDATEUsersSETbalanse=balanse+ '". REF_MONEY. "' WHEREchat_id= '". $ RMessage [1]. "'" "); - Valery Makinsky