Skip to content

Commit

Permalink
implemented Api forum topic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
baderouaich committed Oct 14, 2023
1 parent c725a7c commit 8ee1cc5
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
57 changes: 56 additions & 1 deletion include/tgbotxx/Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ namespace tgbotxx {


/// @brief Use this method to create a topic in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
/// The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights.
/// https://core.telegram.org/bots/api#forumtopic
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @param name Topic name, 1-128 characters
Expand All @@ -1168,6 +1168,61 @@ namespace tgbotxx {
const std::string& iconCustomEmojiId = "") const;


/// @brief Use this method to edit name and icon of a topic in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights.
/// https://core.telegram.org/bots/api#forumtopic
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @param messageThreadId Unique identifier for the target message thread of the forum topic
/// @param name Optional. New topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept
/// @param iconCustomEmojiId Optional. New unique identifier of the custom emoji shown as the topic icon.
/// Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
/// Pass an empty string to remove the icon. If not specified, the current icon will be kept
/// @returns True on success.
/// @throws Exception on failure
/// @relatedalso createForumTopic closeForumTopic reopenForumTopic deleteForumTopic
/// @ref https://core.telegram.org/bots/api#editforumtopic
bool editForumTopic(std::int64_t chatId,
std::int32_t messageThreadId,
const std::string& name,
const std::optional<std::string>& iconCustomEmojiId = std::nullopt) const;


/// @brief Use this method to close an open topic in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights.
/// https://core.telegram.org/bots/api#forumtopic
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @param messageThreadId Unique identifier for the target message thread of the forum topic
/// @returns True on success.
/// @throws Exception on failure
/// @relatedalso createForumTopic editForumTopic reopenForumTopic deleteForumTopic
/// @ref https://core.telegram.org/bots/api#closeforumtopic
bool closeForumTopic(std::int64_t chatId, std::int32_t messageThreadId) const;


/// @brief Use this method to reopen a closed topic in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights.
/// https://core.telegram.org/bots/api#forumtopic
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @param messageThreadId Unique identifier for the target message thread of the forum topic
/// @returns True on success.
/// @throws Exception on failure
/// @relatedalso createForumTopic editForumTopic closeForumTopic deleteForumTopic
/// @ref https://core.telegram.org/bots/api#reopenforumtopic
bool reopenForumTopic(std::int64_t chatId, std::int32_t messageThreadId) const;


/// @brief Use this method to delete a forum topic along with all its messages in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights.
/// https://core.telegram.org/bots/api#forumtopic
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @param messageThreadId Unique identifier for the target message thread of the forum topic
/// @returns True on success.
/// @throws Exception on failure
/// @relatedalso createForumTopic editForumTopic closeForumTopic reopenForumTopic
/// @ref https://core.telegram.org/bots/api#deleteforumtopic
bool deleteForumTopic(std::int64_t chatId, std::int32_t messageThreadId) const;


/// @brief Use this method to remove webhook integration if you decide to switch back to getUpdates.
/// @param dropPendingUpdates: Pass True to drop all pending updates.
/// @returns True on success.
Expand Down
40 changes: 40 additions & 0 deletions src/Api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,3 +1356,43 @@ Ptr<ForumTopic> Api::createForumTopic(std::int64_t chatId,
Ptr<ForumTopic> forumTopic(new ForumTopic(forumTopicObj));
return forumTopic;
}

bool Api::editForumTopic(std::int64_t chatId,
std::int32_t messageThreadId,
const std::string& name,
const std::optional<std::string>& iconCustomEmojiId) const {
cpr::Multipart data{};
data.parts.reserve(4);
data.parts.emplace_back("chat_id", std::to_string(chatId));
data.parts.emplace_back("message_thread_id", messageThreadId);
if (not name.empty())
data.parts.emplace_back("name", name);
if (iconCustomEmojiId.has_value()) {
data.parts.emplace_back("icon_custom_emoji_id", *iconCustomEmojiId);
}
return sendRequest("editForumTopic", data);
}

bool Api::closeForumTopic(std::int64_t chatId, std::int32_t messageThreadId) const {
cpr::Multipart data{};
data.parts.reserve(2);
data.parts.emplace_back("chat_id", std::to_string(chatId));
data.parts.emplace_back("message_thread_id", messageThreadId);
return sendRequest("closeForumTopic", data);
}

bool Api::reopenForumTopic(std::int64_t chatId, std::int32_t messageThreadId) const {
cpr::Multipart data{};
data.parts.reserve(2);
data.parts.emplace_back("chat_id", std::to_string(chatId));
data.parts.emplace_back("message_thread_id", messageThreadId);
return sendRequest("reopenForumTopic", data);
}

bool Api::deleteForumTopic(std::int64_t chatId, std::int32_t messageThreadId) const {
cpr::Multipart data{};
data.parts.reserve(2);
data.parts.emplace_back("chat_id", std::to_string(chatId));
data.parts.emplace_back("message_thread_id", messageThreadId);
return sendRequest("deleteForumTopic", data);
}

0 comments on commit 8ee1cc5

Please sign in to comment.