tgbotxx 1.2.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) {
16 }
17 virtual ~OwnedGift() = default;
18
20 std::string type;
21
24 virtual nl::json toJson() const {
25 nl::json json = nl::json::object();
27 return json;
28 }
29
31 virtual void fromJson(const nl::json& json) {
32 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
33 }
34 };
35
39 type = "regular";
40 }
41 explicit OwnedGiftRegular(const nl::json& json) {
43 }
44 ~OwnedGiftRegular() override = default;
45
48
50 std::string ownedGiftId;
51
54
56 std::int64_t sendDate{};
57
59 std::string text;
60
62 std::vector<Ptr<MessageEntity>> entities;
63
65 bool isPrivate{};
66
68 bool isSaved{};
69
72
75
77 std::int32_t convertStarCount{};
78
81
83 nl::json toJson() const override {
84 nl::json json = OwnedGift::toJson();
86 OBJECT_SERIALIZE_FIELD(json, "owned_gift_id", ownedGiftId);
93 OBJECT_SERIALIZE_FIELD(json, "can_be_upgraded", canBeUpgraded);
94 OBJECT_SERIALIZE_FIELD(json, "was_refunded", wasRefunded);
95 OBJECT_SERIALIZE_FIELD(json, "convert_star_count", convertStarCount);
96 OBJECT_SERIALIZE_FIELD(json, "prepaid_upgrade_star_count", prepaidUpgradeStarCount);
97 return json;
98 }
99
101 void fromJson(const nl::json& json) override {
103 OBJECT_DESERIALIZE_FIELD_PTR(json, "gift", gift, false);
104 OBJECT_DESERIALIZE_FIELD(json, "owned_gift_id", ownedGiftId, "", true);
105 OBJECT_DESERIALIZE_FIELD_PTR(json, "sender_user", senderUser, true);
106 OBJECT_DESERIALIZE_FIELD(json, "send_date", sendDate, 0, false);
107 OBJECT_DESERIALIZE_FIELD(json, "text", text, "", true);
109 OBJECT_DESERIALIZE_FIELD(json, "is_private", isPrivate, false, true);
110 OBJECT_DESERIALIZE_FIELD(json, "is_saved", isSaved, false, true);
111 OBJECT_DESERIALIZE_FIELD(json, "can_be_upgraded", canBeUpgraded, false, true);
112 OBJECT_DESERIALIZE_FIELD(json, "was_refunded", wasRefunded, false, true);
113 OBJECT_DESERIALIZE_FIELD(json, "convert_star_count", convertStarCount, 0, true);
114 OBJECT_DESERIALIZE_FIELD(json, "prepaid_upgrade_star_count", prepaidUpgradeStarCount, 0, true);
115 }
116 };
117
121 type = "unique";
122 }
123 explicit OwnedGiftUnique(const nl::json& json) {
125 }
126 ~OwnedGiftUnique() override = default;
127
130
132 std::string ownedGiftId;
133
136
138 std::int64_t sendDate{};
139
141 bool isSaved{};
142
145
147 std::int32_t transferStarCount{};
148
150 std::int64_t nextTransferDate{};
151
153 [[nodiscard]] nl::json toJson() const override {
154 nl::json json = OwnedGift::toJson();
156 OBJECT_SERIALIZE_FIELD(json, "owned_gift_id", ownedGiftId);
158 OBJECT_SERIALIZE_FIELD(json, "send_date", sendDate);
159 OBJECT_SERIALIZE_FIELD(json, "is_saved", isSaved);
160 OBJECT_SERIALIZE_FIELD(json, "can_be_transferred", canBeTransferred);
161 OBJECT_SERIALIZE_FIELD(json, "transfer_star_count", transferStarCount);
162 OBJECT_SERIALIZE_FIELD(json, "next_transfer_date", nextTransferDate);
163 return json;
164 }
165
167 void fromJson(const nl::json& json) override {
169 OBJECT_DESERIALIZE_FIELD_PTR(json, "gift", gift, false);
170 OBJECT_DESERIALIZE_FIELD(json, "owned_gift_id", ownedGiftId, "", true);
171 OBJECT_DESERIALIZE_FIELD_PTR(json, "sender_user", senderUser, true);
172 OBJECT_DESERIALIZE_FIELD(json, "send_date", sendDate, 0, false);
173 OBJECT_DESERIALIZE_FIELD(json, "is_saved", isSaved, false, true);
174 OBJECT_DESERIALIZE_FIELD(json, "can_be_transferred", canBeTransferred, false, true);
175 OBJECT_DESERIALIZE_FIELD(json, "transfer_star_count", transferStarCount, 0, true);
176 OBJECT_DESERIALIZE_FIELD(json, "next_transfer_date", nextTransferDate, 0, true);
177 }
178 };
179
180}
#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:37
bool wasRefunded
Optional. True, if the gift was refunded and isn't available anymore.
Definition OwnedGift.hpp:74
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:47
std::vector< Ptr< MessageEntity > > entities
Optional. Special entities that appear in the text.
Definition OwnedGift.hpp:62
std::string text
Optional. Text of the message that was added to the gift.
Definition OwnedGift.hpp:59
std::int64_t sendDate
Date the gift was sent in Unix time.
Definition OwnedGift.hpp:56
bool isSaved
Optional. True, if the gift is displayed on the account's profile page; for gifts received on behalf ...
Definition OwnedGift.hpp:68
std::int32_t convertStarCount
Optional. Number of Telegram Stars that can be claimed by the receiver instead of the gift.
Definition OwnedGift.hpp:77
bool canBeUpgraded
Optional. True, if the gift can be upgraded to a unique gift; for gifts received on behalf of busines...
Definition OwnedGift.hpp:71
bool isPrivate
Optional. True, if the sender and gift text are shown only to the gift receiver.
Definition OwnedGift.hpp:65
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:80
OwnedGiftRegular(const nl::json &json)
Definition OwnedGift.hpp:41
std::string ownedGiftId
Optional. Unique identifier of the gift for the bot; for gifts received on behalf of business account...
Definition OwnedGift.hpp:50
Ptr< User > senderUser
Optional. Sender of the gift if it is a known user.
Definition OwnedGift.hpp:53
nl::json toJson() const override
Serializes this object to JSON.
Definition OwnedGift.hpp:83
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.