diff options
author | Oleg Morozenkov <m@oleg.rocks> | 2019-12-05 01:24:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-05 01:24:58 +0300 |
commit | a888db726815a9600ea3b16ea045644b51e2898b (patch) | |
tree | 9e12cb0382e8cae450741ac3a86be082cbe9ca89 /include | |
parent | 76f36598570a13862471175cbfdbfb9dec4139d2 (diff) | |
parent | dc8272ef5de54c65243e66715a1683d004ab74cb (diff) |
Merge pull request #116 from nitanmarcel/api_update_pr
Update BOT API to 4.2~4.4
Diffstat (limited to 'include')
-rw-r--r-- | include/tgbot/Api.h | 50 | ||||
-rw-r--r-- | include/tgbot/TgTypeParser.h | 13 | ||||
-rw-r--r-- | include/tgbot/types/Chat.h | 7 | ||||
-rw-r--r-- | include/tgbot/types/ChatMember.h | 10 | ||||
-rw-r--r-- | include/tgbot/types/ChatPermissions.h | 86 | ||||
-rw-r--r-- | include/tgbot/types/InlineKeyboardButton.h | 6 | ||||
-rw-r--r-- | include/tgbot/types/LoginUrl.h | 45 | ||||
-rw-r--r-- | include/tgbot/types/Message.h | 17 | ||||
-rw-r--r-- | include/tgbot/types/Poll.h | 63 | ||||
-rw-r--r-- | include/tgbot/types/PollOption.h | 50 | ||||
-rw-r--r-- | include/tgbot/types/Sticker.h | 5 | ||||
-rw-r--r-- | include/tgbot/types/StickerSet.h | 5 |
12 files changed, 349 insertions, 8 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index ec9edf8..02e68a5 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -290,6 +290,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ + Message::Ptr sendVideo(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming = false, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string& caption = "", int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; @@ -584,7 +585,7 @@ public: /** * @brief Use this method to delete messages sent by bot (or by other users if bot is admin). - * @param chatId Unique identifier for the target chat. + * @param chatId Unique identifier for the target chat or username of the target channel. * @param messageId Unique identifier for the target message. */ void deleteMessage(int64_t chatId, int32_t messageId) const; @@ -677,8 +678,7 @@ public: * @param canAddWebPagePreviews Optional. Pass True, if the user may add web page previews to their messages, implies can_send_media_messages. * @return True on success */ - bool restrictChatMember(int64_t chatId, int32_t userId, uint64_t untilDate = 0, bool canSendMessages = false, - bool canSendMediaMessages = false, bool canSendOtherMessages = false, bool canAddWebPagePreviews = false) const; + bool restrictChatMember(int64_t chatId, int32_t userId, ChatPermissions::Ptr permissions, uint64_t untilDate = 0) const; /** * @brief Use this method to promote or demote a user in a supergroup or a channel. @@ -698,6 +698,14 @@ public: bool canEditMessages = false, bool canDeleteMessages = false, bool canInviteUsers = false, bool canPinMessages = false, bool canPromoteMembers = false) const; /** + * @brief Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success. + * @param chatId Unique identifier for the target chat of the target supergroup. + * @param permissions New default chat permissions. + * @return True on success + */ + bool setChatPermissions(int64_t chatId, ChatPermissions::Ptr permissions) const; + + /** * @brief Use this method to generate a new invite link for a chat; any previously generated link is revoked. * @param chatId Unique identifier for the target chat. * @return The new invite link as String on success. @@ -745,8 +753,8 @@ public: bool setChatDescription(int64_t chatId, const std::string& description) const; /** - * @brief Use this method to pin a message in a supergroup or a channel. - * @param chatId Unique identifier for the target chat. + * @brief Use this method to pin a message in a group, a supergroup, or a channel. + * @param chatId Unique identifier for the target chat or username of the target channel. * @param messageId Identifier of a message to pin. * @param disableNotification Optional. Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels. * @return True on success @@ -754,8 +762,8 @@ public: bool pinChatMessage(int64_t chatId, int32_t messageId, bool disableNotification = false) const; /** - * @brief Use this method to unpin a message in a supergroup or a channel. - * @param chatId Unique identifier for the target chat. + * @brief Use this method to unpin a message in a group, a supergroup, or a channel. + * @param chatId Unique identifier for the target chat or username of the target channel. * @return True on success */ bool unpinChatMessage(int64_t chatId) const; @@ -791,7 +799,6 @@ public: std::vector<GameHighScore::Ptr> getGameHighScores(int32_t userId, int32_t score, bool force = false, bool disableEditMessage = false, int64_t chatId = 0, int32_t messageId = 0, const std::string& inlineMessageId = "") const; - /** * @brief Downloads file from Telegram and saves it in memory. * @param filePath Telegram file path. @@ -800,6 +807,33 @@ public: */ std::string downloadFile(const std::string& filePath, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const; + /** + * @brief Use this method to send a poll. + * @param chatId Unique identifier for the target chat or username of the target channel. + * @param question Poll question, 1-255 characters. + * @param options List of answer options, 2-10 strings 1-100 characters each. + * @param disable_notification Optional. Sends the message silenty. + * @param reply_to_message_id Optional. If the message is a reply, ID of the original message. + * @param reply_markup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. + * + * @return On success, the sent message is returned. + */ + Message::Ptr sendPoll(int64_t chatId, std::string question, std::vector<std::string> options, bool disable_notification=false, int32_t reply_to_message_id=0,GenericReply::Ptr reply_markup = std::make_shared<GenericReply>()) const; + + /** + * @brief Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.. + * @param chatId Unique identifier for the target chat or username of the target channel. + * @param question Poll question, 1-255 characters. + * @param options List of answer options, 2-10 strings 1-100 characters each. + * @param disable_notification Optional. Sends the message silenty. + * @param reply_to_message_id Optional. If the message is a reply, ID of the original message. + * @param reply_markup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. + * + * @return On success, the sent message is returned. + */ + + Poll::Ptr stopPoll(int64_t chatId, int64_t messageId, InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared<InlineKeyboardMarkup>()) const; + private: boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const; diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 979ba55..6cda5a7 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -36,6 +36,9 @@ #include "tgbot/types/Document.h" #include "tgbot/types/Sticker.h" #include "tgbot/types/StickerSet.h" +#include "tgbot/types/Poll.h" +#include "tgbot/types/PollOption.h" +#include "tgbot/types/ChatPermissions.h" #include "tgbot/types/MaskPosition.h" #include "tgbot/types/Video.h" #include "tgbot/types/Voice.h" @@ -145,6 +148,15 @@ public: MaskPosition::Ptr parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const; std::string parseMaskPosition(const MaskPosition::Ptr& object) const; + Poll::Ptr parseJsonAndGetPoll(const boost::property_tree::ptree& data) const; + std::string parsePoll(const Poll::Ptr& object) const; + + PollOption::Ptr parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const; + std::string parsePollOption(const PollOption::Ptr& object) const; + + ChatPermissions::Ptr parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const; + std::string parseChatPermissions(const ChatPermissions::Ptr& object) const; + Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const; std::string parseVideo(const Video::Ptr& object) const; @@ -476,6 +488,7 @@ private: json += std::to_string(value); json += ','; } + inline void appendToJson(std::string &json, const std::string &varName, const int &value) const { appendToJsonNumber(json, varName, value); } inline void appendToJson(std::string &json, const std::string &varName, const long &value) const { appendToJsonNumber(json, varName, value); } inline void appendToJson(std::string &json, const std::string &varName, const long long &value) const { appendToJsonNumber(json, varName, value); } diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h index a402ebb..eb38ec7 100644 --- a/include/tgbot/types/Chat.h +++ b/include/tgbot/types/Chat.h @@ -27,6 +27,7 @@ #include <memory> #include "tgbot/types/ChatPhoto.h" +#include "tgbot/types/ChatPermissions.h" namespace TgBot { @@ -111,6 +112,12 @@ public: std::shared_ptr<Message> pinnedMessage; /** + * @brief Optional. Default chat member permissions, for groups and supergroups. + * Returned only in getChat. + */ + ChatPermissions::Ptr permissions; + + /** * @brief Optional. For supergroups, name of group sticker set. * Returned only in getChat. */ diff --git a/include/tgbot/types/ChatMember.h b/include/tgbot/types/ChatMember.h index facfec2..f5e5acd 100644 --- a/include/tgbot/types/ChatMember.h +++ b/include/tgbot/types/ChatMember.h @@ -77,6 +77,11 @@ public: bool canPinMessages = false; /** + * @brief Optional. Restricted only. True, if the user is a member of the chat at the moment of the request. + */ + bool isMember = false; + + /** * @brief Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user). */ bool canPromoteMembers = false; @@ -97,6 +102,11 @@ public: bool canSendOtherMessages = false; /** + * @brief Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages. + */ + bool canSendPolls = false; + + /** * @brief Optional. Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages. */ bool canAddWebPagePreviews = false; diff --git a/include/tgbot/types/ChatPermissions.h b/include/tgbot/types/ChatPermissions.h new file mode 100644 index 0000000..8db32e6 --- /dev/null +++ b/include/tgbot/types/ChatPermissions.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2019 Marcel Alexandru + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_CPP_CHATPERMISSIONS_H +#define TGBOT_CPP_CHATPERMISSIONS_H + +#include <memory> +#include <string> + + +namespace TgBot { + + /** + * @brief This object describes actions that a non-administrator user is allowed to take in a chat. + * @ingroup types + */ + + class ChatPermissions { + public: + typedef std::shared_ptr<ChatPermissions> Ptr; + + /** + * @brief Optional. True, if the user is allowed to send text messages, contacts, locations and venues. + */ + bool canSendMessages = false; + + /** + * @brief Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages. + */ + bool canSendMediaMessages = false; + + /** + * @brief Optional. True, if the user is allowed to send polls, implies can_send_messages. + */ + bool canSendPolls = false; + + /** + * @brief Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages. + */ + bool canSendOtherMessages = false; + + /** + * @brief Optional. True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages. + */ + bool canAddWebPagePreviews = false; + + /** + * @brief Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups. + */ + bool canChangeInfo = false; + + /** + * @brief Optional. True, if the user is allowed to invite new users to the chat. + */ + bool canInviteUsers = false; + + /** + * @brief Optional. True, if the user is allowed to pin messages. Ignored in public supergroups. + */ + bool canPinMessages = false; + + + + }; +} + +#endif //TGBOT_CPP_CHATPERMISSIONS_H diff --git a/include/tgbot/types/InlineKeyboardButton.h b/include/tgbot/types/InlineKeyboardButton.h index 4b83087..f274825 100644 --- a/include/tgbot/types/InlineKeyboardButton.h +++ b/include/tgbot/types/InlineKeyboardButton.h @@ -9,6 +9,7 @@ #include <memory> #include "tgbot/types/CallbackGame.h" +#include "tgbot/types/LoginUrl.h" namespace TgBot { @@ -32,6 +33,11 @@ public: std::string url; /** + * @brief Optional. An HTTP URL used to automatically authorize the user. + */ + LoginUrl::Ptr loginUrl; + + /** * @brief Optional. Data to be sent in a callback query to the bot when button is pressed. */ std::string callbackData; diff --git a/include/tgbot/types/LoginUrl.h b/include/tgbot/types/LoginUrl.h new file mode 100644 index 0000000..1627399 --- /dev/null +++ b/include/tgbot/types/LoginUrl.h @@ -0,0 +1,45 @@ +// +// Created by alexandrumarcel on 19.11.2019. +// + +#ifndef TGBOT_CPP_LOGINURL_H +#define TGBOT_CPP_LOGINURL_H + +#include <memory> +#include <string> +#include <vector> + + +namespace TgBot{ + /** + * @brief This object represents a Poll. + * + * @ingroup types + */ + class LoginUrl{ + public: + typedef std::shared_ptr<LoginUrl> Ptr; + + /** + * @brief UAn HTTP URL to be opened with user authorization data added to the query string when the button is pressed.. + */ + std::string url; + + /** + * @brief Optional. New text of the button in forwarded messages. + */ + std::string forward_text; + + /** + * @brief Optional. Username of a bot, which will be used for user authorization. + */ + std::string bot_username; + + /** + * @brief Optional. Pass True to request the permission for your bot to send messages to the user. + */ + bool request_write_access; + }; +} + +#endif //TGBOT_CPP_LOGINURL_H diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index f92eeaf..9e831bc 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -34,6 +34,7 @@ #include "tgbot/types/Document.h" #include "tgbot/types/Animation.h" #include "tgbot/types/Sticker.h" +#include "tgbot/types/Poll.h" #include "tgbot/types/Video.h" #include "tgbot/types/Contact.h" #include "tgbot/types/Location.h" @@ -44,6 +45,7 @@ #include "tgbot/types/Voice.h" #include "tgbot/types/Invoice.h" #include "tgbot/types/SuccessfulPayment.h" +#include "tgbot/types/InlineKeyboardMarkup.h" namespace TgBot { @@ -97,6 +99,11 @@ public: std::string forwardSignature; /** + * @brief Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages. + */ + std::string forwardSenderName; + + /** * @brief Optional. For forwarded messages, date the original message was sent in Unix time. */ int32_t forwardDate; @@ -194,6 +201,11 @@ public: Venue::Ptr venue; /** + * @brief Optional. Message is a poll, information about the poll. + */ + Poll::Ptr poll; + + /** * @brief Optional. A new member was added to the group, information about them (this member may be bot itself). */ User::Ptr newChatMember; @@ -267,6 +279,11 @@ public: * @brief Optional. The domain name of the website on which the user has logged in. */ std::string connectedWebsite; + + /** + * @brief Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. + */ + InlineKeyboardMarkup::Ptr replyMarkup; }; } diff --git a/include/tgbot/types/Poll.h b/include/tgbot/types/Poll.h new file mode 100644 index 0000000..e218997 --- /dev/null +++ b/include/tgbot/types/Poll.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2019 Nitan Alexandru Marcel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_POLL_H +#define TGBOT_POLL_H + +#include <memory> +#include <string> +#include <vector> +#include "tgbot/types/PollOption.h" + +namespace TgBot { + /** + * @brief This object represents a Poll. + * + * @ingroup types + */ + class Poll { + public: + typedef std::shared_ptr<Poll> Ptr; + + /** + * @brief Unique poll identifier. + */ + int64_t id; + + /** + * @brief Poll question, 1-255 characters. + */ + std::string question; + + /** + * @brief List of poll options. + */ + PollOption::Ptr options; + + /** + * @brief True, if the poll is closed. + */ + bool is_closed; + }; +} + +#endif //TGBOT_POLL_H diff --git a/include/tgbot/types/PollOption.h b/include/tgbot/types/PollOption.h new file mode 100644 index 0000000..0d87870 --- /dev/null +++ b/include/tgbot/types/PollOption.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019 Nitan Alexandru Marcel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include <memory> +#include <string> +#include <vector> + +#ifndef TGBOT_POLLOPTION_H +#define TGBOT_POLLOPTION_H + +namespace TgBot { + +class PollOption { + +public: + typedef std::shared_ptr<PollOption> Ptr; + + /** + * @brief Option text, 1-100 characters. + */ + std::string text; + + /** + * @brief Number of users that voted for this option. + */ + int64_t voter_count; +}; + +} + +#endif //TGBOT_POLLOPTION_H diff --git a/include/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h index 9fd200a..68fc574 100644 --- a/include/tgbot/types/Sticker.h +++ b/include/tgbot/types/Sticker.h @@ -57,6 +57,11 @@ public: int32_t height; /** + * @brief True, if the sticker is animated. + */ + bool isAnimated = false; + + /** * @brief Optional. Optional. Sticker thumbnail in .webp or .jpg format. */ PhotoSize::Ptr thumb; diff --git a/include/tgbot/types/StickerSet.h b/include/tgbot/types/StickerSet.h index d08fd4a..deddf74 100644 --- a/include/tgbot/types/StickerSet.h +++ b/include/tgbot/types/StickerSet.h @@ -52,6 +52,11 @@ public: std::string title; /** + * @brief True, if the sticker set contains animated stickers. + */ + bool isAnimated = false; + + /** * @brief True, if the sticker set contains masks. */ bool containsMasks = false; |