tgbotxx  1.1.6.9
Telegram Bot C++ Library
Chat.hpp
Go to the documentation of this file.
1 #pragma once
8 
9 namespace tgbotxx {
12  struct Chat {
13  Chat() = default;
14  explicit Chat(const nl::json& json) {
15  fromJson(json);
16  }
17 
22  std::int64_t id{};
23 
25  enum class Type : std::uint8_t {
26  Private = 0,
27  Group,
28  Supergroup,
29  Channel
30  };
31  inline static constexpr const char *Type2Str[] = {
32  "private", "group", "supergroup", "channel"};
33  inline static constexpr Type Str2Type(const std::string& str) {
34  std::uint8_t i = 0;
35  for (const char *v: Type2Str) {
36  if (str == v)
37  return static_cast<Type>(i);
38  ++i;
39  }
40  throw Exception("Could not convert Chat type string \"" + str + "\" to enum Type");
41  }
42 
45 
47  std::string title;
48 
50  std::string username;
51 
53  std::string firstName;
54 
56  std::string lastName;
57 
60  bool isForum{};
61 
64 
66  std::vector<std::string> activeUsernames;
67 
69  std::vector<Ptr<ReactionType>> availableReactions;
70 
73  std::int32_t accentColorId{};
74 
77 
79  std::int32_t profileAccentColorId{};
80 
83 
87 
91 
93  std::string bio;
94 
97 
100 
103 
106 
108  std::string description;
109 
111  std::string inviteLink;
112 
115 
118 
120  std::int32_t slowModeDelay{};
121 
123  std::int32_t unrestrictBoostCount{};
124 
126  std::int32_t messageAutoDeleteTime{};
127 
130 
133 
136 
139 
141  std::string stickerSetName;
142 
145 
150  std::int64_t linkedChatId{};
151 
154 
155 
158  nl::json toJson() const {
159  nl::json json = nl::json::object();
160  OBJECT_SERIALIZE_FIELD(json, "id", id);
161  json["type"] = Type2Str[static_cast<std::size_t>(type)]; // enum
162  OBJECT_SERIALIZE_FIELD(json, "title", title);
163  OBJECT_SERIALIZE_FIELD(json, "username", username);
164  OBJECT_SERIALIZE_FIELD(json, "first_name", firstName);
165  OBJECT_SERIALIZE_FIELD(json, "last_name", lastName);
166  OBJECT_SERIALIZE_FIELD(json, "is_forum", isForum);
167  OBJECT_SERIALIZE_FIELD_PTR(json, "photo", photo);
168  OBJECT_SERIALIZE_FIELD(json, "active_usernames", activeUsernames);
169  OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, "available_reactions", availableReactions);
170  OBJECT_SERIALIZE_FIELD(json, "accent_color_id", accentColorId);
171  OBJECT_SERIALIZE_FIELD(json, "background_custom_emoji_id", backgroundCustomEmojiId);
172  OBJECT_SERIALIZE_FIELD(json, "profile_accent_color_id", profileAccentColorId);
173  OBJECT_SERIALIZE_FIELD(json, "profile_background_custom_emoji_id", profileBackgroundCustomEmojiId);
174  OBJECT_SERIALIZE_FIELD(json, "emoji_status_custom_emoji_id", emojiStatusCustomEmojiId);
175  OBJECT_SERIALIZE_FIELD(json, "emoji_status_expiration_date", emojiStatusExpirationDate);
176  OBJECT_SERIALIZE_FIELD(json, "bio", bio);
177  OBJECT_SERIALIZE_FIELD(json, "has_private_forwards", hasPrivateForwards);
178  OBJECT_SERIALIZE_FIELD(json, "has_restricted_voice_and_video_messages", hasRestrictedVoiceAndVideoMessages);
179  OBJECT_SERIALIZE_FIELD(json, "join_to_send_messages", joinToSendMessages);
180  OBJECT_SERIALIZE_FIELD(json, "join_by_request", joinByRequest);
181  OBJECT_SERIALIZE_FIELD(json, "description", description);
182  OBJECT_SERIALIZE_FIELD(json, "invite_link", inviteLink);
183  OBJECT_SERIALIZE_FIELD_PTR(json, "pinned_message", pinnedMessage);
184  OBJECT_SERIALIZE_FIELD_PTR(json, "permissions", permissions);
185  OBJECT_SERIALIZE_FIELD(json, "slow_mode_delay", slowModeDelay);
186  OBJECT_SERIALIZE_FIELD(json, "message_auto_delete_time", messageAutoDeleteTime);
187  OBJECT_SERIALIZE_FIELD(json, "has_aggressive_anti_spam_enabled", hasAggressiveAntiSpamEnabled);
188  OBJECT_SERIALIZE_FIELD(json, "has_hidden_members", hasHiddenMembers);
189  OBJECT_SERIALIZE_FIELD(json, "has_protected_content", hasProtectedContent);
190  OBJECT_SERIALIZE_FIELD(json, "has_visible_history", hasVisibleHistory);
191  OBJECT_SERIALIZE_FIELD(json, "sticker_set_name", stickerSetName);
192  OBJECT_SERIALIZE_FIELD(json, "can_set_sticker_set", canSetStickerSet);
193  OBJECT_SERIALIZE_FIELD(json, "linked_chat_id", linkedChatId);
194  OBJECT_SERIALIZE_FIELD_PTR(json, "location", location);
195  return json;
196  }
197 
199  void fromJson(const nl::json& json) {
200  OBJECT_DESERIALIZE_FIELD(json, "id", id, 0, false);
201  type = Str2Type(json["type"]); // enum
202  OBJECT_DESERIALIZE_FIELD(json, "title", title, "", true);
203  OBJECT_DESERIALIZE_FIELD(json, "username", username, "", true);
204  OBJECT_DESERIALIZE_FIELD(json, "first_name", firstName, "", true);
205  OBJECT_DESERIALIZE_FIELD(json, "last_name", lastName, "", true);
206  OBJECT_DESERIALIZE_FIELD(json, "is_forum", isForum, false, true);
207  OBJECT_DESERIALIZE_FIELD_PTR(json, "photo", photo, true);
208  OBJECT_DESERIALIZE_FIELD(json, "active_usernames", activeUsernames, std::vector<std::string>(), true);
209  OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "available_reactions", availableReactions, true);
210  OBJECT_DESERIALIZE_FIELD(json, "accent_color_id", accentColorId, 0, true);
211  OBJECT_DESERIALIZE_FIELD(json, "background_custom_emoji_id", backgroundCustomEmojiId, "", true);
212  OBJECT_DESERIALIZE_FIELD(json, "profile_accent_color_id", profileAccentColorId, 0, true);
213  OBJECT_DESERIALIZE_FIELD(json, "profile_background_custom_emoji_id", profileBackgroundCustomEmojiId, "", true);
214  OBJECT_DESERIALIZE_FIELD(json, "emoji_status_custom_emoji_id", emojiStatusCustomEmojiId, "", true);
215  OBJECT_DESERIALIZE_FIELD(json, "emoji_status_expiration_date", emojiStatusExpirationDate, 0, true);
216  OBJECT_DESERIALIZE_FIELD(json, "bio", bio, "", true);
217  OBJECT_DESERIALIZE_FIELD(json, "has_private_forwards", hasPrivateForwards, false, true);
218  OBJECT_DESERIALIZE_FIELD(json, "has_restricted_voice_and_video_messages", hasRestrictedVoiceAndVideoMessages, false, true);
219  OBJECT_DESERIALIZE_FIELD(json, "join_to_send_messages", joinToSendMessages, false, true);
220  OBJECT_DESERIALIZE_FIELD(json, "join_by_request", joinByRequest, false, true);
221  OBJECT_DESERIALIZE_FIELD(json, "description", description, "", true);
222  OBJECT_DESERIALIZE_FIELD(json, "invite_link", inviteLink, "", true);
223  OBJECT_DESERIALIZE_FIELD_PTR(json, "pinned_message", pinnedMessage, true);
224  OBJECT_DESERIALIZE_FIELD_PTR(json, "permissions", permissions, true);
225  OBJECT_DESERIALIZE_FIELD(json, "slow_mode_delay", slowModeDelay, 0, true);
226  OBJECT_DESERIALIZE_FIELD(json, "message_auto_delete_time", messageAutoDeleteTime, 0, true);
227  OBJECT_DESERIALIZE_FIELD(json, "has_aggressive_anti_spam_enabled", hasAggressiveAntiSpamEnabled, false, true);
228  OBJECT_DESERIALIZE_FIELD(json, "has_hidden_members", hasHiddenMembers, false, true);
229  OBJECT_DESERIALIZE_FIELD(json, "has_protected_content", hasProtectedContent, false, true);
230  OBJECT_DESERIALIZE_FIELD(json, "has_visible_history", hasVisibleHistory, false, true);
231  OBJECT_DESERIALIZE_FIELD(json, "sticker_set_name", stickerSetName, "", true);
232  OBJECT_DESERIALIZE_FIELD(json, "can_set_sticker_set", canSetStickerSet, false, true);
233  OBJECT_DESERIALIZE_FIELD(json, "linked_chat_id", linkedChatId, 0, true);
234  OBJECT_DESERIALIZE_FIELD_PTR(json, "location", location, true);
235  }
236  };
237 }
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition: Object.hpp:22
#define OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field)
Definition: Object.hpp:27
#define OBJECT_DESERIALIZE_FIELD_PTR(json, json_field, field, optional)
Definition: Object.hpp:70
#define OBJECT_SERIALIZE_FIELD(json, json_field, field)
Available objects: https://core.telegram.org/bots/api#available-types.
Definition: Object.hpp:19
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition: Object.hpp:44
#define OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field, optional)
Definition: Object.hpp:87
tgbotxx::Exception
Definition: Exception.hpp:91
Definition: Api.hpp:14
std::shared_ptr< T > Ptr
Definition: Ptr.hpp:6
This object represents a chat. https://core.telegram.org/bots/api#chat.
Definition: Chat.hpp:12
bool hasPrivateForwards
Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?...
Definition: Chat.hpp:96
std::time_t emojiStatusExpirationDate
Optional. Expiration date of the emoji status of the other party in a private chat in Unix time,...
Definition: Chat.hpp:90
bool hasAggressiveAntiSpamEnabled
Optional. True, if aggressive anti-spam checks are enabled in the supergroup. The field is only avail...
Definition: Chat.hpp:129
std::vector< std::string > activeUsernames
Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and cha...
Definition: Chat.hpp:66
Ptr< Message > pinnedMessage
Optional. The most recent pinned message (by sending date). Returned only in getChat.
Definition: Chat.hpp:114
std::string emojiStatusCustomEmojiId
Optional. Custom emoji identifier of emoji status of the other party in a private chat....
Definition: Chat.hpp:86
bool hasRestrictedVoiceAndVideoMessages
Optional. True, if the privacy settings of the other party restrict sending voice and video note mess...
Definition: Chat.hpp:99
std::string username
Optional. Username, for private chats, supergroups and channels if available.
Definition: Chat.hpp:50
std::string bio
Optional. Bio of the other party in a private chat. Returned only in getChat.
Definition: Chat.hpp:93
bool joinByRequest
Optional. True, if all users directly joining the supergroup need to be approved by supergroup admini...
Definition: Chat.hpp:105
bool hasProtectedContent
Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat...
Definition: Chat.hpp:135
std::int32_t messageAutoDeleteTime
Optional. The time after which all messages sent to the chat will be automatically deleted; in second...
Definition: Chat.hpp:126
std::string inviteLink
Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat.
Definition: Chat.hpp:111
Type
Enum of possible types of a chat.
Definition: Chat.hpp:25
bool isForum
Optional. True, if the supergroup chat is a forum (has topics enabled) https://telegram....
Definition: Chat.hpp:60
std::string backgroundCustomEmojiId
Optional. Custom emoji identifier of emoji chosen by the chat for the reply header and link preview b...
Definition: Chat.hpp:76
Ptr< ChatLocation > location
Optional. For supergroups, the location to which the supergroup is connected. Returned only in getCha...
Definition: Chat.hpp:153
static constexpr const char * Type2Str[]
Definition: Chat.hpp:31
std::vector< Ptr< ReactionType > > availableReactions
Optional. List of available reactions allowed in the chat. If omitted, then all emoji reactions are a...
Definition: Chat.hpp:69
std::int32_t profileAccentColorId
Optional. Identifier of the accent color for the chat's profile background. See profile accent colors...
Definition: Chat.hpp:79
std::string lastName
Optional. Last name of the other party in a private chat.
Definition: Chat.hpp:56
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: Chat.hpp:199
Chat(const nl::json &json)
Definition: Chat.hpp:14
Ptr< ChatPermissions > permissions
Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
Definition: Chat.hpp:117
Type type
Type of chat, can be either “private”, “group”, “supergroup” or “channel”
Definition: Chat.hpp:44
std::string firstName
Optional. First name of the other party in a private chat.
Definition: Chat.hpp:53
nl::json toJson() const
Serializes this object to JSON.
Definition: Chat.hpp:158
std::int64_t linkedChatId
Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel a...
Definition: Chat.hpp:150
std::int32_t unrestrictBoostCount
Optional. For supergroups, the minimum number of boosts that a non-administrator user needs to add in...
Definition: Chat.hpp:123
std::int32_t accentColorId
Optional. Identifier of the accent color for the chat name and backgrounds of the chat photo,...
Definition: Chat.hpp:73
std::string title
Optional. Title, for supergroups, channels and group chats.
Definition: Chat.hpp:47
std::string description
Optional. Description, for groups, supergroups and channel chats. Returned only in getChat.
Definition: Chat.hpp:108
bool hasHiddenMembers
Optional. True, if non-administrators can only get the list of bots and administrators in the chat....
Definition: Chat.hpp:132
static constexpr Type Str2Type(const std::string &str)
Definition: Chat.hpp:33
Chat()=default
std::string stickerSetName
Optional. For supergroups, name of group sticker set. Returned only in getChat.
Definition: Chat.hpp:141
Ptr< ChatPhoto > photo
Optional. Chat photo. Returned only in getChat.
Definition: Chat.hpp:63
bool joinToSendMessages
Optional. True, if users need to join the supergroup before they can send messages....
Definition: Chat.hpp:102
std::string profileBackgroundCustomEmojiId
Optional. Custom emoji identifier of the emoji chosen by the chat for its profile background....
Definition: Chat.hpp:82
std::int32_t slowModeDelay
Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriv...
Definition: Chat.hpp:120
bool canSetStickerSet
Optional. True, if the bot can change the group sticker set. Returned only in getChat.
Definition: Chat.hpp:144
bool hasVisibleHistory
Optional. True, if new chat members will have access to old messages; available only to chat administ...
Definition: Chat.hpp:138