Answer the question
In order to leave comments, you need to log in
How to track just TelegramBot text?
I use the TelegramBot\Api library . I can receive commands, but I cannot receive simple text. How can this be done?
$bot = new \TelegramBot\Api\Client($token);
$botApi = new \TelegramBot\Api\BotApi($token);
$bot->command('start', function($message) use ($bot) {
$chatId = $message->getChat()->getId();
$answer = "Здравствуйте!";
$bot->sendMessage($chatId, $answer);
});
$bot->run();
$bot->command('register', function($message) use ($bot) {
$chatId = $message->getChat()->getId();
$text = $message->getText();
$param = str_replace('/register', '', $text);
$answer = 'Укажите пожалуйста логин';
if(!empty($param)) {
$answer = "Ваш логин: $param";
}
$bot->sendMessage($chatId, $answer);
});
Answer the question
In order to leave comments, you need to log in
The text can be obtained in this way:
$body = json_decode($bot->getRawBody(), true);
$message = isset($body['message']['text']) ? mb_strtolower($body['message']['text']) : '';
user_id|reg_process
123 | 0
user_id|reg_process
123 | 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question