summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--include/tgbot/Api.h25
-rw-r--r--include/tgbot/types/Chat.h18
-rw-r--r--include/tgbot/types/Message.h25
-rw-r--r--src/Api.cpp22
-rw-r--r--src/TgTypeParser.cpp12
6 files changed, 90 insertions, 14 deletions
diff --git a/README.md b/README.md
index cc917b0..74a0130 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp).
- [x] Bot API 3.0 ~ 3.6
- [x] Bot API 4.0 ~ 4.9
-- [x] Bot API 5.0 ~ 5.4 (Implemented all APIs except 'Run Your Own Bot API Server')
+- [x] Bot API 5.0 ~ 5.5 (Implemented all APIs except 'Run Your Own Bot API Server')
## Sample
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 428c8b2..87c6c11 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -741,6 +741,31 @@ public:
bool setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const;
/**
+ * @brief Use this method to ban a channel chat in a supergroup or a channel.
+ * Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels.
+ * The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param senderChatId Unique identifier of the target sender chat
+ *
+ * @return True on success.
+ */
+ bool banChatSenderChat(std::int64_t chatId,
+ std::int64_t senderChatId) const;
+
+ /**
+ * @brief Use this method to unban a previously banned channel chat in a supergroup or channel.
+ * The bot must be an administrator for this to work and must have the appropriate administrator rights.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param senderChatId Unique identifier of the target sender chat
+ *
+ * @return Returns True on success.
+ */
+ bool unbanChatSenderChat(std::int64_t chatId,
+ std::int64_t senderChatId) 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.
diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h
index 2b74447..24f7955 100644
--- a/include/tgbot/types/Chat.h
+++ b/include/tgbot/types/Chat.h
@@ -75,6 +75,12 @@ public:
std::string bio;
/**
+ * @brief Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id=<user_id> links only in chats with the user.
+ * Returned only in Api::getChat.
+ */
+ bool hasPrivateForwards;
+
+ /**
* @brief Optional. Description, for groups, supergroups and channel chats.
* Returned only in Api::getChat.
*/
@@ -106,6 +112,18 @@ public:
std::int32_t slowModeDelay;
/**
+ * @brief Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds.
+ * Returned only in Api::getChat.
+ */
+ std::int32_t messageAutoDeleteTime;
+
+ /**
+ * @brief Optional. True, if messages from the chat can't be forwarded to other chats.
+ * Returned only in Api::getChat.
+ */
+ bool hasProtectedContent;
+
+ /**
* @brief Optional. For supergroups, name of group sticker set.
* Returned only in Api::getChat.
*/
diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h
index dc65604..c918257 100644
--- a/include/tgbot/types/Message.h
+++ b/include/tgbot/types/Message.h
@@ -52,15 +52,15 @@ public:
std::int32_t messageId;
/**
- * @brief Optional. Sender, empty for messages sent to channels
+ * @brief Optional. Sender of the message; empty for messages sent to channels.
+ * For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
*/
User::Ptr from;
/**
* @brief Optional. Sender of the message, sent on behalf of a chat.
- * The channel itself for channel messages.
- * The supergroup itself for messages from anonymous group administrators.
- * The linked channel for messages automatically forwarded to the discussion group
+ * For example, the channel itself for channel posts, the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group.
+ * For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
*/
Chat::Ptr senderChat;
@@ -105,6 +105,11 @@ public:
std::int32_t forwardDate;
/**
+ * @brief Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group
+ */
+ bool isAutomaticForward;
+
+ /**
* @brief Optional. For replies, the original message.
* Note that the Message object in this field will not contain further replyToMessage fields even if it itself is a reply.
*/
@@ -121,6 +126,11 @@ public:
std::int32_t editDate;
/**
+ * @brief Optional. True, if the message can't be forwarded
+ */
+ bool hasProtectedContent;
+
+ /**
* @brief Optional. The unique identifier of a media message group this message belongs to
*/
std::string mediaGroupId;
@@ -347,13 +357,6 @@ public:
* loginUrl buttons are represented as ordinary url buttons.
*/
InlineKeyboardMarkup::Ptr replyMarkup;
-
- /**
- * @brief Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group
- *
- * Note: Added with Bot API 5.5
- */
- bool automaticForward;
};
}
diff --git a/src/Api.cpp b/src/Api.cpp
index ad9f544..c1c86d2 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -1041,6 +1041,28 @@ bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t user
return sendRequest("setChatAdministratorCustomTitle", args).get<bool>("", false);
}
+bool Api::banChatSenderChat(std::int64_t chatId,
+ std::int64_t senderChatId) const {
+ vector<HttpReqArg> args;
+ args.reserve(2);
+
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("sender_chat_id", senderChatId);
+
+ return sendRequest("banChatSenderChat", args).get<bool>("", false);
+}
+
+bool Api::unbanChatSenderChat(std::int64_t chatId,
+ std::int64_t senderChatId) const {
+ vector<HttpReqArg> args;
+ args.reserve(2);
+
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("sender_chat_id", senderChatId);
+
+ return sendRequest("unbanChatSenderChat", args).get<bool>("", false);
+}
+
bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const {
vector<HttpReqArg> args;
args.reserve(2);
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index ed75e21..e8a81d7 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -24,11 +24,14 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& d
result->lastName = data.get<std::string>("last_name", "");
result->photo = tryParseJson<ChatPhoto>(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo");
result->bio = data.get<std::string>("bio", "");
+ result->hasPrivateForwards = data.get<bool>("has_private_forwards", false);
result->description = data.get<std::string>("description", "");
result->inviteLink = data.get<std::string>("invite_link", "");
result->pinnedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message");
result->permissions = tryParseJson<ChatPermissions>(&TgTypeParser::parseJsonAndGetChatPermissions, data, "permissions");
result->slowModeDelay = data.get<std::int32_t>("slow_mode_delay", 0);
+ result->messageAutoDeleteTime = data.get<std::int32_t>("message_auto_delete_time", 0);
+ result->hasProtectedContent = data.get<bool>("has_protected_content", false);
result->stickerSetName = data.get<std::string>("sticker_set_name", "");
result->canSetStickerSet = data.get<bool>("can_set_sticker_set", false);
result->linkedChatId = data.get<std::int64_t>("linked_chat_id", 0);
@@ -58,11 +61,14 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const {
appendToJson(result, "last_name", object->lastName);
appendToJson(result, "photo", parseChatPhoto(object->photo));
appendToJson(result, "bio", object->bio);
+ appendToJson(result, "has_private_forwards", object->hasPrivateForwards);
appendToJson(result, "description", object->description);
appendToJson(result, "invite_link", object->inviteLink);
appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage));
appendToJson(result, "permissions", parseChatPermissions(object->permissions));
appendToJson(result, "slow_mode_delay", object->slowModeDelay);
+ appendToJson(result, "message_auto_delete_time", object->messageAutoDeleteTime);
+ appendToJson(result, "has_protected_content", object->hasProtectedContent);
appendToJson(result, "sticker_set_name", object->stickerSetName);
appendToJson(result, "can_set_sticker_set", object->canSetStickerSet);
appendToJson(result, "linked_chat_id", object->linkedChatId);
@@ -147,9 +153,11 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt
result->forwardSignature = data.get<std::string>("forward_signature", "");
result->forwardSenderName = data.get<std::string>("forward_sender_name", "");
result->forwardDate = data.get<std::int32_t>("forward_date", 0);
+ result->isAutomaticForward = data.get<bool>("is_automatic_forward", false);
result->replyToMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message");
result->viaBot = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "via_bot");
result->editDate = data.get<std::int32_t>("edit_date", 0);
+ result->hasProtectedContent = data.get<bool>("has_protected_content", false);
result->mediaGroupId = data.get<std::string>("media_group_id", "");
result->authorSignature = data.get<std::string>("author_signature", "");
result->text = data.get<std::string>("text", "");
@@ -193,7 +201,6 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt
result->voiceChatEnded = tryParseJson<VoiceChatEnded>(&TgTypeParser::parseJsonAndGetVoiceChatEnded, data, "voice_chat_ended");
result->voiceChatParticipantsInvited = tryParseJson<VoiceChatParticipantsInvited>(&TgTypeParser::parseJsonAndGetVoiceChatParticipantsInvited, data, "voice_chat_participants_invited");
result->replyMarkup = tryParseJson<InlineKeyboardMarkup>(&TgTypeParser::parseJsonAndGetInlineKeyboardMarkup, data, "reply_markup");
- result->automaticForward = data.get<bool>("is_automatic_forward", false);
return result;
}
@@ -214,9 +221,11 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "forward_signature", object->forwardSignature);
appendToJson(result, "forward_sender_name", object->forwardSenderName);
appendToJson(result, "forward_date", object->forwardDate);
+ appendToJson(result, "is_automatic_forward", object->isAutomaticForward);
appendToJson(result, "reply_to_message", parseMessage(object->replyToMessage));
appendToJson(result, "via_bot", parseUser(object->viaBot));
appendToJson(result, "edit_date", object->editDate);
+ appendToJson(result, "has_protected_content", object->hasProtectedContent);
appendToJson(result, "media_group_id", object->mediaGroupId);
appendToJson(result, "author_signature", object->authorSignature);
appendToJson(result, "text", object->text);
@@ -259,7 +268,6 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "voice_chat_ended", parseVoiceChatEnded(object->voiceChatEnded));
appendToJson(result, "voice_chat_participants_invited", parseVoiceChatParticipantsInvited(object->voiceChatParticipantsInvited));
appendToJson(result, "reply_markup", parseInlineKeyboardMarkup(object->replyMarkup));
- appendToJson(result, "is_automatic_forward", object->automaticForward);
removeLastComma(result);
result += '}';
return result;