example-bot icon indicating copy to clipboard operation
example-bot copied to clipboard

Conversation in CallbackqueryCommand?

Open sascha-hendel opened this issue 2 years ago • 1 comments

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

sascha-hendel avatar Nov 26 '23 16:11 sascha-hendel

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

Hitmare avatar Jun 18 '24 08:06 Hitmare