tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
StoryAreaType.hpp
Go to the documentation of this file.
1#pragma once
5#include <string>
6
7namespace tgbotxx {
8
12 StoryAreaType() = default;
13 explicit StoryAreaType(const nl::json& json) {
14 _fromJson(json);
15 }
16 virtual ~StoryAreaType() = default;
17
19 std::string type;
20
21 virtual nl::json toJson() const {
22 nl::json json = nl::json::object();
23 OBJECT_SERIALIZE_FIELD(json, "type", type);
24 return json;
25 }
26
27 virtual void fromJson(const nl::json& json) {
28 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
29 }
30
31 private:
32 void _fromJson(const nl::json& json) {
33 fromJson(json);
34 }
35 };
36
40 StoryAreaType::type = "location";
41 }
42 explicit StoryAreaTypeLocation(const nl::json& json) : StoryAreaType(json) {
43 StoryAreaType::type = "location";
44 }
45
46 float latitude{};
47 float longitude{};
49
50 nl::json toJson() const override {
51 nl::json json = StoryAreaType::toJson();
52 OBJECT_SERIALIZE_FIELD(json, "latitude", latitude);
53 OBJECT_SERIALIZE_FIELD(json, "longitude", longitude);
54 OBJECT_SERIALIZE_FIELD_PTR(json, "address", address);
55 return json;
56 }
57
58 void fromJson(const nl::json& json) override {
60 OBJECT_DESERIALIZE_FIELD(json, "latitude", latitude, 0.0f, false);
61 OBJECT_DESERIALIZE_FIELD(json, "longitude", longitude, 0.0f, false);
62 OBJECT_DESERIALIZE_FIELD_PTR(json, "address", address, true);
63 }
64 };
65
69 StoryAreaType::type = "suggested_reaction";
70 }
71 explicit StoryAreaTypeSuggestedReaction(const nl::json& json) : StoryAreaType(json) {
72 StoryAreaType::type = "suggested_reaction";
73 }
74
76 bool isDark{};
77 bool isFlipped{};
78
79 nl::json toJson() const override {
80 nl::json json = StoryAreaType::toJson();
81 OBJECT_SERIALIZE_FIELD_PTR(json, "reaction_type", reactionType);
82 OBJECT_SERIALIZE_FIELD(json, "is_dark", isDark);
83 OBJECT_SERIALIZE_FIELD(json, "is_flipped", isFlipped);
84 return json;
85 }
86
87 void fromJson(const nl::json& json) override {
89 OBJECT_DESERIALIZE_FIELD_PTR(json, "reaction_type", reactionType, false);
90 OBJECT_DESERIALIZE_FIELD(json, "is_dark", isDark, false, true);
91 OBJECT_DESERIALIZE_FIELD(json, "is_flipped", isFlipped, false, true);
92 }
93 };
94
100 explicit StoryAreaTypeLink(const nl::json& json) : StoryAreaType(json) {
101 StoryAreaType::type = "link";
102 }
103
104 std::string url;
105
106 nl::json toJson() const override {
107 nl::json json = StoryAreaType::toJson();
108 OBJECT_SERIALIZE_FIELD(json, "url", url);
109 return json;
110 }
111
112 void fromJson(const nl::json& json) override {
114 OBJECT_DESERIALIZE_FIELD(json, "url", url, "", false);
115 }
116 };
117
121 StoryAreaType::type = "weather";
122 }
123 explicit StoryAreaTypeWeather(const nl::json& json) : StoryAreaType(json) {
124 StoryAreaType::type = "weather";
125 }
126
127 float temperature{};
128 std::string emoji;
129 std::int32_t backgroundColor{};
130
131 nl::json toJson() const override {
132 nl::json json = StoryAreaType::toJson();
133 OBJECT_SERIALIZE_FIELD(json, "temperature", temperature);
134 OBJECT_SERIALIZE_FIELD(json, "emoji", emoji);
135 OBJECT_SERIALIZE_FIELD(json, "background_color", backgroundColor);
136 return json;
137 }
138
139 void fromJson(const nl::json& json) override {
141 OBJECT_DESERIALIZE_FIELD(json, "temperature", temperature, 0.0f, false);
142 OBJECT_DESERIALIZE_FIELD(json, "emoji", emoji, "", false);
143 OBJECT_DESERIALIZE_FIELD(json, "background_color", backgroundColor, 0, false);
144 }
145 };
146
150 StoryAreaType::type = "unique_gift";
151 }
152 explicit StoryAreaTypeUniqueGift(const nl::json& json) : StoryAreaType(json) {
153 StoryAreaType::type = "unique_gift";
154 }
155
156 std::string name;
157
158 nl::json toJson() const override {
159 nl::json json = StoryAreaType::toJson();
160 OBJECT_SERIALIZE_FIELD(json, "name", name);
161 return json;
162 }
163
164 void fromJson(const nl::json& json) override {
166 OBJECT_DESERIALIZE_FIELD(json, "name", name, "", false);
167 }
168 };
169
170}
#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
Base class for types of clickable areas on a story https://core.telegram.org/bots/api#storyareatype.
virtual void fromJson(const nl::json &json)
virtual ~StoryAreaType()=default
StoryAreaType()=default
StoryAreaType(const nl::json &json)
std::string type
Type of the area.
virtual nl::json toJson() const
Story area pointing to a link.
nl::json toJson() const override
StoryAreaTypeLink(const nl::json &json)
void fromJson(const nl::json &json) override
std::string url
StoryAreaTypeLink()
Story area pointing to a location.
nl::json toJson() const override
Ptr< LocationAddress > address
StoryAreaTypeLocation(const nl::json &json)
float latitude
float longitude
void fromJson(const nl::json &json) override
StoryAreaTypeLocation()
Story area pointing to a suggested reaction.
StoryAreaTypeSuggestedReaction(const nl::json &json)
StoryAreaTypeSuggestedReaction()
bool isFlipped
Ptr< ReactionType > reactionType
bool isDark
void fromJson(const nl::json &json) override
nl::json toJson() const override
Story area pointing to a unique gift.
void fromJson(const nl::json &json) override
StoryAreaTypeUniqueGift()
StoryAreaTypeUniqueGift(const nl::json &json)
std::string name
nl::json toJson() const override
Story area showing weather information.
std::string emoji
nl::json toJson() const override
StoryAreaTypeWeather(const nl::json &json)
void fromJson(const nl::json &json) override
float temperature
StoryAreaTypeWeather()
std::int32_t backgroundColor