Skip to content

Commit

Permalink
added ForumTopic object
Browse files Browse the repository at this point in the history
implemented Api methods
  • Loading branch information
baderouaich committed Oct 14, 2023
1 parent 5bae914 commit c725a7c
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 47 deletions.
117 changes: 105 additions & 12 deletions include/tgbotxx/Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <tgbotxx/objects/EncryptedPassportElement.hpp>
#include <tgbotxx/objects/File.hpp>
#include <tgbotxx/objects/ForceReply.hpp>
#include <tgbotxx/objects/ForumTopic.hpp>
#include <tgbotxx/objects/ForumTopicClosed.hpp>
#include <tgbotxx/objects/ForumTopicCreated.hpp>
#include <tgbotxx/objects/ForumTopicEdited.hpp>
Expand Down Expand Up @@ -871,7 +872,7 @@ namespace tgbotxx {
/// @param customTitle New custom title for the administrator; 0-16 characters, emoji are not allowed
/// @returns True on success.
/// @throws Exception on failure
/// @related unbanChatSenderChat
/// @relatedalso unbanChatSenderChat
/// @ref https://core.telegram.org/bots/api#banchatsenderchat
bool banChatSenderChat(std::int64_t chatId,
std::int64_t senderChatId) const;
Expand All @@ -884,7 +885,7 @@ namespace tgbotxx {
/// @param customTitle New custom title for the administrator; 0-16 characters, emoji are not allowed
/// @returns True on success.
/// @throws Exception on failure
/// @related banChatSenderChat
/// @relatedalso banChatSenderChat
/// @ref https://core.telegram.org/bots/api#unbanchatsenderchat
bool unbanChatSenderChat(std::int64_t chatId,
std::int64_t senderChatId) const;
Expand Down Expand Up @@ -933,7 +934,7 @@ namespace tgbotxx {
/// @param createsJoinRequest Optional. True, if users joining the chat via the link need to be approved by chat administrators. If True, memberLimit can't be specified
/// @returns the new invite link as ChatInviteLink object on success.
/// @throws Exception on failure
/// @related editChatInviteLink revokeChatInviteLink
/// @relatedalso editChatInviteLink revokeChatInviteLink
/// @ref https://core.telegram.org/bots/api#createchatinvitelink
Ptr<ChatInviteLink> createChatInviteLink(std::int64_t chatId,
const std::string& name = "",
Expand All @@ -952,7 +953,7 @@ namespace tgbotxx {
/// @param createsJoinRequest Optional. True, if users joining the chat via the link need to be approved by chat administrators. If True, memberLimit can't be specified
/// @returns The edited invite link as a ChatInviteLink object on success.
/// @throws Exception on failure
/// @related createChatInviteLink revokeChatInviteLink
/// @relatedalso createChatInviteLink revokeChatInviteLink
/// @ref https://core.telegram.org/bots/api#editchatinvitelink
Ptr<ChatInviteLink> editChatInviteLink(std::int64_t chatId,
const std::string& inviteLink,
Expand All @@ -968,7 +969,7 @@ namespace tgbotxx {
/// @param inviteLink The invite link to revoke
/// @returns The revoked invite link as ChatInviteLink object on success.
/// @throws Exception on failure
/// @related createChatInviteLink editChatInviteLink
/// @relatedalso createChatInviteLink editChatInviteLink
/// @ref https://core.telegram.org/bots/api#revokechatinvitelink
Ptr<ChatInviteLink> revokeChatInviteLink(std::int64_t chatId, const std::string& inviteLink) const;

Expand All @@ -979,7 +980,7 @@ namespace tgbotxx {
/// @param userId Unique identifier of the target user
/// @returns True on success.
/// @throws Exception on failure
/// @related declineChatJoinRequest
/// @relatedalso declineChatJoinRequest
/// @ref https://core.telegram.org/bots/api#approvechatjoinrequest
bool approveChatJoinRequest(std::int64_t chatId, std::int64_t userId) const;

Expand All @@ -990,7 +991,7 @@ namespace tgbotxx {
/// @param userId Unique identifier of the target user
/// @returns True on success.
/// @throws Exception on failure
/// @related approveChatJoinRequest
/// @relatedalso approveChatJoinRequest
/// @ref https://core.telegram.org/bots/api#declinechatjoinrequest
bool declineChatJoinRequest(std::int64_t chatId, std::int64_t userId) const;

Expand All @@ -1001,7 +1002,7 @@ namespace tgbotxx {
/// @param photo New chat photo, uploaded using multipart/form-data
/// @returns True on success.
/// @throws Exception on failure
/// @related deleteChatPhoto
/// @relatedalso deleteChatPhoto
/// @ref https://core.telegram.org/bots/api#setchatphoto
bool setChatPhoto(std::int64_t chatId, const cpr::File& photo) const;

Expand All @@ -1011,7 +1012,7 @@ namespace tgbotxx {
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @returns True on success.
/// @throws Exception on failure
/// @related setChatPhoto
/// @relatedalso setChatPhoto
/// @ref https://core.telegram.org/bots/api#deletechatphoto
bool deleteChatPhoto(std::int64_t chatId) const;

Expand Down Expand Up @@ -1045,7 +1046,7 @@ namespace tgbotxx {
/// Notifications are always disabled in channels and private chats.
/// @returns True on success.
/// @throws Exception on failure
/// @related unpinChatMessage unpinAllChatMessages
/// @relatedalso unpinChatMessage unpinAllChatMessages
/// @ref https://core.telegram.org/bots/api#pinchatmessage
bool pinChatMessage(std::int64_t chatId,
std::int32_t messageId,
Expand All @@ -1059,7 +1060,7 @@ namespace tgbotxx {
/// @param messageId Optional. Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.
/// @returns True on success.
/// @throws Exception on failure
/// @related pinChatMessage unpinAllChatMessages
/// @relatedalso pinChatMessage unpinAllChatMessages
/// @ref https://core.telegram.org/bots/api#unpinchatmessage
bool unpinChatMessage(std::int64_t chatId, std::int32_t messageId = 0) const;

Expand All @@ -1070,11 +1071,103 @@ namespace tgbotxx {
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @returns True on success.
/// @throws Exception on failure
/// @related pinChatMessage unpinChatMessage
/// @relatedalso pinChatMessage unpinChatMessage
/// @ref https://core.telegram.org/bots/api#unpinallchatmessages
bool unpinAllChatMessages(std::int64_t chatId) const;


/// @brief Use this method for your bot to leave a group, supergroup or channel.
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @returns True on success.
/// @throws Exception on failure
/// @ref https://core.telegram.org/bots/api#leavechat
bool leaveChat(std::int64_t chatId) const;


/// @brief Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @returns a Chat object on success.
/// @throws Exception on failure
/// @ref https://core.telegram.org/bots/api#getchat
Ptr<Chat> getChat(std::int64_t chatId) const;


/// @brief Use this method to get a list of administrators in a chat, which aren't bots.
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @returns an Array of ChatMember objects.
/// @throws Exception on failure
/// @ref https://core.telegram.org/bots/api#getchatadministrators
std::vector<Ptr<ChatMember>> getChatAdministrators(std::int64_t chatId) const;


/// @brief Use this method to get the number of members in a chat.
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @returns std::int32_t on success.
/// @throws Exception on failure
/// @ref https://core.telegram.org/bots/api#getchatmembercount
std::int32_t getChatMemberCount(std::int64_t chatId) const;


/// @brief Use this method to get information about a member of a chat.
/// The method is only guaranteed to work for other users if the bot is an administrator in the chat.
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @param userId Unique identifier of the target user
/// @returns a ChatMember object on success.
/// @throws Exception on failure
/// @ref https://core.telegram.org/bots/api#getchatmember
Ptr<ChatMember> getChatMember(std::int64_t chatId, std::int64_t userId) const;


/// @brief Use this method to set a new group sticker set for a supergroup.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Use the field canSetStickerSet optionally returned in getChat requests to check if the bot can use this method.
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @param stickerSetName Name of the sticker set to be set as the group sticker set
/// @returns True on success.
/// @throws Exception on failure
/// @relatedalso deleteChatStickerSet getForumTopicIconStickers Sticker::setName
/// @ref https://core.telegram.org/bots/api#setchatstickerset
bool setChatStickerSet(std::int64_t chatId, const std::string& stickerSetName) const;


/// @brief Use this method to delete a group sticker set from a supergroup.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Use the field canSetStickerSet optionally returned in getChat requests to check if the bot can use this method.
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @returns True on success.
/// @throws Exception on failure
/// @relatedalso setChatStickerSet getForumTopicIconStickers Sticker::setName
/// @ref https://core.telegram.org/bots/api#deletechatstickerset
bool deleteChatStickerSet(std::int64_t chatId) const;


/// @brief Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user.
/// Requires no parameters.
/// @param chatId Integer Unique identifier for the target chat or username of the target channel (in the format \@channelusername)
/// @returns an Array of Sticker objects.
/// @throws Exception on failure
/// @relatedalso setChatStickerSet deleteChatStickerSet
/// @ref https://core.telegram.org/bots/api#getforumtopiciconstickers
std::vector<Ptr<Sticker>> getForumTopicIconStickers() const;


/// @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.
/// 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
/// @param iconColor Optional. Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F)
/// @param iconCustomEmojiId Optional. Unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers. https://core.telegram.org/bots/api#getforumtopiciconstickers
/// @returns information about the created topic as a ForumTopic object.
/// @throws Exception on failure
/// @relatedalso editForumTopic closeForumTopic reopenForumTopic deleteForumTopic
/// @ref https://core.telegram.org/bots/api#createforumtopic
Ptr<ForumTopic> createForumTopic(std::int64_t chatId,
const std::string& name,
std::int32_t iconColor = 0x000000,
const std::string& iconCustomEmojiId = "") 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
44 changes: 44 additions & 0 deletions include/tgbotxx/objects/ForumTopic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#include <tgbotxx/objects/Object.hpp>

namespace tgbotxx {
/// @brief This object represents a forum topic.
/// @ref https://core.telegram.org/bots/api#forumtopic
struct ForumTopic {
ForumTopic() = default;
explicit ForumTopic(const nl::json& json) {
fromJson(json);
}

/// @brief Unique identifier of the forum topic
std::int32_t messageThreadId{};

/// @brief Name of the topic
std::string name;

/// @brief Color of the topic icon in RGB format
std::int32_t iconColor{};

/// @brief Optional. Unique identifier of the custom emoji shown as the topic icon
std::int32_t iconCustomEmojiId{};

/// @brief Serializes this object to JSON
/// @returns JSON representation of this object
nl::json toJson() const {
nl::json json = nl::json::object();
OBJECT_SERIALIZE_FIELD(json, "message_thread_id", messageThreadId);
OBJECT_SERIALIZE_FIELD(json, "name", name);
OBJECT_SERIALIZE_FIELD(json, "icon_color", iconColor);
OBJECT_SERIALIZE_FIELD(json, "icon_custom_emoji_id", iconCustomEmojiId);
return json;
}

/// @brief Deserializes this object from JSON
void fromJson(const nl::json& json) {
OBJECT_DESERIALIZE_FIELD(json, "message_thread_id", messageThreadId, 0, false);
OBJECT_DESERIALIZE_FIELD(json, "name", name, "", false);
OBJECT_DESERIALIZE_FIELD(json, "icon_color", iconColor, 0x000000, false);
OBJECT_DESERIALIZE_FIELD(json, "icon_custom_emoji_id", iconCustomEmojiId, 0, true);
}
};
}
1 change: 1 addition & 0 deletions include/tgbotxx/tgbotxx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <tgbotxx/objects/EncryptedCredentials.hpp>
#include <tgbotxx/objects/EncryptedPassportElement.hpp>
#include <tgbotxx/objects/File.hpp>
#include <tgbotxx/objects/ForumTopic.hpp>
#include <tgbotxx/objects/ForumTopicClosed.hpp>
#include <tgbotxx/objects/ForumTopicCreated.hpp>
#include <tgbotxx/objects/ForumTopicEdited.hpp>
Expand Down
Loading

0 comments on commit c725a7c

Please sign in to comment.