Webhook telegram api problem



  • I'm writing my bot. I want to use webhook to get new messages. The installation of webhook has been successful, but how do we get new messages? What code do you need to write on the server for these new messages?



  • Initiate connection:

    $botToken = "_ТОКЕН_ОТ_@BotFather";
    $website = "https://api.telegram.org/bot" . $botToken;
    

    We get a message:

    $content = file_get_contents("php://input"); //олучаем json-ответ
    $update = json_decode($content, TRUE); //декодируем json
    $message = $update["message"]; //получаем объект Message
    

    We get the data from the report:

    $chatId = $message["chat"]["id"]; //ID чата, где должен присутствовать бот
    $text = $message["text"]; //текст сообщения
    



Suggested Topics

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