summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tgbot/Api.h107
-rw-r--r--include/tgbot/TgTypeParser.h9
-rw-r--r--include/tgbot/types/MaskPosition.h62
-rw-r--r--include/tgbot/types/Sticker.h11
-rw-r--r--include/tgbot/types/StickerSet.h65
-rw-r--r--src/Api.cpp130
-rw-r--r--src/TgTypeParser.cpp63
7 files changed, 406 insertions, 41 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 5750a83..dd1805d 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -39,6 +39,7 @@
#include "tgbot/types/Venue.h"
#include "tgbot/types/WebhookInfo.h"
#include "tgbot/types/ChatMember.h"
+#include "tgbot/types/StickerSet.h"
#include "tgbot/types/File.h"
namespace TgBot {
@@ -188,7 +189,7 @@ public:
/**
* Use this method to send .webp stickers.
* @param chatId Unique identifier for the target chat.
- * @param sticker Id of the sticker that is already on the Telegram servers.
+ * @param stickerId Id of the sticker that is already on the Telegram servers.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
* @param disableNotification Optional. Sends the message silenty.
@@ -198,6 +199,90 @@ public:
const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const;
/**
+ * Use this method to get a sticker set.
+ * @param chatId Name of the sticker set.
+ * @return On success, a StickerSet object is returned.
+ */
+ StickerSet::Ptr getStickerSet(const std::string& name) const;
+
+ /**
+ * Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times).
+ * @param userId User identifier of sticker file owner.
+ * @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
+ * @return Returns the uploaded File on success.
+ */
+ File::Ptr uploadStickerFile(int32_t userId, const InputFile::Ptr pngSticker) const;
+
+ /**
+ * Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set.
+ * @param userId User identifier of created sticker set owner.
+ * @param name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
+ * @param title Sticker set title, 1-64 characters.
+ * @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
+ * @param emojis One or more emoji corresponding to the sticker.
+ * @param containsMasks Optional. Pass True, if a set of mask stickers should be created.
+ * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces.
+ * @return Returns True on success.
+ */
+ bool createNewStickerSet(int32_t userId, const std::string& name, const std::string& title,
+ InputFile::Ptr pngSticker, const std::string& emojis, bool containsMasks = false, MaskPosition::Ptr maskPosition = nullptr) const;
+
+ /**
+ * Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set.
+ * @param userId User identifier of created sticker set owner.
+ * @param name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
+ * @param title Sticker set title, 1-64 characters.
+ * @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet.
+ * @param emojis One or more emoji corresponding to the sticker.
+ * @param containsMasks Optional. Pass True, if a set of mask stickers should be created.
+ * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces.
+ * @return Returns True on success.
+ */
+ bool createNewStickerSet(int32_t userId, const std::string& name, const std::string& title,
+ const std::string pngSticker, const std::string& emojis, bool containsMasks = false, MaskPosition::Ptr maskPosition = nullptr) const;
+
+ /**
+ * Use this method to add a new sticker to a set created by the bot.
+ * @param userId User identifier of created sticker set owner.
+ * @param name Sticker set name.
+ * @param title Sticker set title, 1-64 characters.
+ * @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
+ * @param emojis One or more emoji corresponding to the sticker.
+ * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces.
+ * @return Returns True on success.
+ */
+ bool addStickerToSet(int32_t userId, const std::string& name, const std::string& title,
+ InputFile::Ptr pngSticker, const std::string& emojis, MaskPosition::Ptr maskPosition = nullptr) const;
+
+ /**
+ * Use this method to add a new sticker to a set created by the bot.
+ * @param userId User identifier of created sticker set owner.
+ * @param name Sticker set name.
+ * @param title Sticker set title, 1-64 characters.
+ * @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet.
+ * @param emojis One or more emoji corresponding to the sticker.
+ * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces.
+ * @return Returns True on success.
+ */
+ bool addStickerToSet(int32_t userId, const std::string& name, const std::string& title,
+ const std::string& pngSticker, const std::string& emojis, MaskPosition::Ptr maskPosition = nullptr) const;
+
+ /**
+ * Use this method to move a sticker in a set created by the bot to a specific position.
+ * @param stickers File identifier of the sticker.
+ * @param position New sticker position in the set, zero-based.
+ * @return Returns True on success.
+ */
+ bool setStickerPositionInSet(const std::string& sticker, uint32_t position) const;
+
+ /**
+ * Use this method to delete a sticker from a set created by the bot.
+ * @param stickers File identifier of the sticker.
+ * @return Returns True on success.
+ */
+ bool deleteStickerPositionInSet(const std::string& sticker) const;
+
+ /**
* Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
* @param chatId Unique identifier for the target chat.
* @param video Video to send.
@@ -210,7 +295,7 @@ public:
* @param disableNotification Optional. Sends the message silenty.
* @return On success, the sent message is returned.
*/
- Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "",
+ Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string& caption = "",
int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const;
/**
@@ -226,7 +311,7 @@ public:
* @param disableNotification Optional. Sends the message silenty.
* @return On success, the sent message is returned.
*/
- Message::Ptr sendVideo(int64_t chatId, const std::string& videoId, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "",
+ Message::Ptr sendVideo(int64_t chatId, const std::string& videoId, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string& caption = "",
int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const;
/**
@@ -254,7 +339,7 @@ public:
* @param replyMarkup Additional interface options. A object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendVideoNote(int64_t chatId, const std::string &videoNote, int64_t replyToMessageId = 0, bool disableNotification = false,
+ Message::Ptr sendVideoNote(int64_t chatId, const std::string& videoNote, int64_t replyToMessageId = 0, bool disableNotification = false,
int32_t duration = 0, int32_t length = 0, const GenericReply::Ptr replyMarkup = GenericReply::Ptr());
@@ -269,7 +354,7 @@ public:
* @param disableNotification Optional. Sends the message silenty.
* @return On success, the sent message is returned.
*/
- Message::Ptr sendVoice(int64_t chatId, const InputFile::Ptr voice, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0,
+ Message::Ptr sendVoice(int64_t chatId, const InputFile::Ptr voice, const std::string& caption = "", int duration = 0, int32_t replyToMessageId = 0,
const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const;
/**
@@ -283,7 +368,7 @@ public:
* @param disableNotification Optional. Sends the message silenty.
* @return On success, the sent message is returned.
*/
- Message::Ptr sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0,
+ Message::Ptr sendVoice(int64_t chatId, const std::string& voiceId, const std::string& caption = "", int duration = 0, int32_t replyToMessageId = 0,
const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const;
/**
@@ -312,7 +397,7 @@ public:
* @param disableNotification Optional. Sends the message silenty.
* @return On success, the sent message is returned.
*/
- Message::Ptr sendVenue(int64_t chatId, float latitude, float longitude, std::string title, std::string address, std::string foursquareId = "",
+ Message::Ptr sendVenue(int64_t chatId, float latitude, float longitude, const std::string& title, const std::string& address, const std::string& foursquareId = "",
bool disableNotification = false, int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const;
/**
@@ -326,7 +411,7 @@ public:
* @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
* @return On success, the sent message is returned.
*/
- Message::Ptr sendContact(int64_t chatId, std::string phoneNumber, std::string firstName, std::string lastName = "", bool disableNotification = false,
+ Message::Ptr sendContact(int64_t chatId, const std::string& phoneNumber, const std::string& firstName, const std::string& lastName = "", bool disableNotification = false,
int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const;
/**
@@ -557,7 +642,7 @@ public:
* @param photo New chat photo.
* @return True on success
*/
- bool setChatPhoto(int64_t chatId, InputFile::Ptr photo) const;
+ bool setChatPhoto(int64_t chatId, const InputFile::Ptr photo) const;
/**
* Use this method to delete a chat photo.
@@ -574,7 +659,7 @@ public:
* @param title New chat title, 1-255 characters.
* @return True on success
*/
- bool setChatTitle(int64_t chatId, std::string title) const;
+ bool setChatTitle(int64_t chatId, const std::string& title) const;
/**
* Use this method to change the description of a supergroup or a channel.
@@ -582,7 +667,7 @@ public:
* @param description New chat description, 1-255 characters.
* @return True on success
*/
- bool setChatDescription(int64_t chatId, std::string description) const;
+ bool setChatDescription(int64_t chatId, const std::string& description) const;
/**
* Use this method to pin a message in a supergroup or a channel.
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index 0aea80b..b7121df 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -35,6 +35,8 @@
#include "tgbot/types/Audio.h"
#include "tgbot/types/Document.h"
#include "tgbot/types/Sticker.h"
+#include "tgbot/types/StickerSet.h"
+#include "tgbot/types/MaskPosition.h"
#include "tgbot/types/Video.h"
#include "tgbot/types/VideoNote.h"
#include "tgbot/types/Contact.h"
@@ -119,6 +121,10 @@ public:
std::string parseDocument(const Document::Ptr& object) const;
Sticker::Ptr parseJsonAndGetSticker(const boost::property_tree::ptree& data) const;
std::string parseSticker(const Sticker::Ptr& object) const;
+ StickerSet::Ptr parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const;
+ std::string parseStickerSet(const StickerSet::Ptr& object) const;
+ MaskPosition::Ptr parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const;
+ std::string parseMaskPosition(const MaskPosition::Ptr& object) const;
Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const;
std::string parseVideo(const Video::Ptr& object) const;
VideoNote::Ptr parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const;
@@ -150,7 +156,8 @@ public:
ChatMember::Ptr parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const;
std::string parseChatMember(const ChatMember::Ptr& object) const;
- ChatPhoto::Ptr parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const; // returned only in getChat
+ ChatPhoto::Ptr parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const;
+ std::string parseChatPhoto(const ChatPhoto::Ptr& object) const;
ResponseParameters::Ptr parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const;
std::string parseResponseParameters(const ResponseParameters::Ptr& object) const;
diff --git a/include/tgbot/types/MaskPosition.h b/include/tgbot/types/MaskPosition.h
new file mode 100644
index 0000000..edd5d5e
--- /dev/null
+++ b/include/tgbot/types/MaskPosition.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * 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_MARKPOSITION_H
+#define TGBOT_MARKPOSITION_H
+
+#include <memory>
+#include <string>
+
+namespace TgBot {
+
+/**
+ * This object describes the position on faces where a mask should be placed by default.
+ * @ingroup types
+ */
+class MaskPosition {
+public:
+ typedef std::shared_ptr<MaskPosition> Ptr;
+
+ /**
+ * The part of the face relative to which the mask should be placed. One of “forehead”, “eyes”, “mouth”, or “chin”.
+ */
+ std::string point;
+
+ /**
+ * Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example, choosing -1.0 will place mask just to the left of the default mask position.
+ */
+ float xShift;
+
+ /**
+ * Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example, 1.0 will place the mask just below the default mask position.
+ */
+ float yShift;
+
+ /**
+ * Mask scaling coefficient. For example, 2.0 means double size.
+ */
+ float scale;
+};
+}
+
+#endif //TGBOT_MARKPOSITION_H \ No newline at end of file
diff --git a/include/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h
index 94140c1..b7c746b 100644
--- a/include/tgbot/types/Sticker.h
+++ b/include/tgbot/types/Sticker.h
@@ -27,6 +27,7 @@
#include <memory>
#include "tgbot/types/PhotoSize.h"
+#include "tgbot/types/MaskPosition.h"
namespace TgBot {
@@ -65,6 +66,16 @@ public:
std::string emoji;
/**
+ * Optional. Name of the sticker set to which the sticker belongs.
+ */
+ std::string setName;
+
+ /**
+ * Optional. For mask stickers, the position where the mask should be placed.
+ */
+ MaskPosition::Ptr maskPosition;
+
+ /**
* Optional. File size.
*/
int32_t fileSize;
diff --git a/include/tgbot/types/StickerSet.h b/include/tgbot/types/StickerSet.h
new file mode 100644
index 0000000..d36c6f1
--- /dev/null
+++ b/include/tgbot/types/StickerSet.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * 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_STICKERSET_H
+#define TGBOT_STICKERSET_H
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "tgbot/types/Sticker.h"
+
+namespace TgBot {
+
+/**
+ * This object represents a sticker set.
+ * @ingroup types
+ */
+class StickerSet {
+public:
+ typedef std::shared_ptr<StickerSet> Ptr;
+
+ /**
+ * Sticker set name.
+ */
+ std::string name;
+
+ /**
+ * Sticker set title.
+ */
+ std::string title;
+
+ /**
+ * True, if the sticker set contains masks.
+ */
+ bool containsMasks = false;
+
+ /**
+ * List of all set stickers.
+ */
+ std::vector<Sticker::Ptr> stickers;
+};
+}
+
+#endif //TGBOT_STICKERSET_H \ No newline at end of file
diff --git a/src/Api.cpp b/src/Api.cpp
index 5b9c8e8..91bab0d 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -109,7 +109,7 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string&
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args));
}
-Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr audio, const std::string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
+Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr audio, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName));
@@ -137,7 +137,7 @@ Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr audio, const st
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args));
}
-Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const std::string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
+Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("audio", audioId));
@@ -165,7 +165,7 @@ Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const std::st
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args));
}
-Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
+Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("document", document->data, true, document->mimeType, document->fileName));
@@ -184,7 +184,7 @@ Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, co
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args));
}
-Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
+Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("document", document));
@@ -235,7 +235,79 @@ Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t r
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args));
}
-Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t duration, int32_t width, int32_t height, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
+StickerSet::Ptr Api::getStickerSet(const string& name) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("name", name));
+ return TgTypeParser::getInstance().parseJsonAndGetStickerSet(sendRequest("getStickerSet", args));
+}
+
+File::Ptr Api::uploadStickerFile(int32_t userId, const InputFile::Ptr pngSticker) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("user_id", userId));
+ args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
+ return TgTypeParser::getInstance().parseJsonAndGetFile(sendRequest("uploadStickerFile", args));
+}
+
+bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, InputFile::Ptr pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("user_id", userId));
+ args.push_back(HttpReqArg("name", name));
+ args.push_back(HttpReqArg("title", title));
+ args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
+ args.push_back(HttpReqArg("emojis", emojis));
+ args.push_back(HttpReqArg("contains_mask", containsMasks));
+ args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ return sendRequest("createNewStickerSet", args).get<bool>("", false);
+}
+
+bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("user_id", userId));
+ args.push_back(HttpReqArg("name", name));
+ args.push_back(HttpReqArg("title", title));
+ args.push_back(HttpReqArg("png_sticker", pngSticker));
+ args.push_back(HttpReqArg("emojis", emojis));
+ args.push_back(HttpReqArg("contains_mask", containsMasks));
+ args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ return sendRequest("createNewStickerSet", args).get<bool>("", false);
+}
+
+bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, InputFile::Ptr pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("user_id", userId));
+ args.push_back(HttpReqArg("name", name));
+ args.push_back(HttpReqArg("title", title));
+ args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
+ args.push_back(HttpReqArg("emojis", emojis));
+ args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ return sendRequest("addStickerToSet", args).get<bool>("", false);
+}
+
+bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("user_id", userId));
+ args.push_back(HttpReqArg("name", name));
+ args.push_back(HttpReqArg("title", title));
+ args.push_back(HttpReqArg("png_sticker", pngSticker));
+ args.push_back(HttpReqArg("emojis", emojis));
+ args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ return sendRequest("addStickerToSet", args).get<bool>("", false);
+}
+
+bool Api::setStickerPositionInSet(const string& sticker, uint32_t position) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("sticker", sticker));
+ args.push_back(HttpReqArg("position", position));
+ return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
+}
+
+bool Api::deleteStickerPositionInSet(const string& sticker) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("sticker", sticker));
+ return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
+}
+
+Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("video", video->data, true, video->mimeType, video->fileName));
@@ -263,7 +335,7 @@ Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args));
}
-Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t duration, int32_t width, int32_t height, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
+Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("video", videoId));
@@ -313,7 +385,7 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote,
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args));
}
-Message::Ptr Api::sendVideoNote(int64_t chatId, const std::string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) {
+Message::Ptr Api::sendVideoNote(int64_t chatId, const string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("video_note", videoNote));
@@ -335,7 +407,7 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const std::string &videoNote, in
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args));
}
-Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
+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));
args.push_back(HttpReqArg("voice", voice->data, true, voice->mimeType, voice->fileName));
@@ -357,7 +429,7 @@ Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const st
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoice", args));
}
-Message::Ptr Api::sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
+Message::Ptr Api::sendVoice(int64_t chatId, const string& voiceId, 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));
args.push_back(HttpReqArg("voice", voiceId));
@@ -396,7 +468,7 @@ Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude,
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendLocation", args));
}
-Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, std::string title, std::string address, std::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, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("latitude", latitude));
@@ -418,7 +490,7 @@ Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, std
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVenue", args));
}
-Message::Ptr Api::sendContact(int64_t chatId, std::string phoneNumber, std::string firstName, std::string lastName, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
+Message::Ptr Api::sendContact(int64_t chatId, const string& phoneNumber, const string& firstName, const string& lastName, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("phone_number", phoneNumber));
@@ -454,7 +526,7 @@ UserProfilePhotos::Ptr Api::getUserProfilePhotos(int32_t userId, int32_t offset,
return TgTypeParser::getInstance().parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args));
}
-File::Ptr Api::getFile(const std::string &fileId) const
+File::Ptr Api::getFile(const string &fileId) const
{
vector<HttpReqArg> args;
args.push_back(HttpReqArg("file_id", fileId));
@@ -489,7 +561,7 @@ int32_t Api::getChatMembersCount(int64_t chatId) const
return sendRequest("getChatMembersCount", args).get<int32_t>("", 0);
}
-bool Api::answerCallbackQuery(const std::string & callbackQueryId, const std::string & text, bool showAlert, const std::string &url, int32_t cacheTime) const
+bool Api::answerCallbackQuery(const string & callbackQueryId, const string & text, bool showAlert, const string &url, int32_t cacheTime) const
{
vector<HttpReqArg> args;
args.push_back(HttpReqArg("callback_query_id", callbackQueryId));
@@ -508,8 +580,8 @@ bool Api::answerCallbackQuery(const std::string & callbackQueryId, const std::st
return sendRequest("answerCallbackQuery", args).get<bool>("", false);
}
-Message::Ptr Api::editMessageText(const std::string& text, int64_t chatId, int32_t messageId, const std::string& inlineMessageId,
- const std::string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const {
+Message::Ptr Api::editMessageText(const string& text, int64_t chatId, int32_t messageId, const string& inlineMessageId,
+ const string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("text", text));
@@ -539,8 +611,8 @@ Message::Ptr Api::editMessageText(const std::string& text, int64_t chatId, int32
}
}
-Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const std::string& caption,
- const std::string& inlineMessageId, const GenericReply::Ptr replyMarkup) const {
+Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const string& caption,
+ const string& inlineMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
if (chatId) {
@@ -567,7 +639,7 @@ Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const st
}
-Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, const std::string& inlineMessageId,
+Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, const string& inlineMessageId,
const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
@@ -610,8 +682,8 @@ vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo
args.push_back(HttpReqArg("timeout", timeout));
}
if (allowedUpdates != nullptr) {
- string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<std::string>(
- [](const std::string &s)->std::string {
+ string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<string>(
+ [](const string &s)->string {
return s;
}, *allowedUpdates);
args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson));
@@ -630,8 +702,8 @@ void Api::setWebhook(const string& url, const InputFile::Ptr certificate, int32_
if (allowedUpdates != nullptr)
{
- string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<std::string>(
- [](const std::string &s)->std::string {
+ string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<string>(
+ [](const string &s)->string {
return s;
}, *allowedUpdates);
args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson));
@@ -663,8 +735,8 @@ WebhookInfo::Ptr Api::getWebhookInfo() const
}
}
-bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
- int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const {
+bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
+ int32_t cacheTime, bool isPersonal, const string& nextOffset, const string& switchPmText, const string& switchPmParameter) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("inline_query_id", inlineQueryId));
string resultsJson = TgTypeParser::getInstance().parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results);
@@ -756,13 +828,13 @@ bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo,
return sendRequest("promoteChatMember", args).get<bool>("", false);
}
-std::string Api::exportChatInviteLink(int64_t chatId) const {
+string Api::exportChatInviteLink(int64_t chatId) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
return sendRequest("exportChatInviteLink", args).get("", "");
}
-bool Api::setChatPhoto(int64_t chatId, InputFile::Ptr photo) const {
+bool Api::setChatPhoto(int64_t chatId, const InputFile::Ptr photo) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName));
@@ -775,14 +847,14 @@ bool Api::deleteChatPhoto(int64_t chatId) const {
return sendRequest("deleteChatPhoto", args).get<bool>("", false);
}
-bool Api::setChatTitle(int64_t chatId, std::string title) const {
+bool Api::setChatTitle(int64_t chatId, const string& title) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("title", title));
return sendRequest("setChatTitle", args).get<bool>("", false);
}
-bool Api::setChatDescription(int64_t chatId, std::string description) const {
+bool Api::setChatDescription(int64_t chatId, const string& description) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("description", description));
@@ -832,7 +904,7 @@ ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) con
}
}
-std::string Api::downloadFile(const std::string& filePath, const std::vector<HttpReqArg>& args) const {
+string Api::downloadFile(const string& filePath, const std::vector<HttpReqArg>& args) const {
string url = "https://api.telegram.org/file/bot";
url += _token;
url += "/";
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index fafe94f..ff2ffe7 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -287,6 +287,8 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const {
result->height = data.get<int32_t>("height");
result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
result->emoji = data.get("emoji", "");
+ result->setName = data.get("set_name", "");
+ result->maskPosition = tryParseJson<MaskPosition>(&TgTypeParser::parseJsonAndGetMaskPosition, data, "mask_position");
result->fileSize = data.get("file_size", 0);
return result;
}
@@ -308,6 +310,54 @@ string TgTypeParser::parseSticker(const Sticker::Ptr& object) const {
return result;
}
+StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const ptree& data) const {
+ auto result(make_shared<StickerSet>());
+ result->name = data.get("name", "");
+ result->title = data.get("title", "");
+ result->containsMasks = data.get<bool>("contains_masks", false);
+ result->stickers = parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "stickers");
+ return result;
+}
+
+string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "name", object->name);
+ appendToJson(result, "title", object->title);
+ appendToJson(result, "contains_masks", object->containsMasks);
+ appendToJson(result, "thumb", parseArray(&TgTypeParser::parseJsonAndGetSticker, object->stickers));
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+MaskPosition::Ptr TgTypeParser::parseJsonAndGetMaskPosition(const ptree& data) const {
+ auto result(make_shared<MaskPosition>());
+ result->point = data.get("point", "");
+ result->xShift = data.get<float>("x_shift", 0);
+ result->yShift = data.get<float>("y_shift", 0);
+ result->scale = data.get<float>("scale", 0);
+ return result;
+}
+
+string TgTypeParser::parseMaskPosition(const MaskPosition::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "point", object->point);
+ appendToJson(result, "x_shift", object->xShift);
+ appendToJson(result, "y_shift", object->yShift);
+ appendToJson(result, "scale", object->scale);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
Video::Ptr TgTypeParser::parseJsonAndGetVideo(const ptree& data) const {
auto result(make_shared<Video>());
result->fileId = data.get<string>("file_id");
@@ -621,6 +671,19 @@ ChatPhoto::Ptr TgTypeParser::parseJsonAndGetChatPhoto(const boost::property_tree
return result;
}
+std::string TgTypeParser::parseChatPhoto(const ChatPhoto::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "small_file_id", object->smallFileId);
+ appendToJson(result, "big_file_id", object->bigFileId);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const {
auto result(make_shared<ResponseParameters>());
result->migrateToChatId = data.get<int32_t>("migrate_to_chat_id", 0);