tgbotxx  1.1.6.9
Telegram Bot C++ Library
Voice.hpp
Go to the documentation of this file.
1 #pragma once
3 
4 namespace tgbotxx {
7  struct Voice {
8  Voice() = default;
9  explicit Voice(const nl::json& json) {
10  fromJson(json);
11  }
12 
14  std::string fileId;
15 
18  std::string fileUniqueId;
19 
21  std::int32_t duration{};
22 
24  std::string mimeType;
25 
29  std::int64_t fileSize{};
30 
33  nl::json toJson() const {
34  nl::json json = nl::json::object();
35  OBJECT_SERIALIZE_FIELD(json, "file_id", fileId);
36  OBJECT_SERIALIZE_FIELD(json, "file_unique_id", fileUniqueId);
37  OBJECT_SERIALIZE_FIELD(json, "duration", duration);
38  OBJECT_SERIALIZE_FIELD(json, "mime_type", mimeType);
39  OBJECT_SERIALIZE_FIELD(json, "file_size", fileSize);
40  return json;
41  }
42 
44  void fromJson(const nl::json& json) {
45  OBJECT_DESERIALIZE_FIELD(json, "file_id", fileId, "", false);
46  OBJECT_DESERIALIZE_FIELD(json, "file_unique_id", fileUniqueId, "", false);
47  OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, false);
48  OBJECT_DESERIALIZE_FIELD(json, "mime_type", mimeType, "", true);
49  OBJECT_DESERIALIZE_FIELD(json, "file_size", fileSize, 0, true);
50  }
51  };
52 }
#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
Definition: Api.hpp:14
This object represents a voice note. https://core.telegram.org/bots/api#voice.
Definition: Voice.hpp:7
std::int64_t fileSize
Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have diff...
Definition: Voice.hpp:29
std::string fileUniqueId
Unique identifier for this file, which is supposed to be the same over time and for different bots....
Definition: Voice.hpp:18
std::string mimeType
Optional. MIME type of the file as defined by sender.
Definition: Voice.hpp:24
std::string fileId
Identifier for this file, which can be used to download or reuse the file.
Definition: Voice.hpp:14
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: Voice.hpp:44
Voice()=default
std::int32_t duration
Duration of the audio in seconds as defined by sender.
Definition: Voice.hpp:21
nl::json toJson() const
Serializes this object to JSON.
Definition: Voice.hpp:33
Voice(const nl::json &json)
Definition: Voice.hpp:9