I can handle a callback query with an overwrited CallbackqueryCommand.PHP and then I do the following:
return $this->telegram->executeCommand('command', $this->update);
There I have the following lines for a message (not a callback):
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$text = $message->getText(true);
Is it possible to transform it to callback entity? I've tried several times without any success.
Thank you
This is how I handle commands that can be used with either command/message or callback query:
$message = $this->getMessage();
$callback_query = $this->getUpdate()->getCallbackQuery();
if ($message) {
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$text = $message->getText(true);
} elseif ($callback_query) {
$chat_id = $callback_query->getMessage()->getChat()->getId();
$user_id = $callback_query->getFrom()->getId();
$text = $callback_query->getData();
$data_callback = [];
$data_callback ['callback_query_id'] = $callback_query->getId();
}
// your code
$data = [];
$data['chat_id'] = $chat_id;
$data['parse_mode'] = 'HTML';
$data['disable_web_page_preview'] = true;
$data['text'] = $text;
if ($inline_keyboard) {
$data['reply_markup'] = new InlineKeyboardMarkup(['inline_keyboard' => $inline_keyboard]);
}
if ($message) {
return Request::sendMessage($data);
} elseif ($callback_query) {
Request::answerCallbackQuery($data_callback);
$data['message_id'] = $callback_query->getMessage()->getMessageId();
return Request::editMessageText($data);
} else {
return Request::emptyResponse();
}
Thank you! It works for me.
Most helpful comment
This is how I handle commands that can be used with either command/message or callback query: