Hello everyone, tell me what the error is, because when you start it, it writes this thing

Warning: file_get_contents ( https://api.telegram.org/botTOKEN/sendmessage?chat_id=&text=text ): HTTP / 1.1 400 Bad Request in C: \ xamppp \ htdocs \ bot.php on line 13

<?php $botTokken = "токен"; $website = 'https://api.telegram.org/bot'.$botTokken.''; $update = file_get_contents($website."/getupdates"); $updateArray = json_decode($update,true); $chadId = $updateArray["result"][0]["message"]["chat"]["id"]; #chatId $text = $updateArray["result"][0]["message"]["chat"]["text"]; #chatId file_get_contents($website.'/sendmessage?chat_id='.$chatId.'&text=text'); print_r($chadId); ?> 
  • the problem is that it does not accept data from $ chadId = $ updateArray ["result"] [0] ["message"] ["chat"] ["id"]; #chatId $ text = $ updateArray ["result"] [0] ["message"] ["chat"] ["text"]; #text how to fix? - Malyshev

2 answers 2

 <?php $botTokken = "токен"; $website = 'https://api.telegram.org/bot'.$botTokken.''; $update = file_get_contents($website."/getupdates"); $updateArray = json_decode($update,true); $chadId = $updateArray["result"][0]["message"]["chat"]["id"]; #chatId $text = $updateArray["result"][0]["message"]["text"]; #text $text = $text; $send = $website.'/sendmessage?chat_id='.$chadId.'&text='.$text.''; file_get_contents($send); print_r($text); print_r($chadId); ?> <script type="text/javascript"> // начать повторы с интервалом 2 сек var timerId = setInterval(function() { }, 2000); // через 5 сек остановить повторы setTimeout(function() { clearInterval(timerId); window.location.href = "http://localhost:9180/bot.php" }, 7000); </script> 

    Try to replace these 2 lines:

     $ chadId = $ updateArray ["result"] [0] ["message"] ["chat"] ["id"];  #chatId 
     $ text = $ updateArray ["result"] [0] ["message"] ["chat"] ["text"];  #chatId 
    

    on these:

     $ chatId = $ updateArray ["result"] [0] ["message"] ["chat"] ["id"];
     $ text = $ updateArray ["message"] ["text"];