summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJellyBrick <shlee1503@naver.com>2018-07-27 17:40:44 +0900
committerJellyBrick <shlee1503@naver.com>2018-07-27 17:40:44 +0900
commit941c97706cb5b81d5a2e44a827e8f6bf76a2c6bd (patch)
treeba87716d560a674d338c5d43f319b749ff4f46c4
parent6c2dc4d2eb84e7ba98f73332ccf95ffa5a7adf3f (diff)
Bot API 4.0 - Part 2
-rw-r--r--include/tgbot/Api.h18
-rw-r--r--include/tgbot/types/InputMedia.h34
-rw-r--r--include/tgbot/types/InputMediaAnimation.h49
-rw-r--r--include/tgbot/types/InputMediaAudio.h49
-rw-r--r--include/tgbot/types/InputMediaDocument.h49
-rw-r--r--include/tgbot/types/InputVenueMessageContent.h5
-rw-r--r--src/Api.cpp28
-rw-r--r--src/TgTypeParser.cpp54
-rw-r--r--src/net/HttpParser.cpp2
9 files changed, 275 insertions, 13 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 2af7be2..480949e 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -682,6 +682,24 @@ public:
const std::string& inlineMessageId = "", GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const;
/**
+ * @brief Use this method to edit audio, document, photo, or video messages.
+ *
+ *
+ * If a message is a part of a message album, then it can be edited only to a photo or a video.
+ * Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded.
+ * Use previously uploaded file via its file_id or specify a URL.
+ *
+ * @param media A JSON-serialized object for a new media content of the message.
+ * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel.
+ * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message
+ * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message
+ * @param replyMarkup Optional A JSON-serialized object for an inline keyboard.
+ * @return On success, if the edited message was sent by the bot, the edited Message is returned, otherwise nullptr is returned.
+ */
+ Message::Ptr editMessageMedia(InputMedia::Ptr media, int64_t chatId = 0, int32_t messageId = 0, const std::string& inlineMessageId = "",
+ GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const;
+
+ /**
* @brief Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
* @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel.
* @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message
diff --git a/include/tgbot/types/InputMedia.h b/include/tgbot/types/InputMedia.h
index a4610ad..c8cd4ae 100644
--- a/include/tgbot/types/InputMedia.h
+++ b/include/tgbot/types/InputMedia.h
@@ -28,6 +28,8 @@
#include <memory>
#include <string>
+#include <boost/variant.hpp>
+
namespace TgBot {
/**
@@ -41,11 +43,14 @@ public:
enum class TYPE : uint8_t {
PHOTO,
- VIDEO
+ VIDEO,
+ ANIMATION,
+ DOCUMENT,
+ AUDIO
};
/**
- * @brief Type of the result, It should be one of TYPE::PHOTO/TYPE::VIDEO
+ * @brief Type of the result, It should be one of TYPE::*
*/
TYPE type;
@@ -55,7 +60,14 @@ public:
std::string media;
/**
- * @brief Optional. Caption of the photo to be sent, 0-200 characters
+ * @brief Optional. Thumbnail of the file sent.
+ *
+ * The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
+ */
+ std::string thumb;
+
+ /**
+ * @brief Optional. Caption of the media to be sent, 0-200 characters
*/
std::string caption;
@@ -65,21 +77,31 @@ public:
std::string parseMode;
/**
- * @brief Optional. Video width
+ * @brief Optional. Media width
*/
int32_t width = 0;
/**
- * @brief Optional. Video height
+ * @brief Optional. Media height
*/
int32_t height = 0;
/**
- * @brief Optional. Video duration
+ * @brief Optional. Media duration
*/
int32_t duration = 0;
/**
+ * @brief Optional. Performer of the audio.
+ */
+ int32_t performer = 0;
+
+ /**
+ * @brief Optional. Title of the audio.
+ */
+ int32_t title = 0;
+
+ /**
* @brief Optional. Pass True, if the uploaded video is suitable for streaming
*/
bool supportsStreaming = false;
diff --git a/include/tgbot/types/InputMediaAnimation.h b/include/tgbot/types/InputMediaAnimation.h
new file mode 100644
index 0000000..8b3b976
--- /dev/null
+++ b/include/tgbot/types/InputMediaAnimation.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * Copyright (c) 2016 Konstantin Kukin
+ * Copyright (c) 2018 JellyBrick
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_INPUTMEDIAANIMATION_H
+#define TGBOT_INPUTMEDIAANIMATION_H
+
+#include <memory>
+#include <string>
+
+#include "tgbot/types/InputMedia.h"
+
+namespace TgBot {
+
+/**
+ * @brief Represents a video to be sent.
+ * @ingroup types
+ */
+class InputMediaAnimation : public InputMedia {
+public:
+ typedef std::shared_ptr<InputMediaAnimation> Ptr;
+
+ InputMediaAnimation() {
+ this->type = TYPE::ANIMATION;
+ }
+};
+}
+
+#endif //TGBOT_INPUTMEDIAANIMATION_H
diff --git a/include/tgbot/types/InputMediaAudio.h b/include/tgbot/types/InputMediaAudio.h
new file mode 100644
index 0000000..08b21ab
--- /dev/null
+++ b/include/tgbot/types/InputMediaAudio.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * Copyright (c) 2016 Konstantin Kukin
+ * Copyright (c) 2018 JellyBrick
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_INPUTMEDIAAUDIO_H
+#define TGBOT_INPUTMEDIAAUDIO_H
+
+#include <memory>
+#include <string>
+
+#include "tgbot/types/InputMedia.h"
+
+namespace TgBot {
+
+/**
+ * @brief Represents a video to be sent.
+ * @ingroup types
+ */
+class InputMediaAudio : public InputMedia {
+public:
+ typedef std::shared_ptr<InputMediaAudio> Ptr;
+
+ InputMediaAudio() {
+ this->type = TYPE::AUDIO;
+ }
+};
+}
+
+#endif //TGBOT_INPUTMEDIAAUDIO_H
diff --git a/include/tgbot/types/InputMediaDocument.h b/include/tgbot/types/InputMediaDocument.h
new file mode 100644
index 0000000..a00eabb
--- /dev/null
+++ b/include/tgbot/types/InputMediaDocument.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * Copyright (c) 2016 Konstantin Kukin
+ * Copyright (c) 2018 JellyBrick
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_INPUTMEDIADOCUMENT_H
+#define TGBOT_INPUTMEDIADOCUMENT_H
+
+#include <memory>
+#include <string>
+
+#include "tgbot/types/InputMedia.h"
+
+namespace TgBot {
+
+/**
+ * @brief Represents a video to be sent.
+ * @ingroup types
+ */
+class InputMediaDocument : public InputMedia {
+public:
+ typedef std::shared_ptr<InputMediaDocument> Ptr;
+
+ InputMediaDocument() {
+ this->type = TYPE::DOCUMENT;
+ }
+};
+}
+
+#endif //TGBOT_INPUTMEDIADOCUMENT_H
diff --git a/include/tgbot/types/InputVenueMessageContent.h b/include/tgbot/types/InputVenueMessageContent.h
index 254a0a0..1f0bea7 100644
--- a/include/tgbot/types/InputVenueMessageContent.h
+++ b/include/tgbot/types/InputVenueMessageContent.h
@@ -48,6 +48,11 @@ public:
* @brief Optional. Foursquare identifier of the venue, if known
*/
std::string foursquareId;
+
+ /**
+ * @brief Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
+ */
+ std::string foursquareType;
/**
* @brief Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
diff --git a/src/Api.cpp b/src/Api.cpp
index 85ba050..bd141d7 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -753,7 +753,7 @@ bool Api::deleteChatStickerSet(int64_t chatId) const {
return sendRequest("deleteChatStickerSet", args).get<bool>("", false);
}
-Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
+Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, const string& foursquareType, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
args.reserve(10);
args.emplace_back("chat_id", chatId);
@@ -962,6 +962,32 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons
}
}
+Message::Ptr Message::Ptr editMessageMedia(InputMedia::Ptr media, int64_t chatId, int32_t messageId, const std::string& inlineMessageId,
+ GenericReply::Ptr replyMarkup) const {
+
+ vector<HttpReqArg> args;
+ args.reserve(5);
+ args.emplace_back("media", _tgTypeParser.parseInputMedia(media));
+ if (chatId) {
+ args.emplace_back("chat_id", chatId);
+ }
+ if (messageId) {
+ args.emplace_back("message_id", messageId);
+ }
+ if (!inlineMessageId.empty()) {
+ args.emplace_back("inline_message_id", inlineMessageId);
+ }
+ if (replyMarkup) {
+ args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
+ }
+ ptree p = sendRequest("editMessageCaption", args);
+ if (p.get_child_optional("message_id")) {
+ return _tgTypeParser.parseJsonAndGetMessage(p);
+ } else {
+ return nullptr;
+ }
+}
+
ChatMember::Ptr Api::getChatMember(int64_t chatId, int32_t userId) const {
vector<HttpReqArg> args;
args.reserve(2);
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 5a01aa6..1bbc38e 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -624,6 +624,7 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const
result->media = data.get("media", "");
result->caption = data.get("caption", "");
result->parseMode = data.get("parse_mode", "");
+ result->thumb = data.get("thumb", "");
return result;
}
else if (type == "video") {
@@ -631,12 +632,40 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const
result->media = data.get("media", "");
result->caption = data.get("caption", "");
result->parseMode = data.get("parse_mode", "");
+ result->thumb = data.get("thumb", "");
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 if (type == "animation") {
+ auto result(make_shared<InputMediaAnimation>());
+ result->media = data.get("media", "");
+ result->caption = data.get("caption", "");
+ result->parseMode = data.get("parse_mode", "");
+ result->thumb = data.get("thumb", "");
+ result->width = data.get<int32_t>("width", 0);
+ result->height = data.get<int32_t>("height", 0);
+ result->duration = data.get<int32_t>("duration", 0);
+ return result;
+ } else if (type == "document") {
+ auto result(make_shared<InputMediaDocument>());
+ result->media = data.get("media", "");
+ result->caption = data.get("caption", "");
+ result->parseMode = data.get("parse_mode", "");
+ result->thumb = data.get("thumb", "");
+ return result;
+ } else if (type == "audio") {
+ auto result(make_shared<InputMediaAudio>());
+ result->media = data.get("media", "");
+ result->caption = data.get("caption", "");
+ result->parseMode = data.get("parse_mode", "");
+ result->thumb = data.get("thumb", "");
+ result->duration = data.get<int32_t>("duration", 0);
+ result->title = data.get<int32_t>("title", 0);
+ result->performer = data.get<int32_t>("performer", 0);
+ }
else {
return nullptr;
}
@@ -648,15 +677,27 @@ string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const {
}
string result;
result += '{';
- if (object->type == InputMedia::TYPE::PHOTO) {
- appendToJson(result, "type", "photo");
- }
- else {
- appendToJson(result, "type", "video");
+ switch(object->type) {
+ case InputMedia::TYPE::PHOTO:
+ appendToJson(result, "type", "photo");
+ break;
+ case InputMedia::TYPE::VIDEO:
+ appendToJson(result, "type", "video");
+ break;
+ case InputMedia::TYPE::ANIMATION:
+ appendToJson(result, "type", "animation");
+ break;
+ case InputMedia::TYPE::DOCUMENT:
+ appendToJson(result, "type", "document");
+ break;
+ case InputMedia::TYPE::AUDIO:
+ appendToJson(result, "type", "audio");
+ break;
}
appendToJson(result, "media", object->media);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
+ args.emplace_back("thumb", boost::get<std::string>(object->thumb));
if (object->width) {
appendToJson(result, "width", object->width);
}
@@ -666,6 +707,9 @@ string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const {
if (object->duration) {
appendToJson(result, "duration", object->duration);
}
+ if (object->performer) {
+ appendToJson(result, "performer", object->performer);
+ }
if (object->supportsStreaming) {
appendToJson(result, "supports_streaming", object->supportsStreaming);
}
diff --git a/src/net/HttpParser.cpp b/src/net/HttpParser.cpp
index 41dec14..c4f8215 100644
--- a/src/net/HttpParser.cpp
+++ b/src/net/HttpParser.cpp
@@ -100,7 +100,7 @@ string HttpParser::generateMultipartFormData(const vector<HttpReqArg>& args, con
string HttpParser::generateMultipartBoundary(const vector<HttpReqArg>& args) const {
string result;
- srand((unsigned int) time(nullptr));
+ srand((uint32_t) time(nullptr));
for (const HttpReqArg& item : args) {
if (item.isFile) {
while (result.empty() || item.value.find(result) != string::npos) {