tgbotxx 1.1.6.9
Telegram Bot C++ Library
Loading...
Searching...
No Matches
Contact.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace tgbotxx {
7 struct Contact {
8 Contact() = default;
9 explicit Contact(const nl::json& json) {
10 fromJson(json);
11 }
12
14 std::string phoneNumber;
15
17 std::string firstName;
18
20 std::string lastName;
21
26 std::int64_t userId{};
27
30 std::string vcard;
31
32
35 nl::json toJson() const {
36 nl::json json = nl::json::object();
37 OBJECT_SERIALIZE_FIELD(json, "phone_number", phoneNumber);
38 OBJECT_SERIALIZE_FIELD(json, "first_name", firstName);
39 OBJECT_SERIALIZE_FIELD(json, "last_name", lastName);
40 OBJECT_SERIALIZE_FIELD(json, "user_id", userId);
41 OBJECT_SERIALIZE_FIELD(json, "vcard", vcard);
42 return json;
43 }
44
46 void fromJson(const nl::json& json) {
47 OBJECT_DESERIALIZE_FIELD(json, "phone_number", phoneNumber, "", false);
48 OBJECT_DESERIALIZE_FIELD(json, "first_name", firstName, "", false);
49 OBJECT_DESERIALIZE_FIELD(json, "last_name", lastName, "", true);
50 OBJECT_DESERIALIZE_FIELD(json, "user_id", userId, 0, true);
51 OBJECT_DESERIALIZE_FIELD(json, "vcard", vcard, "", true);
52 }
53 };
54}
#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
This object represents a phone contact. https://core.telegram.org/bots/api#contact.
Definition Contact.hpp:7
std::string lastName
Optional. Contact's last name.
Definition Contact.hpp:20
nl::json toJson() const
Serializes this object to JSON.
Definition Contact.hpp:35
std::string phoneNumber
Contact's phone number.
Definition Contact.hpp:14
std::string firstName
Contact's first name.
Definition Contact.hpp:17
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition Contact.hpp:46
Contact(const nl::json &json)
Definition Contact.hpp:9
std::string vcard
Optional. Additional data about the contact in the form of a vCard https://en.wikipedia....
Definition Contact.hpp:30
std::int64_t userId
Optional. Contact's user identifier in Telegram. This number may have more than 32 significant bits a...
Definition Contact.hpp:26
Contact()=default