A
A
Alex Goncharov2016-04-27 17:59:15
PHP
Alex Goncharov, 2016-04-27 17:59:15

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"]);
}

The question is. I need to add a "Leave Feedback" command. That is, as soon as the bot receives the text "Leave feedback" - then everything that is sent to it, for example, is written to a file.
Any message received after the person sent "Leave Feedback" is written to the file. That is, the loop is executed until the person enters "Stop".
As soon as the bot receives the "Stop" command, it stops executing the instructions that come after "Leave feedback" and already freely reacts to any text entered. The Leave Feedback command is terminated.
Where exactly should code be inserted that runs indefinitely until a "Stop" command is received?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nllm, 2016-04-27
@nllm

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 question

Ask a Question

731 491 924 answers to any question