php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.87k stars 951 forks source link

InlineKeyboard callback features #404

Closed dzarezenko closed 7 years ago

dzarezenko commented 7 years ago

Hi, I have implemented InlineKeyboard functionality in my bot. This is a set of buttons with bullets, each button represents a category. All works fine on the server side, but I need changes on the client in the Telegram:

  1. I want show/hide bullet on button click, when user check/uncheck category. How can I do this with your lib?
  2. How can I remove top drop-down message on button click ("Hello World!")?

tb

Thanks!

jacklul commented 7 years ago

Store which buttons are checked using Conversation's notes array?

dzarezenko commented 7 years ago

@jacklul Sorry, what do you mean?

jacklul commented 7 years ago

Look into surveycommand example, use Conversation to store which ones are checked.

"Hello world" is handled by Callbackquerycommand, that's where you can remove it and place your own code.

dzarezenko commented 7 years ago

Thank you for the response. I have resolved both my issues:

  1. Resolved with Request::editMessageReplyMarkup:

    Longman\TelegramBot\Request::editMessageReplyMarkup([
    'chat_id'      => $this->chatId,
    'message_id'   => $this->messageId,
    'reply_markup' => $this->generateKeyboard()
    ]);

    I detect what button is pressed by callback_data parameter of the InlineKeyboard button, something like

    [
    'text' => (isset($userCategories[$category->id]) ? Icons::LARGE_RED_CIRCLE . " " : "") . $category->title,
    'callback_data' => "setCategory:{$category->id}"
    ]

    so I know what action to perform and with what category (what button pressed).

  2. I have resolved by replacing CallbackqueryCommand class with my own class as you suggested.

Thanks!