Ensuring Prompt Response Recognition in TelegramBot API Using PHP

When utilizing the TelegramBot API in PHP, I aim to prompt users for their name and age during onboarding. Initially, I ask for their name using the following code:


$bot->command('start', function ($message) use ($bot) {
    $bot->sendMessage($message->getChat()->getId(), "What's your name?", null, false, null);
});

Subsequently, I handle any input received:

$bot->on(function (TelegramBotApiTypesUpdate $update) use ($bot) {
    $message = $update->getMessage();
    $id = $message->getChat()->getId();
    $bot->sendMessage($id, 'Your name: ' . $message->getText());
}, function () {
    return true;
});

The concern arises regarding discerning whether the input corresponds to my prompt, as users can type at any time. How can I reliably identify if the input is in response to my question?

Analyzed the context of incoming messages to determine if they follow a logical sequence from your prompt