tgbotxx 1.1.6.9
Telegram Bot C++ Library
Loading...
Searching...
No Matches
InputMedia.hpp
Go to the documentation of this file.
1#pragma once
4
5namespace tgbotxx {
13 struct InputMedia {
14 InputMedia() = default;
15 explicit InputMedia(const nl::json& json) {
16 _fromJson(json);
17 }
18
20 std::string type;
21
28 std::variant<cpr::File, std::string> media{""};
29
31 std::string caption;
32
35 std::string parseMode;
36
38 std::vector<Ptr<MessageEntity>> captionEntities;
39
40
43 virtual nl::json toJson() const {
44 nl::json json = nl::json::object();
45 OBJECT_SERIALIZE_FIELD(json, "type", type);
46 // media variant
47 if (auto idx = media.index(); idx == 0)
48 json["media"] = std::get<cpr::File>(media).filepath;
49 else if (idx == 1)
50 json["media"] = std::get<std::string>(media);
51 OBJECT_SERIALIZE_FIELD(json, "caption", caption);
52 OBJECT_SERIALIZE_FIELD(json, "parse_mode", parseMode);
53 OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, "caption_entities", captionEntities);
54 return json;
55 }
56
58 virtual void fromJson(const nl::json& json) {
59 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
60 // media variant, we can't get a local file from remote, so it's always a URL or file id std::string.
61 OBJECT_DESERIALIZE_FIELD(json, "media", std::get<std::string>(media), "", false);
62 OBJECT_DESERIALIZE_FIELD(json, "caption", caption, "", true);
63 OBJECT_DESERIALIZE_FIELD(json, "parse_mode", parseMode, "", true);
64 OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "caption_entities", captionEntities, true);
65 }
66
67 private:
68 void _fromJson(const nl::json& json) {
69 fromJson(json);
70 }
71 };
72
77 InputMedia::type = "animation";
78 }
79 explicit InputMediaAnimation(const nl::json& json) {
81 InputMedia::type = "animation";
82 }
83
89 std::string thumbnail;
90
92 std::int32_t width{};
93
95 std::int32_t height{};
96
98 std::int32_t duration{};
99
102
103
104 nl::json toJson() const override {
105 nl::json json = InputMedia::toJson();
106 OBJECT_SERIALIZE_FIELD(json, "thumbnail", thumbnail);
107 OBJECT_SERIALIZE_FIELD(json, "width", width);
108 OBJECT_SERIALIZE_FIELD(json, "height", height);
109 OBJECT_SERIALIZE_FIELD(json, "duration", duration);
110 OBJECT_SERIALIZE_FIELD(json, "has_spoiler", hasSpoiler);
111 return json;
112 }
113 void fromJson(const nl::json& json) override {
115 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
116 OBJECT_DESERIALIZE_FIELD(json, "width", width, 0, true);
117 OBJECT_DESERIALIZE_FIELD(json, "height", height, 0, true);
118 OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, true);
119 OBJECT_DESERIALIZE_FIELD(json, "has_spoiler", hasSpoiler, false, true);
120 }
121 };
122
123
128 InputMedia::type = "document";
129 }
130 explicit InputMediaDocument(const nl::json& json) : InputMedia(json) {
131 InputMedia::type = "document";
132 }
133
139 std::string thumbnail;
140
144
145
146 nl::json toJson() const override {
147 nl::json json = InputMedia::toJson();
148 OBJECT_SERIALIZE_FIELD(json, "thumbnail", thumbnail);
149 OBJECT_SERIALIZE_FIELD(json, "disable_content_type_detection", disableContentTypeDetection);
150 return json;
151 }
152 void fromJson(const nl::json& json) override {
154 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
155 OBJECT_DESERIALIZE_FIELD(json, "disable_content_type_detection", disableContentTypeDetection, false, true);
156 }
157 };
158
159
164 InputMedia::type = "audio";
165 }
166 explicit InputMediaAudio(const nl::json& json) : InputMedia(json) {
167 InputMedia::type = "audio";
168 }
169
175 std::string thumbnail;
176
178 std::int32_t duration{};
179
181 std::string performer;
182
184 std::string title;
185
186 nl::json toJson() const override {
187 nl::json json = InputMedia::toJson();
188 OBJECT_SERIALIZE_FIELD(json, "thumbnail", thumbnail);
189 OBJECT_SERIALIZE_FIELD(json, "duration", duration);
190 OBJECT_SERIALIZE_FIELD(json, "performer", performer);
191 OBJECT_SERIALIZE_FIELD(json, "title", title);
192 return json;
193 }
194 void fromJson(const nl::json& json) override {
196 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
197 OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, true);
198 OBJECT_DESERIALIZE_FIELD(json, "performer", performer, "", true);
199 OBJECT_DESERIALIZE_FIELD(json, "title", title, "", true);
200 }
201 };
202
203
208 InputMedia::type = "photo";
209 }
210 explicit InputMediaPhoto(const nl::json& json) : InputMedia(json) {
211 InputMedia::type = "photo";
212 }
213
216
217 nl::json toJson() const override {
218 nl::json json = InputMedia::toJson();
219 OBJECT_SERIALIZE_FIELD(json, "has_spoiler", hasSpoiler);
220 return json;
221 }
222 void fromJson(const nl::json& json) override {
224 OBJECT_DESERIALIZE_FIELD(json, "has_spoiler", hasSpoiler, false, true);
225 }
226 };
227
228
233 InputMedia::type = "video";
234 }
235 explicit InputMediaVideo(const nl::json& json) : InputMedia(json) {
236 InputMedia::type = "video";
237 }
238
244 std::string thumbnail;
245
247 std::int32_t width{};
248
250 std::int32_t height{};
251
253 std::int32_t duration{};
254
257
260
261
262 nl::json toJson() const override {
263 nl::json json = InputMedia::toJson();
264 OBJECT_SERIALIZE_FIELD(json, "thumbnail", thumbnail);
265 OBJECT_SERIALIZE_FIELD(json, "width", width);
266 OBJECT_SERIALIZE_FIELD(json, "height", height);
267 OBJECT_SERIALIZE_FIELD(json, "duration", duration);
268 OBJECT_SERIALIZE_FIELD(json, "supports_streaming", supportsStreaming);
269 OBJECT_SERIALIZE_FIELD(json, "has_spoiler", hasSpoiler);
270 return json;
271 }
272 void fromJson(const nl::json& json) override {
274 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
275 OBJECT_DESERIALIZE_FIELD(json, "width", width, 0, true);
276 OBJECT_DESERIALIZE_FIELD(json, "height", height, 0, true);
277 OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, true);
278 OBJECT_DESERIALIZE_FIELD(json, "supports_streaming", supportsStreaming, false, true);
279 OBJECT_DESERIALIZE_FIELD(json, "has_spoiler", hasSpoiler, false, true);
280 }
281 };
282
283}
#define OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field)
Definition Object.hpp:27
#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:44
#define OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field, optional)
Definition Object.hpp:87
Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent....
std::string thumbnail
Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supporte...
nl::json toJson() const override
Serializes this object to JSON.
InputMediaAnimation(const nl::json &json)
std::int32_t duration
Optional. Animation duration in seconds.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
std::int32_t width
Optional. Animation width.
std::int32_t height
Optional. Animation height.
bool hasSpoiler
Optional. Pass True if the animation needs to be covered with a spoiler animation.
Represents an audio file to be treated as music to be sent. https://core.telegram....
std::string performer
Optional. Performer of the audio.
std::string title
Optional. Title of the audio.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
std::int32_t duration
Optional. Duration of the audio in seconds.
nl::json toJson() const override
Serializes this object to JSON.
std::string thumbnail
Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supporte...
InputMediaAudio(const nl::json &json)
Represents a general file to be sent. https://core.telegram.org/bots/api#inputmediadocument.
nl::json toJson() const override
Serializes this object to JSON.
std::string thumbnail
Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supporte...
InputMediaDocument(const nl::json &json)
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
bool disableContentTypeDetection
Optional. Disables automatic server-side content type detection for files uploaded using multipart/fo...
This object represents the content of a media message to be sent. It should be one of:
InputMedia(const nl::json &json)
std::string parseMode
Optional. Mode for parsing entities in the media caption. See https://core.telegram....
virtual void fromJson(const nl::json &json)
Deserializes this object from JSON.
std::vector< Ptr< MessageEntity > > captionEntities
Optional. List of special entities that appear in the caption, which can be specified instead of pars...
std::variant< cpr::File, std::string > media
File to send.
virtual nl::json toJson() const
Serializes this object to JSON.
std::string type
Type of the result.
std::string caption
Optional. Caption of the media to be sent, 0-1024 characters after entities parsing.
Represents a photo to be sent. https://core.telegram.org/bots/api#inputmediaphoto.
bool hasSpoiler
Optional. Pass True if the photo needs to be covered with a spoiler animation.
nl::json toJson() const override
Serializes this object to JSON.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
InputMediaPhoto(const nl::json &json)
Represents a video to be sent. https://core.telegram.org/bots/api#inputmediavideo.
bool hasSpoiler
Optional. Pass True if the animation needs to be covered with a spoiler animation.
std::int32_t duration
Optional. Video duration in seconds.
std::string thumbnail
Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supporte...
InputMediaVideo(const nl::json &json)
nl::json toJson() const override
Serializes this object to JSON.
std::int32_t width
Optional. Video width.
bool supportsStreaming
Optional. Pass True if the uploaded video is suitable for streaming.
std::int32_t height
Optional. Video height.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.