Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TgBot::ReplyKeyboardMarkup::Ptr and problems with it #339

Copy link
Copy link
@artemka-sh

Description

@artemka-sh
Issue body actions

Using this keyboard as in examples sometimes I get something other than what I write in the buttons, sometimes a random offer to send a phone number or geolocation may pop up, although nothing like that was written

void TelegramMessenger::sendQuestionWithKeyboard(qint64 userId, const Question& question) {
    std::string text = question.question;
    TgBot::ReplyKeyboardMarkup::Ptr keyboard(new TgBot::ReplyKeyboardMarkup);
    keyboard->resizeKeyboard = true;
    keyboard->oneTimeKeyboard = true;
    if (!question.answers.empty()) {
        keyboard->keyboard.clear();
        for (const auto& ans : question.answers) {
            std::vector<TgBot::KeyboardButton::Ptr> row;
            TgBot::KeyboardButton::Ptr btn(new TgBot::KeyboardButton);
            btn->text = ans;
            row.push_back(btn);
            keyboard->keyboard.push_back(row);
        }
    } else {
        keyboard = nullptr;
    }
    bot->getApi().sendMessage(userId, text, nullptr, nullptr, keyboard);
} 

Here is the code that crashed, it is created and sent to functions in its scope
I don't know why you need to add these parameters for everything to work well, I haven't tested it completely yet, but the message with the pop-up window asking to send a phone number no longer popped up

void TelegramMessenger::sendQuestionWithKeyboard(qint64 userId, const Question question) {
    std::string text = question.question;
    TgBot::ReplyKeyboardMarkup::Ptr keyboard(new TgBot::ReplyKeyboardMarkup);
    keyboard->resizeKeyboard = true;
    keyboard->oneTimeKeyboard = true;
    if (!question.answers.empty()) {
        keyboard->keyboard.clear();
        for (const auto& ans : question.answers) {
            std::vector<TgBot::KeyboardButton::Ptr> row;
            TgBot::KeyboardButton::Ptr btn(new TgBot::KeyboardButton);
            btn->text = ans;
            btn->requestContact = false;
            btn->requestLocation = false;
            btn->requestPoll = TgBot::KeyboardButtonPollType::Ptr();
            row.push_back(btn);
            keyboard->keyboard.push_back(row);
        }
    } else {
        keyboard = nullptr;
    }
    bot->getApi().sendMessage(userId, text, nullptr, nullptr, keyboard);
} 

I'm leaving this here, maybe it will help someone a little.
I'll be glad if you tell me what I'm doing wrong, I remember creating this keyboard with permanent storage and tried everything, somehow I managed to do it by manipulating memory so that this error doesn't appear, but I don't remember how)

I hope I managed to convey the idea

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.