tgbot-cpp icon indicating copy to clipboard operation
tgbot-cpp copied to clipboard

Api: callback button spinning circle

Open teterevlev opened this issue 6 years ago • 1 comments

When I use the sample "inline-keyboard" on Android, the tapped button gets a spinning circle (as though waiting for answer). All everything else is ok. image

Here the code:

#include <exception>
#include <tgbot/tgbot.h>
using namespace std;
using namespace TgBot;
int main() {
    Bot bot(token);
    InlineKeyboardMarkup::Ptr keyboard(new InlineKeyboardMarkup);
    vector<InlineKeyboardButton::Ptr> row0;
    InlineKeyboardButton::Ptr checkButton(new InlineKeyboardButton);
    checkButton->text = "check";
    checkButton->callbackData = "check";
    row0.push_back(checkButton);
    keyboard->inlineKeyboard.push_back(row0);
    bot.getEvents().onCommand("start", [&bot, &keyboard](Message::Ptr message) {
        bot.getApi().sendMessage(message->chat->id, "ok", false, 0, keyboard);
    });
    bot.getEvents().onCallbackQuery([&bot, &keyboard](CallbackQuery::Ptr query) {
        if (StringTools::startsWith(query->data, "check")) {
            bot.getApi().sendMessage(query->message->chat->id, "ok", false, 0, keyboard);
        }
    });
    try {
        printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str());
        TgLongPoll longPoll(bot);
        while (true) {
            longPoll.start();
        }
    } catch (TgException& e) {
        printf("error: %s\n", e.what());
    }
    
    return 0;
}

teterevlev avatar Jan 19 '19 09:01 teterevlev

You have to call answerCallbackQuery (even if you don't want to give any user feedback) when reacting on Keyboard Callbacks. See Telegram Bot API documentation, especially the Note there. Upon calling that function the spinning circle will disappear, without calling the function it will only disappear after a few seconds.

Sil3ntStorm avatar Feb 06 '19 18:02 Sil3ntStorm