tgbotxx 1.2.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) {
14 }
15 virtual ~InputPaidMedia() = default;
16
18 std::string type;
19
26 std::variant<std::monostate, cpr::File, std::string> media{};
27
29 [[nodiscard]] virtual nl::json toJson() const {
30 nl::json json = nl::json::object();
32 if (not std::holds_alternative<std::monostate>(media)) {
33 // media variant
34 if (std::holds_alternative<cpr::File>(media))
35 json["media"] = std::get<cpr::File>(media).filepath;
36 else
37 json["media"] = std::get<std::string>(media);
38 }
39 return json;
40 }
41
43 virtual void fromJson(const nl::json& json) {
44 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
45 // media variant, we can't get a local file from remote, so it's always a URL or file id std::string.
46 OBJECT_DESERIALIZE_FIELD(json, "media", std::get<std::string>(media), "", false);
47 }
48 };
49
53 type = "photo";
54 }
55 explicit InputPaidMediaPhoto(const nl::json& json) {
57 }
58
59 [[nodiscard]] nl::json toJson() const override {
60 nl::json json = InputPaidMedia::toJson();
61 return json;
62 }
63
64 void fromJson(const nl::json& json) override {
66 }
67 };
68
72 type = "video";
73 }
74 explicit InputPaidMediaVideo(const nl::json& json) {
76 }
77
79 std::string thumbnail;
80
82 std::string cover;
83
85 std::time_t startTimestamp{};
86
88 std::int32_t width{};
89
91 std::int32_t height{};
92
94 std::time_t duration{};
95
98
99 [[nodiscard]] nl::json toJson() const override {
100 nl::json json = InputPaidMedia::toJson();
103 OBJECT_SERIALIZE_FIELD(json, "start_timestamp", startTimestamp);
107 OBJECT_SERIALIZE_FIELD(json, "supports_streaming", supportsStreaming);
108 return json;
109 }
110
111 void fromJson(const nl::json& json) override {
113 OBJECT_DESERIALIZE_FIELD(json, "thumbnail", thumbnail, "", true);
114 OBJECT_DESERIALIZE_FIELD(json, "cover", cover, "", true);
115 OBJECT_DESERIALIZE_FIELD(json, "start_timestamp", startTimestamp, 0, 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, "supports_streaming", supportsStreaming, false, true);
120 }
121 };
122
123}
#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
Base class describing paid media to send https://core.telegram.org/bots/api#inputpaidmedia.
InputPaidMedia(const nl::json &json)
std::string type
Type of the media.
virtual nl::json toJson() const
Serializes this object to JSON.
std::variant< std::monostate, cpr::File, std::string > media
File to send.
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.