Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User's choise in sendPoll #235

Open
minigo opened this issue Oct 13, 2022 · 6 comments
Open

User's choise in sendPoll #235

minigo opened this issue Oct 13, 2022 · 6 comments

Comments

@minigo
Copy link

minigo commented Oct 13, 2022

How to know about the user's choice, whether he chose the correct answer or not?

llnulldisk added a commit to llnulldisk/tgbot-cpp that referenced this issue Oct 18, 2022
@llnulldisk
Copy link
Contributor

llnulldisk commented Oct 18, 2022

Thanks! You can now add a listener with onPoll or with onPollAnswer depending on which Update object you need

@minigo
Copy link
Author

minigo commented Nov 14, 2022

What conditions does the handler onPollAnswer work? In my project onPoll work everytime, onPollAnswer - never

@llnulldisk
Copy link
Contributor

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?

@minigo
Copy link
Author

minigo commented Nov 15, 2022

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);

@llnulldisk
Copy link
Contributor

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?

@minigo
Copy link
Author

minigo commented Nov 17, 2022

Thank you very much! Work great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants