tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
InputSticker.hpp
Go to the documentation of this file.
1#pragma once
2#include <cpr/file.h>
5#include <variant>
6
7namespace tgbotxx {
10 struct InputSticker {
11 InputSticker() = default;
12 explicit InputSticker(const nl::json& json) {
13 fromJson(json);
14 }
15
21 std::variant<cpr::File, std::string> sticker{""};
22
24 std::string format;
25
27 std::vector<std::string> emojiList;
28
31
34 std::vector<std::string> keywords;
35
38 nl::json toJson() const {
39 nl::json json = nl::json::object();
40 // sticker variant
41 if (auto idx = sticker.index(); idx == 0)
42 json["sticker"] = std::get<cpr::File>(sticker).filepath;
43 else if (idx == 1)
44 json["sticker"] = std::get<std::string>(sticker);
45 OBJECT_SERIALIZE_FIELD(json, "format", format);
46 OBJECT_SERIALIZE_FIELD(json, "emoji_list", emojiList);
47 OBJECT_SERIALIZE_FIELD_PTR(json, "mask_position", maskPosition);
48 OBJECT_SERIALIZE_FIELD(json, "keywords", keywords);
49 return json;
50 }
51
53 void fromJson(const nl::json& json) {
54 // sticker variant, we can't get a local file from remote, so it's always a URL or file id std::string.
55 OBJECT_DESERIALIZE_FIELD(json, "sticker", std::get<std::string>(sticker), "", false);
56 OBJECT_DESERIALIZE_FIELD(json, "format", format, "", false);
57 OBJECT_DESERIALIZE_FIELD(json, "emoji_list", emojiList, std::vector<std::string>(), false);
58 OBJECT_DESERIALIZE_FIELD_PTR(json, "mask_position", maskPosition, true);
59 OBJECT_DESERIALIZE_FIELD(json, "keywords", keywords, std::vector<std::string>(), true);
60 }
61 };
62}
#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
This object describes a sticker to be added to a sticker set. https://core.telegram....
void fromJson(const nl::json &json)
Deserializes this object from JSON.
std::variant< cpr::File, std::string > sticker
The added sticker.
Ptr< MaskPosition > maskPosition
Optional. Position where the mask should be placed on faces. For “mask” stickers only.
std::string format
Format of the added sticker, must be one of “static” for a .WEBP or .PNG image, “animated” for a ....
nl::json toJson() const
Serializes this object to JSON.
InputSticker(const nl::json &json)
std::vector< std::string > emojiList
List of 1-20 emoji associated with the sticker.
std::vector< std::string > keywords
Optional. List of 0-20 search keywords for the sticker with total length of up to 64 characters....