diff options
author | llnulldisk <48621230+llnulldisk@users.noreply.github.com> | 2022-08-30 20:06:06 +0200 |
---|---|---|
committer | llnulldisk <48621230+llnulldisk@users.noreply.github.com> | 2022-08-30 20:06:06 +0200 |
commit | e1651b15f37f194436fd4c8a30b9a6d5c9775232 (patch) | |
tree | 78a3193074de8fbc837af82dc12f67eca7fed500 | |
parent | 4aa6af3180aef70f9a4320a2f6d818f68f5bb669 (diff) |
Update to API 4.8
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | include/tgbot/Api.h | 14 | ||||
-rw-r--r-- | include/tgbot/types/Dice.h | 9 | ||||
-rw-r--r-- | include/tgbot/types/Poll.h | 21 | ||||
-rw-r--r-- | src/Api.cpp | 30 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 10 |
6 files changed, 72 insertions, 14 deletions
@@ -12,7 +12,7 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp). ## State - [x] Bot API 3.0 ~ 3.6 -- [x] Bot API 4.0 ~ 4.7 (Implemented all APIs except 'Telegram Passport') +- [x] Bot API 4.0 ~ 4.8 (Implemented all APIs except 'Telegram Passport') ## Sample diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 755998b..9613c15 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -350,6 +350,10 @@ public: * @param type Optional. Poll type, “quiz” or “regular”, defaults to “regular” * @param allowsMultipleAnswers Optional. True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False * @param correctOptionId Optional. 0-based identifier of the correct answer option, required for polls in quiz mode + * @param explanation Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing + * @param explanationParseMode Optional. Mode for parsing entities in the explanation. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param openPeriod Optional. Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date. + * @param closeDate Optional. Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period. * @param isClosed Optional. Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. * @param replyToMessageId Optional. If the message is a reply, ID of the original message @@ -359,8 +363,9 @@ public: */ Message::Ptr sendPoll(std::int64_t chatId, const std::string& question, const std::vector<std::string>& options, bool isAnonymous = true, const std::string& type = "", bool allowsMultipleAnswers = false, - std::int32_t correctOptionId = 0, bool isClosed = false, bool disableNotification = false, - std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; + std::int32_t correctOptionId = 0, const std::string& explanation = "", const std::string& explanationParseMode = "", + std::int32_t openPeriod = 0, std::int64_t closeDate = 0, bool isClosed = false, + bool disableNotification = false, std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * @brief Deprecated. Use @ref Api::sendPoll @@ -373,14 +378,15 @@ public: * @brief Use this method to send a dice, which will have a random value from 1 to 6. * * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param emoji Optional. Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲” * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. * @param replyToMessageId Optional. If the message is a reply, ID of the original message * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. * * @return On success, the sent @ref Message is returned. */ - Message::Ptr sendDice(std::int64_t chatId, bool disableNotification = false, std::int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; + Message::Ptr sendDice(std::int64_t chatId, const std::string& emoji = "", bool disableNotification = false, + std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * @brief Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). diff --git a/include/tgbot/types/Dice.h b/include/tgbot/types/Dice.h index ec874e0..3179f4a 100644 --- a/include/tgbot/types/Dice.h +++ b/include/tgbot/types/Dice.h @@ -6,7 +6,7 @@ namespace TgBot { /** - * @brief This object represents a dice with random value from 1 to 6. + * @brief This object represents a dice with a random value from 1 to 6 for currently supported base emoji. * * @ingroup types */ @@ -16,7 +16,12 @@ public: typedef std::shared_ptr<Dice> Ptr; /** - * @brief Value of the dice, 1-6 + * @brief Emoji on which the dice throw animation is based + */ + std::string emoji; + + /** + * @brief Value of the dice, 1-6 for currently supported base emoji */ std::int8_t value; }; diff --git a/include/tgbot/types/Poll.h b/include/tgbot/types/Poll.h index e1f9d2c..2a75c68 100644 --- a/include/tgbot/types/Poll.h +++ b/include/tgbot/types/Poll.h @@ -2,6 +2,7 @@ #define TGBOT_POLL_H #include "tgbot/types/PollOption.h" +#include "tgbot/types/MessageEntity.h" #include <cstdint> #include <memory> @@ -65,6 +66,26 @@ public: * Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot. */ std::int32_t correctOptionId; + + /** + * @brief Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters + */ + std::string explanation; + + /** + * @brief Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation + */ + std::vector<MessageEntity::Ptr> explanationEntities; + + /** + * @brief Optional. Amount of time in seconds the poll will be active after creation + */ + std::int32_t openPeriod; + + /** + * @brief Optional. Point in time (Unix timestamp) when the poll will be automatically closed + */ + std::int64_t closeDate; }; } diff --git a/src/Api.cpp b/src/Api.cpp index def9243..24ae56f 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -533,10 +533,11 @@ Message::Ptr Api::sendContact(std::int64_t chatId, const string& phoneNumber, co Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, const std::vector<std::string>& options, bool isAnonymous, const std::string& type, bool allowsMultipleAnswers, - std::int32_t correctOptionId, bool isClosed, bool disableNotification, - std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { + std::int32_t correctOptionId, const std::string& explanation, const std::string& explanationParseMode, + std::int32_t openPeriod, std::int64_t closeDate, bool isClosed, + bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { vector<HttpReqArg> args; - args.reserve(11); + args.reserve(15); args.emplace_back("chat_id", chatId); args.emplace_back("question", question); @@ -555,6 +556,18 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, con if (correctOptionId != 0) { args.emplace_back("correct_option_id", correctOptionId); } + if (!explanation.empty()) { + args.emplace_back("explanation", explanation); + } + if (!explanationParseMode.empty()) { + args.emplace_back("explanation_parse_mode", explanationParseMode); + } + if (openPeriod != 0) { + args.emplace_back("open_period", openPeriod); + } + if (closeDate != 0) { + args.emplace_back("close_date", closeDate); + } if (isClosed) { args.emplace_back("is_closed", isClosed); } @@ -574,18 +587,21 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, con Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, const std::vector<std::string>& options, bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { - return sendPoll(chatId, question, options, true, "", false, 0, false, disableNotification, replyToMessageId, replyMarkup); + return sendPoll(chatId, question, options, true, "", false, 0, "", "", 0, 0, false, false, 0); } -Message::Ptr Api::sendDice(std::int64_t chatId, bool disableNotification, std::int32_t replyToMessageId, - GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendDice(std::int64_t chatId, const std::string& emoji, bool disableNotification, + std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { vector<HttpReqArg> args; - args.reserve(4); + args.reserve(5); args.emplace_back("chat_id", chatId); if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (!emoji.empty()) { + args.emplace_back("emoji", emoji); + } if (replyToMessageId != 0) { args.emplace_back("reply_to_message_id", replyToMessageId); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 41cf642..d1d0ecb 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -430,6 +430,10 @@ Poll::Ptr TgTypeParser::parseJsonAndGetPoll(const ptree& data) const { result->type = data.get<string>("type", ""); result->allowsMultipleAnswers = data.get<bool>("allows_multiple_answers", false); result->correctOptionId = data.get<int32_t>("correct_option_id", 0); + result->explanation = data.get<string>("explanation", ""); + result->explanationEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "explanation_entities"); + result->openPeriod = data.get<int32_t>("open_period", 0); + result->closeDate = data.get<int64_t>("close_date", 0); return result; } @@ -448,6 +452,10 @@ string TgTypeParser::parsePoll(const Poll::Ptr& object) const { appendToJson(result, "type", object->type); appendToJson(result, "allows_multiple_answers", object->allowsMultipleAnswers); appendToJson(result, "correct_option_id", object->correctOptionId); + appendToJson(result, "explanation", object->correctOptionId); + appendToJson(result, "explanation_entities", parseArray(&TgTypeParser::parseMessageEntity, object->explanationEntities)); + appendToJson(result, "open_period", object->openPeriod); + appendToJson(result, "close_date", object->closeDate); removeLastComma(result); result += '}'; return result; @@ -455,6 +463,7 @@ string TgTypeParser::parsePoll(const Poll::Ptr& object) const { Dice::Ptr TgTypeParser::parseJsonAndGetDice(const ptree& data) const { auto result(make_shared<Dice>()); + result->emoji = data.get<string>("emoji", ""); result->value = data.get<int8_t>("value", 0); return result; } @@ -465,6 +474,7 @@ string TgTypeParser::parseDice(const Dice::Ptr& object) const { } string result; result += '{'; + appendToJson(result, "emoji", object->emoji); appendToJson(result, "value", object->value); removeLastComma(result); result += '}'; |