diff --git a/src/qTbot/src/public/qTbot/itelegrambot.cpp b/src/qTbot/src/public/qTbot/itelegrambot.cpp index d8fd103..f1e617e 100644 --- a/src/qTbot/src/public/qTbot/itelegrambot.cpp +++ b/src/qTbot/src/public/qTbot/itelegrambot.cpp @@ -70,6 +70,41 @@ bool ITelegramBot::sendMessage(const QVariant &chatId, const QString &text) { return sendSpecificMessage(TelegramArgs{chatId, text}); } +bool ITelegramBot::sendLocationRequest(const QVariant &chatId, const QString &text, const QString &buttonText, + bool onetimeKeyboard) { + + auto replyMarkup = QSharedPointer<QJsonObject>::create(); + QJsonArray keyboard; + QJsonObject contactButton; + contactButton["text"] = buttonText; + contactButton["request_location"] = true; + QJsonArray row; + row.append(contactButton); + keyboard.append(row); + replyMarkup->insert("keyboard", keyboard); + replyMarkup->insert("resize_keyboard", true); + replyMarkup->insert("one_time_keyboard", onetimeKeyboard); + + return sendSpecificMessage(TelegramArgs{chatId, text}, {{"reply_markup", replyMarkup}}); +} + +bool ITelegramBot::sendSelfContactRequest(const QVariant &chatId, const QString &text, const QString &buttonText, + bool onetimeKeyboard) { + auto replyMarkup = QSharedPointer<QJsonObject>::create(); + QJsonArray keyboard; + QJsonObject contactButton; + contactButton["text"] = buttonText; + contactButton["request_contact"] = true; + QJsonArray row; + row.append(contactButton); + keyboard.append(row); + replyMarkup->insert("keyboard", keyboard); + replyMarkup->insert("resize_keyboard", true); + replyMarkup->insert("one_time_keyboard", onetimeKeyboard); + + return sendSpecificMessage(TelegramArgs{chatId, text}, {{"reply_markup", replyMarkup}}); +} + bool ITelegramBot::sendSpecificMessage(const TelegramArgs& args, const ExtraJsonObjects &extraObjects) { diff --git a/src/qTbot/src/public/qTbot/itelegrambot.h b/src/qTbot/src/public/qTbot/itelegrambot.h index f00ed83..82e140b 100644 --- a/src/qTbot/src/public/qTbot/itelegrambot.h +++ b/src/qTbot/src/public/qTbot/itelegrambot.h @@ -42,6 +42,24 @@ public: bool sendMessage(const QVariant &chatId, const QString& text) override; + /** + * @brief sendLocationRequest This method setn into chat button that will automaticaly sent geo location to bot. + * @param chatId + * @param text message text + * @param buttonText Text on the button + * @return true if request sents successfull else false. + */ + bool sendLocationRequest(const QVariant &chatId, const QString& text, const QString &buttonText, bool onetimeKeyboard); + + /** + * @brief sendSelfContactRequest This method sent into chat button that will automaticaly sent self contact information to bot. + * @param chatId + * @param text message text + * @param buttonText Text on the button + * @return true if request sents successfull else false. + */ + bool sendSelfContactRequest(const QVariant &chatId, const QString& text, const QString &buttonText, bool onetimeKeyboard); + /** * @brief Sends a specific message to a chat. *