Please tell me how to write a simple script for the bot, for example:
wrote the command "/ test",
bot asks: "Are you sure?"
write in response: "Yes"
The bot sends the following message according to the script, if you write "no" - the script ends.
It is important that my answer “Yes” is not processed by the bot until it asks “Are you sure?” (After the / test command)
<?php $access_token = '...'; $api = 'https://api.telegram.org/bot' . $access_token; $output = json_decode(file_get_contents('php://input'), TRUE); $chat_id = $output['message']['chat']['id']; $first_name = $output['message']['chat']['first_name']; $message = $output['message']['text']; switch($message) { case '/test': sendMessage($chat_id, "Вы уверены?"); break; default: $sorry_text = $first_name . ' , мне нечего ответить'; sendMessage($chat_id, $sorry_text); } function sendMessage($chat_id, $message, $encodedMarkup) { file_get_contents($GLOBALS['api'] . '/sendMessage?chat_id=' . $chat_id . '&text=' . urlencode($message) . $encodedMarkup); }
I realized that this is done through ForceReply, but I have not figured it out yet.
UPDATE made an inline keybord, but for the time being did not understand how to display a message depending on the pressed case '/ test' button:
$x1 = array("text"=>"First Button","callback_data"=>"test1"); $x2 = array("text"=>"Second Button","callback_data"=>"test2"); $opz = [[$x1,$x2]]; $keyboard=array("inline_keyboard"=>$opz); $keyboard = json_encode($keyboard); sendMessage($chat_id, "testt2", $keyboard); break;
those. now when you press the button nothing is displayed
ForceReply
. - Anatol