diff options
-rw-r--r-- | include/tgbot/TgTypeParser.h | 4 | ||||
-rw-r--r-- | include/tgbot/types/Voice.h | 6 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 26 |
3 files changed, 33 insertions, 3 deletions
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 06e7890..dbfa27e 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -38,6 +38,7 @@ #include "tgbot/types/StickerSet.h" #include "tgbot/types/MaskPosition.h" #include "tgbot/types/Video.h" +#include "tgbot/types/Voice.h" #include "tgbot/types/VideoNote.h" #include "tgbot/types/Contact.h" #include "tgbot/types/Location.h" @@ -147,6 +148,9 @@ public: Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const; std::string parseVideo(const Video::Ptr& object) const; + Voice::Ptr parseJsonAndGetVoice(const boost::property_tree::ptree& data) const; + std::string parseVoice(const Voice::Ptr& object) const; + VideoNote::Ptr parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const; std::string parseVideoNote(const VideoNote::Ptr& object) const; diff --git a/include/tgbot/types/Voice.h b/include/tgbot/types/Voice.h index 0957349..d1e1198 100644 --- a/include/tgbot/types/Voice.h +++ b/include/tgbot/types/Voice.h @@ -22,7 +22,7 @@ public: /** * @brief Unique identifier for this file. */ - std::string file_id; + std::string fileId; /** * @brief Duration of the audio in seconds as defined by sender. @@ -32,12 +32,12 @@ public: /** * @brief Optional. MIME type of the file as defined by sender; */ - std::string mime_type; + std::string mimeType; /** * @brief Optional. File size. */ - int32_t file_size; + int32_t fileSize; }; } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 6a0cef9..4e31c94 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -158,6 +158,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo"); result->sticker = tryParseJson<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "sticker"); result->video = tryParseJson<Video>(&TgTypeParser::parseJsonAndGetVideo, data, "video"); + result->voice = tryParseJson<Voice>(&TgTypeParser::parseJsonAndGetVoice, data, "voice"); result->contact = tryParseJson<Contact>(&TgTypeParser::parseJsonAndGetContact, data, "contact"); result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); result->newChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_participant"); @@ -204,6 +205,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo)); appendToJson(result, "sticker", parseSticker(object->sticker)); appendToJson(result, "video", parseVideo(object->video)); + appendToJson(result, "voice", parseVoice(object->voice)); appendToJson(result, "contact", parseContact(object->contact)); appendToJson(result, "location", parseLocation(object->location)); appendToJson(result, "new_chat_member", parseUser(object->newChatMember)); @@ -413,6 +415,30 @@ string TgTypeParser::parseVideo(const Video::Ptr& object) const { return result; } +Voice::Ptr TgTypeParser::parseJsonAndGetVoice(const ptree& data) const { + auto result(make_shared<Voice>()); + result->fileId = data.get<string>("file_id"); + result->duration = data.get<int32_t>("duration"); + result->mimeType = data.get("mime_type", ""); + result->fileSize = data.get("file_size", 0); + return result; +} + +string TgTypeParser::parseVoice(const Voice::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "file_id", object->fileId); + appendToJson(result, "duration", object->duration); + appendToJson(result, "mime_type", object->mimeType); + appendToJson(result, "file_size", object->fileSize); + removeLastComma(result); + result += '}'; + return result; +} + VideoNote::Ptr TgTypeParser::parseJsonAndGetVideoNote(const ptree& data) const { auto result(make_shared<VideoNote>()); result->fileId = data.get<string>("file_id"); |