tgbotxx  1.1.6.9
Telegram Bot C++ Library
User.hpp
Go to the documentation of this file.
1 #pragma once
3 
4 namespace tgbotxx {
7  struct User {
8  User() = default;
9  explicit User(const nl::json& json) {
10  fromJson(json);
11  }
12 
17  std::int64_t id{};
18 
20  bool isBot{};
21 
23  std::string firstName;
24 
26  std::string lastName;
27 
29  std::string username;
30 
32  std::string languageCode;
33 
35  bool isPremium{};
36 
39 
41  bool canJoinGroups{};
42 
45 
48 
49 
50  nl::json toJson() const {
51  nl::json user = nl::json::object();
52  OBJECT_SERIALIZE_FIELD(user, "id", id);
53  OBJECT_SERIALIZE_FIELD(user, "is_bot", isBot);
54  OBJECT_SERIALIZE_FIELD(user, "first_name", firstName);
55  OBJECT_SERIALIZE_FIELD(user, "last_name", lastName);
56  OBJECT_SERIALIZE_FIELD(user, "username", username);
57  OBJECT_SERIALIZE_FIELD(user, "language_code", languageCode);
58  OBJECT_SERIALIZE_FIELD(user, "is_premium", isPremium);
59  OBJECT_SERIALIZE_FIELD(user, "added_to_attachment_menu", addedToAttachmentMenu);
60  OBJECT_SERIALIZE_FIELD(user, "can_join_groups", canJoinGroups);
61  OBJECT_SERIALIZE_FIELD(user, "can_read_all_group_messages", canReadAllGroupMessages);
62  OBJECT_SERIALIZE_FIELD(user, "supports_inline_queries", supportsInlineQueries);
63  return user;
64  }
65 
66  void fromJson(const nl::json& json) {
67  OBJECT_DESERIALIZE_FIELD(json, "id", id, -1, false);
68  OBJECT_DESERIALIZE_FIELD(json, "is_bot", isBot, false, false);
69  OBJECT_DESERIALIZE_FIELD(json, "first_name", firstName, "", false);
70  OBJECT_DESERIALIZE_FIELD(json, "last_name", lastName, "", true);
71  OBJECT_DESERIALIZE_FIELD(json, "username", username, "", true);
72  OBJECT_DESERIALIZE_FIELD(json, "language_code", languageCode, "", true);
73  OBJECT_DESERIALIZE_FIELD(json, "is_premium", isPremium, false, true);
74  OBJECT_DESERIALIZE_FIELD(json, "added_to_attachment_menu", addedToAttachmentMenu, false, true);
75  OBJECT_DESERIALIZE_FIELD(json, "can_join_groups", canJoinGroups, false, true);
76  OBJECT_DESERIALIZE_FIELD(json, "can_read_all_group_messages", canReadAllGroupMessages, false, true);
77  OBJECT_DESERIALIZE_FIELD(json, "supports_inline_queries", supportsInlineQueries, false, true);
78  }
79  };
80 }
#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
Definition: Api.hpp:14
This object represents a Telegram user or bot. https://core.telegram.org/bots/api#user.
Definition: User.hpp:7
std::string lastName
Optional. User's or bot's last name.
Definition: User.hpp:26
std::string languageCode
Optional. IETF language tag of the user's language.
Definition: User.hpp:32
void fromJson(const nl::json &json)
Definition: User.hpp:66
bool isBot
True, if this user is a bot.
Definition: User.hpp:20
bool addedToAttachmentMenu
Optional. True, if this user added the bot to the attachment menu.
Definition: User.hpp:38
std::string firstName
User's or bot's first name.
Definition: User.hpp:23
bool canReadAllGroupMessages
Optional. True, if privacy mode is disabled for the bot. Returned only in getMe.
Definition: User.hpp:44
User()=default
User(const nl::json &json)
Definition: User.hpp:9
bool supportsInlineQueries
Optional. True, if the bot supports inline queries. Returned only in getMe.
Definition: User.hpp:47
bool isPremium
Optional. True, if this user is a Telegram Premium user.
Definition: User.hpp:35
std::string username
Optional. User's or bot's username.
Definition: User.hpp:29
nl::json toJson() const
Definition: User.hpp:50
bool canJoinGroups
Optional. True, if the bot can be invited to groups. Returned only in getMe.
Definition: User.hpp:41