Answer the question
In order to leave comments, you need to log in
How to fulfill a condition in PHP?
Hello colleagues. There is data that, when data enters php://input, is processed by instructions in a php file.
In this example
function processMessage($message) {
$message_id = $message['message_id'];
$chat_id = $message['chat']['id'];
if (isset($message['text'])) {
$text = $message['text'];
$lastcom = $text;
if ($text === "/start") {
apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => '
Привет! Вы стартовали бота!
', 'parse_mode' => 'Markdown'));
}
else if ($text === "/stop") {
apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => '
Вы остановили бота!
', 'parse_mode' => 'Markdown'));
}
else if ($text === "Оставить отзыв") {
apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => '
Оставьте свой отзыв:
', 'parse_mode' => 'Markdown'));
}
// любой текст, который поступает после команды "Оставить отзыв" должен записываться в файл, пока не будет введено "Стоп"
}
}
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (!$update) {
// receive wrong update, must not happen
exit;
}
//если message не является пустым, то отправляем сообщение
if (isset($update["message"])) {
processMessage($update["message"]);
}
Answer the question
In order to leave comments, you need to log in
It is necessary to fix the current state of the bot user, with whom the dialogue is taking place.
Describe the rules, which commands under which states can be executed.
When the command "Leave feedback" change the state to waiting for input feedback. After the "Stop" command, change the state to waiting for the input of commands.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question