tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
OwnedGift.hpp
Go to the documentation of this file.
1#pragma once
7
8namespace tgbotxx {
9
12 struct OwnedGift {
13 OwnedGift() = default;
14 explicit OwnedGift(const nl::json& json) {
15 _fromJson(json);
16 }
17 virtual ~OwnedGift() = default;
18
20 std::string type;
21
24 virtual nl::json toJson() const {
25 nl::json json = nl::json::object();
26 OBJECT_SERIALIZE_FIELD(json, "type", type);
27 return json;
28 }
29
31 virtual void fromJson(const nl::json& json) {
32 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
33 }
34 private:
35 void _fromJson(const nl::json& json) {
36 fromJson(json);
37 }
38 };
39
43 OwnedGift::type = "regular";
44 }
45 explicit OwnedGiftRegular(const nl::json& json) : OwnedGift(json) {
46 OwnedGift::type = "regular";
47 }
48 ~OwnedGiftRegular() override = default;
49
52
54 std::string ownedGiftId;
55
58
60 std::int64_t sendDate{};
61
63 std::string text;
64
66 std::vector<Ptr<MessageEntity>> entities;
67
69 bool isPrivate{};
70
72 bool isSaved{};
73
76
79
81 std::int32_t convertStarCount{};
82
85
87 nl::json toJson() const override {
88 nl::json json = OwnedGift::toJson();
89 OBJECT_SERIALIZE_FIELD_PTR(json, "gift", gift);
90 OBJECT_SERIALIZE_FIELD(json, "owned_gift_id", ownedGiftId);
91 OBJECT_SERIALIZE_FIELD_PTR(json, "sender_user", senderUser);
92 OBJECT_SERIALIZE_FIELD(json, "send_date", sendDate);
93 OBJECT_SERIALIZE_FIELD(json, "text", text);
95 OBJECT_SERIALIZE_FIELD(json, "is_private", isPrivate);
96 OBJECT_SERIALIZE_FIELD(json, "is_saved", isSaved);
97 OBJECT_SERIALIZE_FIELD(json, "can_be_upgraded", canBeUpgraded);
98 OBJECT_SERIALIZE_FIELD(json, "was_refunded", wasRefunded);
99 OBJECT_SERIALIZE_FIELD(json, "convert_star_count", convertStarCount);
100 OBJECT_SERIALIZE_FIELD(json, "prepaid_upgrade_star_count", prepaidUpgradeStarCount);
101 return json;
102 }
103
105 void fromJson(const nl::json& json) override {
107 OBJECT_DESERIALIZE_FIELD_PTR(json, "gift", gift, false);
108 OBJECT_DESERIALIZE_FIELD(json, "owned_gift_id", ownedGiftId, "", true);
109 OBJECT_DESERIALIZE_FIELD_PTR(json, "sender_user", senderUser, true);
110 OBJECT_DESERIALIZE_FIELD(json, "send_date", sendDate, 0, false);
111 OBJECT_DESERIALIZE_FIELD(json, "text", text, "", true);
112 OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "entities", entities, true);
113 OBJECT_DESERIALIZE_FIELD(json, "is_private", isPrivate, false, true);
114 OBJECT_DESERIALIZE_FIELD(json, "is_saved", isSaved, false, true);
115 OBJECT_DESERIALIZE_FIELD(json, "can_be_upgraded", canBeUpgraded, false, true);
116 OBJECT_DESERIALIZE_FIELD(json, "was_refunded", wasRefunded, false, true);
117 OBJECT_DESERIALIZE_FIELD(json, "convert_star_count", convertStarCount, 0, true);
118 OBJECT_DESERIALIZE_FIELD(json, "prepaid_upgrade_star_count", prepaidUpgradeStarCount, 0, true);
119 }
120 };
121
125 OwnedGift::type = "unique";
126 }
127 explicit OwnedGiftUnique(const nl::json& json) : OwnedGift(json) {
128 OwnedGift::type = "unique";
129 }
130 ~OwnedGiftUnique() override = default;
131
134
136 std::string ownedGiftId;
137
140
142 std::int64_t sendDate{};
143
145 bool isSaved{};
146
149
151 std::int32_t transferStarCount{};
152
154 std::int64_t nextTransferDate{};
155
157 nl::json toJson() const override {
158 nl::json json = OwnedGift::toJson();
159 OBJECT_SERIALIZE_FIELD_PTR(json, "gift", gift);
160 OBJECT_SERIALIZE_FIELD(json, "owned_gift_id", ownedGiftId);
161 OBJECT_SERIALIZE_FIELD_PTR(json, "sender_user", senderUser);
162 OBJECT_SERIALIZE_FIELD(json, "send_date", sendDate);
163 OBJECT_SERIALIZE_FIELD(json, "is_saved", isSaved);
164 OBJECT_SERIALIZE_FIELD(json, "can_be_transferred", canBeTransferred);
165 OBJECT_SERIALIZE_FIELD(json, "transfer_star_count", transferStarCount);
166 OBJECT_SERIALIZE_FIELD(json, "next_transfer_date", nextTransferDate);
167 return json;
168 }
169
171 void fromJson(const nl::json& json) override {
173 OBJECT_DESERIALIZE_FIELD_PTR(json, "gift", gift, false);
174 OBJECT_DESERIALIZE_FIELD(json, "owned_gift_id", ownedGiftId, "", true);
175 OBJECT_DESERIALIZE_FIELD_PTR(json, "sender_user", senderUser, true);
176 OBJECT_DESERIALIZE_FIELD(json, "send_date", sendDate, 0, false);
177 OBJECT_DESERIALIZE_FIELD(json, "is_saved", isSaved, false, true);
178 OBJECT_DESERIALIZE_FIELD(json, "can_be_transferred", canBeTransferred, false, true);
179 OBJECT_DESERIALIZE_FIELD(json, "transfer_star_count", transferStarCount, 0, true);
180 OBJECT_DESERIALIZE_FIELD(json, "next_transfer_date", nextTransferDate, 0, true);
181 }
182 };
183
184}
#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:72
#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
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
Base class for a gift owned by a user or a chat Can be either OwnedGiftRegular or OwnedGiftUnique.
Definition OwnedGift.hpp:12
OwnedGift(const nl::json &json)
Definition OwnedGift.hpp:14
std::string type
Type of the gift: "regular" or "unique".
Definition OwnedGift.hpp:20
virtual nl::json toJson() const
Serializes this object to JSON.
Definition OwnedGift.hpp:24
virtual ~OwnedGift()=default
virtual void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition OwnedGift.hpp:31
Describes a regular gift owned by a user or a chat.
Definition OwnedGift.hpp:41
bool wasRefunded
Optional. True, if the gift was refunded and isn't available anymore.
Definition OwnedGift.hpp:78
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
~OwnedGiftRegular() override=default
Ptr< Gift > gift
Information about the regular gift.
Definition OwnedGift.hpp:51
std::vector< Ptr< MessageEntity > > entities
Optional. Special entities that appear in the text.
Definition OwnedGift.hpp:66
std::string text
Optional. Text of the message that was added to the gift.
Definition OwnedGift.hpp:63
std::int64_t sendDate
Date the gift was sent in Unix time.
Definition OwnedGift.hpp:60
bool isSaved
Optional. True, if the gift is displayed on the account's profile page; for gifts received on behalf ...
Definition OwnedGift.hpp:72
std::int32_t convertStarCount
Optional. Number of Telegram Stars that can be claimed by the receiver instead of the gift.
Definition OwnedGift.hpp:81
bool canBeUpgraded
Optional. True, if the gift can be upgraded to a unique gift; for gifts received on behalf of busines...
Definition OwnedGift.hpp:75
bool isPrivate
Optional. True, if the sender and gift text are shown only to the gift receiver.
Definition OwnedGift.hpp:69
std::int32_t prepaidUpgradeStarCount
Optional. Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
Definition OwnedGift.hpp:84
OwnedGiftRegular(const nl::json &json)
Definition OwnedGift.hpp:45
std::string ownedGiftId
Optional. Unique identifier of the gift for the bot; for gifts received on behalf of business account...
Definition OwnedGift.hpp:54
Ptr< User > senderUser
Optional. Sender of the gift if it is a known user.
Definition OwnedGift.hpp:57
nl::json toJson() const override
Serializes this object to JSON.
Definition OwnedGift.hpp:87
Describes a unique gift owned by a user or a chat.
~OwnedGiftUnique() override=default
OwnedGiftUnique(const nl::json &json)
Ptr< UniqueGift > gift
Information about the unique gift.
std::int64_t nextTransferDate
Optional. Point in time (Unix timestamp) when the gift can be transferred. If it is in the past,...
std::int64_t sendDate
Date the gift was sent in Unix time.
std::int32_t transferStarCount
Optional. Number of Telegram Stars that must be paid to transfer the gift.
std::string ownedGiftId
Optional. Unique identifier of the received gift for the bot; for gifts received on behalf of busines...
Ptr< User > senderUser
Optional. Sender of the gift if it is a known user.
bool canBeTransferred
Optional. True, if the gift can be transferred to another owner; for gifts received on behalf of busi...
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
bool isSaved
Optional. True, if the gift is displayed on the account's profile page; for gifts received on behalf ...
nl::json toJson() const override
Serializes this object to JSON.