tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
SharedUser.hpp
Go to the documentation of this file.
1#pragma once
4
5namespace tgbotxx {
8 struct SharedUser {
9 SharedUser() = default;
10 explicit SharedUser(const nl::json& json) {
11 fromJson(json);
12 }
13
19 std::int64_t userId{};
20
22 std::string firstName;
23
25 std::string lastName;
26
28 std::string username;
29
31 std::vector<Ptr<PhotoSize>> photo;
32
35 nl::json toJson() const {
36 nl::json json = nl::json::object();
37 OBJECT_SERIALIZE_FIELD(json, "user_id", userId);
38 OBJECT_SERIALIZE_FIELD(json, "first_name", firstName);
39 OBJECT_SERIALIZE_FIELD(json, "last_name", lastName);
40 OBJECT_SERIALIZE_FIELD(json, "username", username);
42 return json;
43 }
44
46 void fromJson(const nl::json& json) {
47 OBJECT_DESERIALIZE_FIELD(json, "user_id", userId, 0, false);
48 OBJECT_DESERIALIZE_FIELD(json, "first_name", firstName, "", true);
49 OBJECT_DESERIALIZE_FIELD(json, "last_name", lastName, "", true);
50 OBJECT_DESERIALIZE_FIELD(json, "username", username, "", true);
51 OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "photo", photo, true);
52 }
53 };
54}
#define OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field)
Definition Object.hpp:27
#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:46
#define OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field, optional)
Definition Object.hpp:89
This object contains information about a user that was shared with the bot using a KeyboardButtonRequ...
Definition SharedUser.hpp:8
nl::json toJson() const
Serializes this object to JSON.
SharedUser(const nl::json &json)
std::int64_t userId
Identifier of the shared user. This number may have more than 32 significant bits and some programmin...
void fromJson(const nl::json &json)
Deserializes this object from JSON.
std::string username
Optional. Username of the user, if the username was requested by the bot.
std::string lastName
Optional. Last name of the user, if the name was requested by the bot.
std::string firstName
Optional. First name of the user, if the name was requested by the bot.
std::vector< Ptr< PhotoSize > > photo
Optional. Available sizes of the chat photo, if the photo was requested by the bot.