tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
InputPaidMedia.hpp
Go to the documentation of this file.
1#pragma once
3#include <variant>
4#include <cpr/file.h>
5
6namespace tgbotxx {
7
11 InputPaidMedia() = default;
12 explicit InputPaidMedia(const nl::json& json) {
13 _fromJson(json);
14 }
15 virtual ~InputPaidMedia() = default;
16
18 std::string type;
19
26 std::variant<cpr::File, std::string> media{""};
27
29 virtual nl::json toJson() const {
30 nl::json json = nl::json::object();
31 OBJECT_SERIALIZE_FIELD(json, "type", type);
32 // media variant
33 if (auto idx = media.index(); idx == 0)
34 json["media"] = std::get<cpr::File>(media).filepath;
35 else if (idx == 1)
36 json["media"] = std::get<std::string>(media);
37 return json;
38 }
39
41 virtual void fromJson(const nl::json& json) {
42 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
43 // media variant, we can't get a local file from remote, so it's always a URL or file id std::string.
44 OBJECT_DESERIALIZE_FIELD(json, "media", std::get<std::string>(media), "", false);
45 }
46
47 private:
49 void _fromJson(const nl::json& json) {
50 fromJson(json);
51 }
52 };
53
59 explicit InputPaidMediaPhoto(const nl::json& json) : InputPaidMedia(json) {
60 InputPaidMedia::type = "photo";
61 }
62
63
64 nl::json toJson() const override {
65 nl::json json = InputPaidMedia::toJson();
66 return json;
67 }
68
69 void fromJson(const nl::json& json) override {
71 }
72 };
73
79 explicit InputPaidMediaVideo(const nl::json& json) : InputPaidMedia(json) {
80 InputPaidMedia::type = "video";
81 }
82
84 std::string thumbnail;
85
87 std::string cover;
88
90 std::time_t startTimestamp{};
91
93 std::int32_t width{};
94
96 std::int32_t height{};
97
99 std::time_t duration{};
100
103
104 nl::json toJson() const override {
105 nl::json json = InputPaidMedia::toJson();
106 OBJECT_SERIALIZE_FIELD(json, "thumbnail", thumbnail);
107 OBJECT_SERIALIZE_FIELD(json, "cover", cover);
108 OBJECT_SERIALIZE_FIELD(json, "start_timestamp", startTimestamp);
109 OBJECT_SERIALIZE_FIELD(json, "width", width);
110 OBJECT_SERIALIZE_FIELD(json, "height", height);
111 OBJECT_SERIALIZE_FIELD(json, "duration", duration);
112 OBJECT_SERIALIZE_FIELD(json, "supports_streaming", supportsStreaming);
113 return json;
114 }
115
116 void fromJson(const nl::json& json) override {
118 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
119 OBJECT_DESERIALIZE_FIELD(json, "cover", cover, "", true);
120 OBJECT_DESERIALIZE_FIELD(json, "start_timestamp", startTimestamp, 0, true);
121 OBJECT_DESERIALIZE_FIELD(json, "width", width, 0, true);
122 OBJECT_DESERIALIZE_FIELD(json, "height", height, 0, true);
123 OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, true);
124 OBJECT_DESERIALIZE_FIELD(json, "supports_streaming", supportsStreaming, false, true);
125 }
126 };
127
128}
#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
Base class describing paid media to send https://core.telegram.org/bots/api#inputpaidmedia.
InputPaidMedia(const nl::json &json)
std::variant< cpr::File, std::string > media
File to send.
std::string type
Type of the media.
virtual nl::json toJson() const
Serializes this object to JSON.
virtual ~InputPaidMedia()=default
virtual void fromJson(const nl::json &json)
Deserializes this object from JSON.
The paid media to send is a photo.
nl::json toJson() const override
Serializes this object to JSON.
InputPaidMediaPhoto(const nl::json &json)
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
The paid media to send is a video.
std::time_t duration
Optional. Video duration in seconds.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
std::int32_t width
Optional. Video width.
InputPaidMediaVideo(const nl::json &json)
std::string thumbnail
Optional. Thumbnail of the file sent.
std::int32_t height
Optional. Video height.
std::string cover
Optional. Cover for the video in the message.
bool supportsStreaming
Optional. True if the uploaded video is suitable for streaming.
std::time_t startTimestamp
Optional. Start timestamp for the video.
nl::json toJson() const override
Serializes this object to JSON.