summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJellyBrick <shlee1503@naver.com>2018-05-28 03:45:31 +0900
committerJellyBrick <shlee1503@naver.com>2018-05-28 03:45:31 +0900
commit981737b20b0db4914c667195b6584d14e9473e3d (patch)
treeb2a3aa0642c8360e0385c69717eb8f2cb86fbf24 /src
parentb0134ff90ccd4203721fd8d32c1d1bacaea8b47f (diff)
Bot API 3.5 update
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp14
-rw-r--r--src/TgTypeParser.cpp61
2 files changed, 73 insertions, 2 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index cb33058..ca2f969 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -407,6 +407,16 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const string &videoNote, int64_t
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args));
}
+vector<Message::Ptr> Api::sendMediaGroup(int64_t chatId, const vector<InputMedia::Ptr>& media, bool disableNotification, int32_t replyToMessageId) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ string mediaJson = TgTypeParser::getInstance().parseArray<InputMedia>(&TgTypeParser::parseInputMedia, media);
+ args.push_back(HttpReqArg("media", mediaJson));
+ args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ return TgTypeParser::getInstance().parseJsonAndGetArray<Message>(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args));
+}
+
Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
@@ -490,7 +500,7 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, int64
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args));
}
-Message::Ptr Api::editMessageLiveLocation(int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
+Message::Ptr Api::stopMessageLiveLocation(int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
vector<HttpReqArg> args;
if (chatId) {
args.push_back(HttpReqArg("chat_id", chatId));
@@ -599,7 +609,7 @@ Chat::Ptr Api::getChat(int64_t chatId) const
return TgTypeParser::getInstance().parseJsonAndGetChat(sendRequest("getChat", args));
}
-std::vector<ChatMember::Ptr> Api::getChatAdministrators(int64_t chatId) const
+vector<ChatMember::Ptr> Api::getChatAdministrators(int64_t chatId) const
{
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 702bc71..fcb7e0e 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -511,6 +511,67 @@ string TgTypeParser::parseUserProfilePhotos(const UserProfilePhotos::Ptr& object
return result;
}
+InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const {
+ string type = data.get("type", "");
+ if (type == "photo") {
+ auto result(make_shared<InputMediaPhoto>());
+ result->media = data.get("media", "");
+ result->caption = data.get("caption", "");
+ result->parseMode = data.get("parse_mode", "");
+ return result;
+ }
+ else if (type == "video") {
+ auto result(make_shared<InputMediaVideo>());
+ result->media = data.get("media", "");
+ result->caption = data.get("caption", "");
+ result->parseMode = data.get("parse_mode", "");
+ result->width = data.get<int32_t>("width", 0);
+ result->height = data.get<int32_t>("height", 0);
+ result->duration = data.get<int32_t>("duration", 0);
+ result->supportsStreaming = data.get<bool>("supports_streaming", false);
+ return result;
+ }
+ else {
+ return nullptr;
+ }
+}
+
+string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ if (object->type == InputMedia::TYPE::PHOTO) {
+ appendToJson(result, "type", "photo");
+ }
+ else {
+ appendToJson(result, "type", "video");
+ }
+ appendToJson(result, "media", object->media);
+ if (object->caption) {
+ appendToJson(result, "caption", object->caption);
+ }
+ if (object->parseMode) {
+ appendToJson(result, "parse_mode", object->parseMode);
+ }
+ if (object->width) {
+ appendToJson(result, "width", object->width);
+ }
+ if (object->height) {
+ appendToJson(result, "height", object->height);
+ }
+ if (object->duration) {
+ appendToJson(result, "duration", object->duration);
+ }
+ if (object->supportsStreaming) {
+ appendToJson(result, "supports_streaming", object->supportsStreaming);
+ }
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& data) const {
auto result(make_shared<File>());
result->fileId = data.get<string>("file_id");