tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
ChatBoostSource.hpp
Go to the documentation of this file.
1#pragma once
4
5namespace tgbotxx {
12 ChatBoostSource() = default;
13 explicit ChatBoostSource(const nl::json& json) {
14 _fromJson(json);
15 }
16 virtual ~ChatBoostSource() = default;
17
19 std::string source;
20
21
24 virtual nl::json toJson() const {
25 nl::json json = nl::json::object();
26 OBJECT_SERIALIZE_FIELD(json, "source", source);
27 return json;
28 }
29
31 virtual void fromJson(const nl::json& json) {
32 OBJECT_DESERIALIZE_FIELD(json, "source", source, "", false);
33 }
34
35 private:
36 void _fromJson(const nl::json& json) {
37 fromJson(json);
38 }
39 };
40
47 explicit ChatBoostSourcePremium(const nl::json& json) {
49 ChatBoostSource::source = "premium";
50 }
51
54
55 nl::json toJson() const override {
56 nl::json json = ChatBoostSource::toJson();
57 OBJECT_SERIALIZE_FIELD_PTR(json, "user", user);
58 return json;
59 }
60 void fromJson(const nl::json& json) override {
62 OBJECT_DESERIALIZE_FIELD_PTR(json, "user", user, false);
63 }
64 };
65
72 explicit ChatBoostSourceGiftCode(const nl::json& json) {
74 ChatBoostSource::source = "gift_code";
75 }
76
79
80 nl::json toJson() const override {
81 nl::json json = ChatBoostSource::toJson();
82 OBJECT_SERIALIZE_FIELD_PTR(json, "user", user);
83 return json;
84 }
85 void fromJson(const nl::json& json) override {
87 OBJECT_DESERIALIZE_FIELD_PTR(json, "user", user, false);
88 }
89 };
90
98 explicit ChatBoostSourceGiveaway(const nl::json& json) {
100 ChatBoostSource::source = "giveaway";
101 }
102
105 std::int32_t giveawayMessageId{};
106
109
112
113 nl::json toJson() const override {
114 nl::json json = ChatBoostSource::toJson();
115 OBJECT_SERIALIZE_FIELD(json, "giveaway_message_id", giveawayMessageId);
116 OBJECT_SERIALIZE_FIELD_PTR(json, "user", user);
117 OBJECT_SERIALIZE_FIELD(json, "is_unclaimed", isUnclaimed);
118 return json;
119 }
120 void fromJson(const nl::json& json) override {
122 OBJECT_DESERIALIZE_FIELD(json, "giveaway_message_id", giveawayMessageId, 0, false);
123 OBJECT_DESERIALIZE_FIELD_PTR(json, "user", user, true);
124 OBJECT_DESERIALIZE_FIELD(json, "is_unclaimed", isUnclaimed, 0, true);
125 }
126 };
127
128
129}
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition Object.hpp:22
#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
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
The boost was obtained by subscribing to Telegram Premium or by gifting a Telegram Premium subscripti...
Ptr< User > user
User for which the gift code was created.
nl::json toJson() const override
Serializes this object to JSON.
ChatBoostSourceGiftCode(const nl::json &json)
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
The boost was obtained by the creation of a Telegram Premium giveaway. This boosts the chat 4 times f...
Ptr< User > user
Optional. User that won the prize in the giveaway if any.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
nl::json toJson() const override
Serializes this object to JSON.
std::int32_t giveawayMessageId
Identifier of a message in the chat with the giveaway; the message could have been deleted already....
ChatBoostSourceGiveaway(const nl::json &json)
bool isUnclaimed
Optional. True, if the giveaway was completed, but there was no user to win the prize.
This object describes the source of a chat boost. It can be one of:
ChatBoostSource(const nl::json &json)
virtual nl::json toJson() const
Serializes this object to JSON.
virtual ~ChatBoostSource()=default
virtual void fromJson(const nl::json &json)
Deserializes this object from JSON.
std::string source
Source of the boost.
The boost was obtained by subscribing to Telegram Premium or by gifting a Telegram Premium subscripti...
ChatBoostSourcePremium(const nl::json &json)
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
nl::json toJson() const override
Serializes this object to JSON.
Ptr< User > user
User that boosted the chat.