Make next input message part of callback_query function in Telegram Bot

Viewed 180

I'm programming a Telegram Bot where it is shown to the user different options as inline buttons, one of them being "Search".

Once in search, I intend the next sent message to be the string to be used to search. However, I don't know how to make it so that the sent message is for the search query and not for other option/purposes. If the bot file is read again from start every time a message or button is pressed, there is no way I can tell the bot that the next message is a message related to the pressed button (search) or a standard message not related to the pressed button (I don't know if I'm clear enough with my doubt or I'm making it more complicated to understand).

So relevant part of the code looks like this:

  if(isset($request->callback_query->data)){
    $data = $request->callback_query->data;
    switch($data){
        case 'search':
            sendMessage($request->callback_query->message->chat->id, "Write what you want to search.");
    //(HERE is where the program should "wait" for the user to input something to be used in a DB query)
    //DBquery function 

                break;
        }
    }else{
        keyboard($request->message->chat->id, "Choose one of the following options:", $keyboard);
    }

$keyboard = array(
    "inline_keyboard" => [
        [
            ["text" => "\xF0\x9F\x94\x8E"." Search item","callback_data" => "search"],
            ["text" => "\xF0\x9F\x8C\x8F"." Visit web","url" => "https://website.com"]
            //more options to be written
        ]
    ]
);
0 Answers
Related