tgbotxx 1.1.6.9
Telegram Bot C++ Library
Loading...
Searching...
No Matches
File.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace tgbotxx {
13 struct File {
14 File() = default;
15 explicit File(const nl::json& json) {
16 fromJson(json);
17 }
18
20 std::string fileId;
21
24 std::string fileUniqueId;
25
29 std::int64_t fileSize{};
30
32 std::string filePath;
33
36 nl::json toJson() const {
37 nl::json json = nl::json::object();
38 OBJECT_SERIALIZE_FIELD(json, "file_id", fileId);
39 OBJECT_SERIALIZE_FIELD(json, "file_unique_id", fileUniqueId);
40 OBJECT_SERIALIZE_FIELD(json, "file_size", fileSize);
41 OBJECT_SERIALIZE_FIELD(json, "file_path", filePath);
42 return json;
43 }
44
46 void fromJson(const nl::json& json) {
47 OBJECT_DESERIALIZE_FIELD(json, "file_id", fileId, "", false);
48 OBJECT_DESERIALIZE_FIELD(json, "file_unique_id", fileUniqueId, "", false);
49 OBJECT_DESERIALIZE_FIELD(json, "file_size", fileSize, 0, true);
50 OBJECT_DESERIALIZE_FIELD(json, "file_path", filePath, "", true);
51 }
52 };
53}
#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
This object represents a file ready to be downloaded.
Definition File.hpp:13
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition File.hpp:46
std::string filePath
Optional. File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file.
Definition File.hpp:32
std::string fileId
Identifier for this file, which can be used to download or reuse the file.
Definition File.hpp:20
nl::json toJson() const
Serializes this object to JSON.
Definition File.hpp:36
std::int64_t fileSize
Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have diff...
Definition File.hpp:29
File(const nl::json &json)
Definition File.hpp:15
File()=default
std::string fileUniqueId
Unique identifier for this file, which is supposed to be the same over time and for different bots....
Definition File.hpp:24