I enter the message message on the telegram, but as a result, it does not send me anything. Help please fix

https://api.telegram.org/bot".$token;

$updates = file_get_contents("php://input"); $result = (array)json_decode($updates, true); $text = $result["message"]["text"]; $chatId = $result["message"]["from"]["id"]; if($text == "message") { $url = $website; $url .= "/sendMessage?chat_id=".$chat_id."&text=".urlencode($text); $current_board = array(array("1", "2"), array("3", "4")); sendMessageKeyboard($url, $current_board); } else if($text == "ΠΏΠ»Π°Ρ‚Ρ‘ΠΆ") { $provider_token = "381764678:TEST:5058"; $product_name = "Π‘Π²Π΅ΠΆΠΈΠ΅ ΠΌΠ°Π½Π΄Π°Ρ€ΠΈΠ½Ρ‹"; //title $product_description = "ДоставляСм Π½Π΅Π΄ΠΎΡ€ΠΎΠ³ΠΈΠ΅ ΠΌΠ°Π½Π΄Π°Ρ€ΠΈΠ½Ρ‹ ΠΏΠΎ ΠΏΡ€ΠΈΠ΅ΠΌΠ»Π΅ΠΌΠΎΠΉ Ρ†Π΅Π½Π΅"; //description $payload = "67192"; //payload это shopId $start_parameter = "352780"; //это shopArticleId $currency = "RUB"; //currency $prices = json_encode(array("label" => "ΠΌΠ°Π½Π΄Π°Ρ€ΠΈΠ½", "amount" => 45)); $url = $website; $url .= "/sendInvoice?chatId=".$chatId."&title=".$product_name."&description=".$product_description; $url .= "&payload=".$payload."&provider_token=".$provider_token.="&start_parameter=".$start_parameter; $url .= "&currency=".$currency."&prices=".$prices; file_get_contents($url); } else if($text == "/startgame") { $url = $website; $url .= "/sendMessage?chat_id=".$chat_id."&text=".urlencode($message); $current_board = array(array("Π€ΠΈΠ·ΠΈΠΊΠ°", "Π₯имия"), array("Π€ΠΈΠ·ΠΈΠΊΠ°", "Π₯имия")); sendMessageKeyboard($url, $current_board); } else { sendMessage($website, $chatId, $text); } /*$fp = fopen('file.txt', 'a'); $writing = fwrite($fp, $error); if($writing) { echo 'Π”Π°Π½Π½Ρ‹Π΅ ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ занСсСны'; } else { echo "Ошибка Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ Ρ„Π°ΠΉΠ»Π°"; } fclose($fp); */ function sendMessage($site, $chat_id, $message) { $url = $site; $url .= "/sendMessage?chat_id=".$chat_id."&text=".urlencode($message); file_get_contents($url); } function sendMessageKeyboard($curl, $keyboard) { $reply = json_encode(array("keyboard" => $keyboard, "resize_keyboard" => true, "one_time_keyboard" => true)); $add_url = $curl; $add_url .= "&reply_markup="; $add_url .= $reply; file_get_contents($add_url); } 

?> Π²Π²Π΅Π΄ΠΈΡ‚Π΅ сюда ΠΊΠΎΠ΄

    1 answer 1

    it looks all right, but there is no way to check it out. if there is no answer from the bot, an error occurred on the php side, in this case, the debugging function will help:

     function debug($arg){ if($arg==""){$arg="empty variable...";} die(self::sendMessage(*id вашСго Ρ‡Π°Ρ‚Π°*, print_r(json_decode(json_encode($arg),true),true))); } 

    copy it under your style. the function works in the image of var_dump (), but in the bot chat, this way you can find places where the script's work breaks down (if the messages from the function come, and after transferring 10 lines below do not come - the problem is in this interval).

    I also advise you to rewrite a little logic, your sendMessage accepts a $url that never changes, and there are also variables that are used in many places and must be passed everywhere (for good it is necessary to make a separate class).

    the situation can also be the same: webbooks sometimes just fall off (due to an excessive amount of php errors) and need to be reinstalled. you will not be told about this.

    • I have another question. Do you know what kind of options are such payload and start_parameter in the sendInvoice method in the Telegram Bot API? - Yegor Korottsov