tgbot-cpp
tgbot-cpp copied to clipboard
User's choise in sendPoll
How to know about the user's choice, whether he chose the correct answer or not?
Thanks! You can now add a listener with onPoll or with onPollAnswer depending on which Update object you need
What conditions does the handler onPollAnswer work? In my project onPoll work everytime, onPollAnswer - never
As stated in the docs, onPollAnswer fires, if someone answers the poll or if someone changes the answer in the poll sent by the bot. onPoll refers to the status of the poll itself and gives an update if the poll is closed with closePoll, for example. I tested it locally and can confirm that it works as intended. In case you encounter a different behaviour, could you provide a minimal code snippet to reproduce your problem?
Creation:
_bot = new TgBot::Bot (_key);
_bot->getEvents ().onPollAnswer (std::bind (&Daemon::cmdOnPollAnswer, this, std::placeholders::_1));
_bot->getEvents ().onPoll (std::bind (&Daemon::cmdOnPoll, this, std::placeholders::_1));
std::vector<TgBot::BotCommand::Ptr> commands;
auto command_question = std::make_shared<TgBot::BotCommand> ();
command_question->command = "question";
command_question->description = "Next question";
commands.push_back (command_question);
_bot->getApi ().setMyCommands (commands);
_bot->getEvents ().onCommand ("start", std::bind (&Daemon::cmdStart, this, std::placeholders::_1));
_bot->getEvents ().onCommand ("question", std::bind (&Daemon::cmdQuestion, this, std::placeholders::_1));
try
{
TgBot::TgLongPoll longPoll (*_bot, 100, 5);
while (_running)
{
longPoll.start ();
}
}
catch (TgBot::TgException& e)
{ }
Sending:
std::vector<std::string> options = {"1","2","3","4"};
_bot->getApi ().sendPoll (message->chat->id,
"Answers",
options,
false,
0,
std::make_shared<TgBot::GenericReply> (),
true,
"quiz",
false,
correct_answer,
explanation);
onPollAnswer:
Registers listener which receives an answer if a user changed their answer in a non-anonymous poll.
Does it help if you set isAnonymous = false
instead of true?
Thank you very much! Work great!