php-telegram-bot / example-bot

[WIP] An A-Z example of a PHP Telegram Bot.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conversation in CallbackqueryCommand?

sascha-hendel opened this issue · comments

Is it possible to start a conservation by pressing a InlineKeyboardButton (handle new Conversation() in CallbackqueryCommand.php)?

hello. yes you can to that by sending a Callback with the InlineKeyboard and using CallbackQueryCommand.php to fetch that callbackquery. Using $this->telegram->executeCommand('commandname'); you can start the Conversationcommand that handles the conversation. To get the chatID and userID you need to extract them from the CallbackQuery itself since the command was started by the Callbackquery and not by the user

 if ($this->getCallbackQuery() !== null) {
    $message  = $this->getCallbackQuery()->getMessage();
    $callback_query     = $this->getCallbackQuery();
    $callback_data     = $callback_query->getData();
    $chat    = $message->getChat();
    $user    = $callback_query->getFrom();
    $text    = $callback_data;
    $chat_id = $chat->getId();
    $user_id = $callback_query->getFrom()->getId();
}
else {
    $message = $this->getMessage();
    $chat    = $message->getChat();
    $user    = $message->getFrom();
    $text    = trim($message->getText(true));
    $chat_id = $chat->getId();
    $user_id = $user->getId();
} 

In addition, if you want to use inlinekeyboards within a Conversation you need to change some stuff, listed in here https://pastebin.com/qxQAekwj