tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
Sticker.hpp
Go to the documentation of this file.
1#pragma once
6
7namespace tgbotxx {
10 struct Sticker {
11 Sticker() = default;
12 explicit Sticker(const nl::json& json) {
13 fromJson(json);
14 }
15
17 std::string fileId;
18
21 std::string fileUniqueId;
22
24 enum class Type : std::uint8_t {
25 Regular = 0,
26 Mask,
28 };
30 static std::optional<std::string> TypeToString(const Type type) noexcept {
31 if (type == Type::Regular) return "regular";
32 if (type == Type::Mask) return "mask";
33 if (type == Type::CustomEmoji) return "custom_emoji";
34 return std::nullopt;
35 }
37 static std::optional<Type> StringToType(const std::string& str) noexcept {
38 if (str == "regular") return Type::Regular;
39 if (str == "mask") return Type::Mask;
40 if (str == "custom_emoji") return Type::CustomEmoji;
41 return std::nullopt;
42 }
46
48 std::int32_t width{};
49
51 std::int32_t height{};
52
54 bool isAnimated{};
55
57 bool isVideo{};
58
61
63 std::string emoji;
64
66 std::string setName;
67
70
73
75 std::string customEmojiId;
76
81
83 std::int64_t fileSize{};
84
85
88 nl::json toJson() const {
89 nl::json json = nl::json::object();
90 OBJECT_SERIALIZE_FIELD(json, "file_id", fileId);
91 OBJECT_SERIALIZE_FIELD(json, "file_unique_id", fileUniqueId);
93 OBJECT_SERIALIZE_FIELD(json, "width", width);
94 OBJECT_SERIALIZE_FIELD(json, "height", height);
95 OBJECT_SERIALIZE_FIELD(json, "is_animated", isAnimated);
96 OBJECT_SERIALIZE_FIELD(json, "is_video", isVideo);
97 OBJECT_SERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail);
98 OBJECT_SERIALIZE_FIELD(json, "emoji", emoji);
99 OBJECT_SERIALIZE_FIELD(json, "set_name", setName);
100 OBJECT_SERIALIZE_FIELD_PTR(json, "premium_animation", premiumAnimation);
101 OBJECT_SERIALIZE_FIELD_PTR(json, "mask_position", maskPosition);
102 OBJECT_SERIALIZE_FIELD(json, "custom_emoji_id", customEmojiId);
103 OBJECT_SERIALIZE_FIELD(json, "needs_repainting", needsRepainting);
104 OBJECT_SERIALIZE_FIELD(json, "file_size", fileSize);
105 return json;
106 }
107
109 void fromJson(const nl::json& json) {
110 OBJECT_DESERIALIZE_FIELD(json, "file_id", fileId, "", false);
111 OBJECT_DESERIALIZE_FIELD(json, "file_unique_id", fileUniqueId, "", false);
112 OBJECT_DESERIALIZE_FIELD_ENUM(json, Type, "type", type, 0, false);
113 OBJECT_DESERIALIZE_FIELD(json, "width", width, 0, false);
114 OBJECT_DESERIALIZE_FIELD(json, "height", height, 0, false);
115 OBJECT_DESERIALIZE_FIELD(json, "is_animated", isAnimated, false, false);
116 OBJECT_DESERIALIZE_FIELD(json, "is_video", isVideo, false, false);
117 OBJECT_DESERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail, true);
118 OBJECT_DESERIALIZE_FIELD(json, "emoji", emoji, "", true);
119 OBJECT_DESERIALIZE_FIELD(json, "set_name", setName, "", true);
120 OBJECT_DESERIALIZE_FIELD_PTR(json, "premium_animation", premiumAnimation, true);
121 OBJECT_DESERIALIZE_FIELD_PTR(json, "mask_position", maskPosition, true);
122 OBJECT_DESERIALIZE_FIELD(json, "custom_emoji_id", customEmojiId, "", true);
123 OBJECT_DESERIALIZE_FIELD(json, "needs_repainting", needsRepainting, false, true);
124 OBJECT_DESERIALIZE_FIELD(json, "file_size", fileSize, 0, true);
125 }
126 };
127}
#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_ENUM(json, enum_name, json_field, field, default_value, optional)
Definition Object.hpp:137
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition Object.hpp:46
#define OBJECT_SERIALIZE_FIELD_ENUM(json, enum_name, json_field, field)
Definition Object.hpp:42
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
This object represents a sticker. https://core.telegram.org/bots/api#sticker.
Definition Sticker.hpp:10
Type type
Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”. The type of the sticker is i...
Definition Sticker.hpp:45
static std::optional< Type > StringToType(const std::string &str) noexcept
Converts string to an enum Type.
Definition Sticker.hpp:37
Sticker()=default
static std::optional< std::string > TypeToString(const Type type) noexcept
Converts enum Type to a string.
Definition Sticker.hpp:30
std::string emoji
Optional. Emoji associated with the sticker.
Definition Sticker.hpp:63
bool isVideo
True, if the sticker is a video sticker.
Definition Sticker.hpp:57
std::string fileUniqueId
Unique identifier for this file, which is supposed to be the same over time and for different bots....
Definition Sticker.hpp:21
Sticker(const nl::json &json)
Definition Sticker.hpp:12
Type
Enum of possible types of Type.
Definition Sticker.hpp:24
std::int64_t fileSize
Optional. File size in bytes.
Definition Sticker.hpp:83
std::int32_t height
Sticker height.
Definition Sticker.hpp:51
bool needsRepainting
Optional. True, if the sticker must be repainted to a text color in messages, the color of the Telegr...
Definition Sticker.hpp:80
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition Sticker.hpp:109
std::string customEmojiId
Optional. For custom emoji stickers, unique identifier of the custom emoji.
Definition Sticker.hpp:75
std::string setName
Optional. Name of the sticker set to which the sticker belongs.
Definition Sticker.hpp:66
std::int32_t width
Sticker width.
Definition Sticker.hpp:48
Ptr< File > premiumAnimation
Optional. For premium regular stickers, premium animation for the sticker.
Definition Sticker.hpp:69
nl::json toJson() const
Serializes this object to JSON.
Definition Sticker.hpp:88
std::string fileId
Identifier for this file, which can be used to download or reuse the file.
Definition Sticker.hpp:17
Ptr< MaskPosition > maskPosition
Optional. For mask stickers, the position where the mask should be placed.
Definition Sticker.hpp:72
bool isAnimated
True, if the sticker is animated.
Definition Sticker.hpp:54
Ptr< PhotoSize > thumbnail
Optional. Sticker thumbnail in the .WEBP or .JPG format.
Definition Sticker.hpp:60