No new messages can be received during the Telegram Bottom Management Crypt



  • I'm writing a bot-control violin through Bot API, consisting of a PHP file on my server, on which the Webhook is located, and which my bot is approaching when I get a new message from the user. But I have a problem that when I get the data from the bot on the message I received, if I do it again when the violin has already begun, I only get an old message, and I can't get a new message and process it in the middle of the violin. I want to put in a complicated logic of investment in the handling of messages from the user, for example:

    $update = file_get_contents('php://input');///получение данных от бота
    $update = json_decode($update, TRUE);///декодирование данных
    $message = $update["message"]["text"];///назначение данных в переменную
    switch($message) {////варьируем действия на основе изначально имеющегося ответа
       case "number1":
       ////отправляем что-нибудь пользователю и ждем ответа
       ////снова получаем, декодируем и назначаем обновленные данные
       $update = file_get_contents('php://input');
       $update = json_decode($update, TRUE);
       $message = $update["message"]["text"];
       switch($message) {////смотрим на новое сообщение
            case "number2":
            ////совершаем действия на основе полученного нового ответа
            }
       }
       ...
    

    And when I'm already trying to retrieve and assign a new user response to the specimen of $message, as a result, only an old answer (which was available at the time of the violin starts) and so I can't vary the logic of further work. What can you recommend?



  • We need to return the code 200 and at least an empty JSON, as far as possible, to form answers to the user, but you won't know what the server will answer to that, after which the server thinks he's brought you up to date.

    As an option, go to long-polling, and hand over the latest update_id as a parameter.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2