tgbotxx 1.2.9.2
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) {
17 }
18 virtual ~InputMedia() = default;
19
21 std::string type;
22
29 std::variant<std::monostate, cpr::File, std::string> media{};
30
32 std::string caption;
33
36 std::string parseMode;
37
39 std::vector<Ptr<MessageEntity>> captionEntities;
40
41
44 [[nodiscard]] virtual nl::json toJson() const {
45 nl::json json = nl::json::object();
47 if (not std::holds_alternative<std::monostate>(media)) {
48 // media variant
49 if (std::holds_alternative<cpr::File>(media))
50 json["media"] = std::get<cpr::File>(media).filepath;
51 else
52 json["media"] = std::get<std::string>(media);
53 }
57 return json;
58 }
59
61 virtual void fromJson(const nl::json& json) {
62 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
63 // media variant, we can't get a local file from remote, so it's always a URL or file id std::string.
64 OBJECT_DESERIALIZE_FIELD(json, "media", std::get<std::string>(media), "", false);
65 OBJECT_DESERIALIZE_FIELD(json, "caption", caption, "", true);
66 OBJECT_DESERIALIZE_FIELD(json, "parse_mode", parseMode, "", true);
68 }
69 };
70
75 type = "animation";
76 }
77 explicit InputMediaAnimation(const nl::json& json) {
79 }
80
86 std::string thumbnail;
87
89 std::int32_t width{};
90
92 std::int32_t height{};
93
95 std::int32_t duration{};
96
98 bool hasSpoiler{};
99
100
101 [[nodiscard]] nl::json toJson() const override {
102 nl::json json = InputMedia::toJson();
107 OBJECT_SERIALIZE_FIELD(json, "has_spoiler", hasSpoiler);
108 return json;
109 }
110 void fromJson(const nl::json& json) override {
112 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
113 OBJECT_DESERIALIZE_FIELD(json, "width", width, 0, true);
114 OBJECT_DESERIALIZE_FIELD(json, "height", height, 0, true);
115 OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, true);
116 OBJECT_DESERIALIZE_FIELD(json, "has_spoiler", hasSpoiler, false, true);
117 }
118 };
119
120
125 type = "document";
126 }
127 explicit InputMediaDocument(const nl::json& json) {
129 }
130
136 std::string thumbnail;
137
141
142
143 [[nodiscard]] nl::json toJson() const override {
144 nl::json json = InputMedia::toJson();
146 OBJECT_SERIALIZE_FIELD(json, "disable_content_type_detection", disableContentTypeDetection);
147 return json;
148 }
149 void fromJson(const nl::json& json) override {
151 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
152 OBJECT_DESERIALIZE_FIELD(json, "disable_content_type_detection", disableContentTypeDetection, false, true);
153 }
154 };
155
156
161 type = "audio";
162 }
163 explicit InputMediaAudio(const nl::json& json) {
165 }
166
172 std::string thumbnail;
173
175 std::int32_t duration{};
176
178 std::string performer;
179
181 std::string title;
182
183 [[nodiscard]] nl::json toJson() const override {
184 nl::json json = InputMedia::toJson();
189 return json;
190 }
191 void fromJson(const nl::json& json) override {
193 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
194 OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, true);
195 OBJECT_DESERIALIZE_FIELD(json, "performer", performer, "", true);
196 OBJECT_DESERIALIZE_FIELD(json, "title", title, "", true);
197 }
198 };
199
200
205 type = "photo";
206 }
207 explicit InputMediaPhoto(const nl::json& json) {
209 }
210
213
214 [[nodiscard]] nl::json toJson() const override {
215 nl::json json = InputMedia::toJson();
216 OBJECT_SERIALIZE_FIELD(json, "has_spoiler", hasSpoiler);
217 return json;
218 }
219 void fromJson(const nl::json& json) override {
221 OBJECT_DESERIALIZE_FIELD(json, "has_spoiler", hasSpoiler, false, true);
222 }
223 };
224
225
230 type = "video";
231 }
232 explicit InputMediaVideo(const nl::json& json) {
234 }
235
241 std::string thumbnail;
242
244 std::int32_t width{};
245
247 std::int32_t height{};
248
250 std::int32_t duration{};
251
254
257
258
259 [[nodiscard]] nl::json toJson() const override {
260 nl::json json = InputMedia::toJson();
265 OBJECT_SERIALIZE_FIELD(json, "supports_streaming", supportsStreaming);
266 OBJECT_SERIALIZE_FIELD(json, "has_spoiler", hasSpoiler);
267 return json;
268 }
269 void fromJson(const nl::json& json) override {
271 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
272 OBJECT_DESERIALIZE_FIELD(json, "width", width, 0, true);
273 OBJECT_DESERIALIZE_FIELD(json, "height", height, 0, true);
274 OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, true);
275 OBJECT_DESERIALIZE_FIELD(json, "supports_streaming", supportsStreaming, false, true);
276 OBJECT_DESERIALIZE_FIELD(json, "has_spoiler", hasSpoiler, false, true);
277 }
278 };
279
280}
#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:46
#define OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field, optional)
Definition Object.hpp:89
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
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...
virtual ~InputMedia()=default
std::variant< std::monostate, 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.