summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--README.md194
-rw-r--r--include/tgbot/Api.h32
-rw-r--r--include/tgbot/types/Sticker.h9
-rw-r--r--include/tgbot/types/StickerSet.h7
-rw-r--r--src/Api.cpp57
-rw-r--r--src/TgTypeParser.cpp4
7 files changed, 168 insertions, 138 deletions
diff --git a/.gitignore b/.gitignore
index 6a1f7ed..9f1d7bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,12 +12,13 @@ doc/
Thumbs.db
TgBot_test
.idea/
-.vscode/
docs/
cmake-build-*
# Visual Studio
/.vs/
+.vscode/
+/build/
/out/
# MacOS dependecies
diff --git a/README.md b/README.md
index 468dcd8..103dcdc 100644
--- a/README.md
+++ b/README.md
@@ -1,98 +1,98 @@
-# tgbot-cpp
-
-[![Travis build Status](https://travis-ci.org/reo7sp/tgbot-cpp.svg?branch=master)](https://travis-ci.org/reo7sp/tgbot-cpp)
-<br>
-[![GitHub contributors](https://img.shields.io/github/contributors/reo7sp/tgbot-cpp.svg)](https://github.com/reo7sp/tgbot-cpp/graphs/contributors)
-
-C++14 library for Telegram bot API.
-
-Documentation is located [here](http://reo7sp.github.io/tgbot-cpp).
-
-
-## State
-
-- [x] Bot API 3.0 ~ 3.6
+# tgbot-cpp
+
+[![Travis build Status](https://travis-ci.org/reo7sp/tgbot-cpp.svg?branch=master)](https://travis-ci.org/reo7sp/tgbot-cpp)
+<br>
+[![GitHub contributors](https://img.shields.io/github/contributors/reo7sp/tgbot-cpp.svg)](https://github.com/reo7sp/tgbot-cpp/graphs/contributors)
+
+C++14 library for Telegram bot API.
+
+Documentation is located [here](http://reo7sp.github.io/tgbot-cpp).
+
+
+## State
+
+- [x] Bot API 3.0 ~ 3.6
- [x] Bot API 4.0 ~ 4.9
-- [x] Bot API 5.0 ~ 5.6 (Implemented all APIs except 'Run Your Own Bot API Server')
-
-
-## Sample
-
-Simple echo bot which sends everything it receives:
-```cpp
-#include <stdio.h>
-#include <tgbot/tgbot.h>
-
-int main() {
- TgBot::Bot bot("PLACE YOUR TOKEN HERE");
- bot.getEvents().onCommand("start", [&bot](TgBot::Message::Ptr message) {
- bot.getApi().sendMessage(message->chat->id, "Hi!");
- });
- bot.getEvents().onAnyMessage([&bot](TgBot::Message::Ptr message) {
- printf("User wrote %s\n", message->text.c_str());
- if (StringTools::startsWith(message->text, "/start")) {
- return;
- }
- bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text);
- });
- try {
- printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str());
- TgBot::TgLongPoll longPoll(bot);
- while (true) {
- printf("Long poll started\n");
- longPoll.start();
- }
- } catch (TgBot::TgException& e) {
- printf("error: %s\n", e.what());
- }
- return 0;
-}
-```
-
-All other samples are located [here](samples).
-
-
-## Dependencies
-
-Firstly you need to install some dependencies such as Boost and build tools such as CMake. On Debian-based distibutives you can do it with these commands:
-```sh
-sudo apt-get install g++ make binutils cmake libssl-dev libboost-system-dev zlib1g-dev
-```
-If you want to use curl-based http client `CurlHttpClient`, you also need to install `libcurl4-openssl-dev` package.
-
-## Library installation
-
-If you want to install the library system-wide:
-```sh
-git clone https://github.com/reo7sp/tgbot-cpp
-cd tgbot-cpp
-cmake .
-make -j4
-sudo make install
-```
-
-You can treat this repository as a submodule of your project, for example, see [echobot-submodule](samples/echobot-submodule/CMakeLists.txt)
-
-You can use Docker to build and run your bot. Set the base image of your's Dockerfile to [reo7sp/tgbot-cpp](https://hub.docker.com/r/reo7sp/tgbot-cpp/).
-
-
-## Bot compilation
-
-### With CMake
-[Example CMakeLists.txt](samples/echobot/CMakeLists.txt)
-
-### Without CMake
-```sh
-g++ telegram_bot.cpp -o telegram_bot --std=c++14 -I/usr/local/include -lTgBot -lboost_system -lssl -lcrypto -lpthread
-```
-
-### Build options
-```
--DTGBOT_DISABLE_NAGLES_ALGORITHM # Disable 'Nagle's algorithm'
--DTGBOT_CHANGE_SOCKET_BUFFER_SIZE # Socket Buffer Size Expansion
--DTGBOT_CHANGE_READ_BUFFER_SIZE # Read Buffer Size Expansion
-```
-
-
-## Licence
-[The MIT License](https://github.com/reo7sp/tgbot-cpp/blob/master/LICENSE).
+- [x] Bot API 5.0 ~ 5.7 (Implemented all APIs except 'Run Your Own Bot API Server')
+
+
+## Sample
+
+Simple echo bot which sends everything it receives:
+```cpp
+#include <stdio.h>
+#include <tgbot/tgbot.h>
+
+int main() {
+ TgBot::Bot bot("PLACE YOUR TOKEN HERE");
+ bot.getEvents().onCommand("start", [&bot](TgBot::Message::Ptr message) {
+ bot.getApi().sendMessage(message->chat->id, "Hi!");
+ });
+ bot.getEvents().onAnyMessage([&bot](TgBot::Message::Ptr message) {
+ printf("User wrote %s\n", message->text.c_str());
+ if (StringTools::startsWith(message->text, "/start")) {
+ return;
+ }
+ bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text);
+ });
+ try {
+ printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str());
+ TgBot::TgLongPoll longPoll(bot);
+ while (true) {
+ printf("Long poll started\n");
+ longPoll.start();
+ }
+ } catch (TgBot::TgException& e) {
+ printf("error: %s\n", e.what());
+ }
+ return 0;
+}
+```
+
+All other samples are located [here](samples).
+
+
+## Dependencies
+
+Firstly you need to install some dependencies such as Boost and build tools such as CMake. On Debian-based distibutives you can do it with these commands:
+```sh
+sudo apt-get install g++ make binutils cmake libssl-dev libboost-system-dev zlib1g-dev
+```
+If you want to use curl-based http client `CurlHttpClient`, you also need to install `libcurl4-openssl-dev` package.
+
+## Library installation
+
+If you want to install the library system-wide:
+```sh
+git clone https://github.com/reo7sp/tgbot-cpp
+cd tgbot-cpp
+cmake .
+make -j4
+sudo make install
+```
+
+You can treat this repository as a submodule of your project, for example, see [echobot-submodule](samples/echobot-submodule/CMakeLists.txt)
+
+You can use Docker to build and run your bot. Set the base image of your's Dockerfile to [reo7sp/tgbot-cpp](https://hub.docker.com/r/reo7sp/tgbot-cpp/).
+
+
+## Bot compilation
+
+### With CMake
+[Example CMakeLists.txt](samples/echobot/CMakeLists.txt)
+
+### Without CMake
+```sh
+g++ telegram_bot.cpp -o telegram_bot --std=c++14 -I/usr/local/include -lTgBot -lboost_system -lssl -lcrypto -lpthread
+```
+
+### Build options
+```
+-DTGBOT_DISABLE_NAGLES_ALGORITHM # Disable 'Nagle's algorithm'
+-DTGBOT_CHANGE_SOCKET_BUFFER_SIZE # Socket Buffer Size Expansion
+-DTGBOT_CHANGE_READ_BUFFER_SIZE # Read Buffer Size Expansion
+```
+
+
+## Licence
+[The MIT License](https://github.com/reo7sp/tgbot-cpp/blob/master/LICENSE).
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index e0c69ec..be81d8e 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -1214,7 +1214,10 @@ public:
File::Ptr uploadStickerFile(std::int64_t userId, InputFile::Ptr pngSticker) const;
/**
- * @brief Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields pngSticker or tgsSticker.
+ * @brief Use this method to create a new sticker set owned by a user.
+ *
+ * The bot will be able to edit the sticker set thus created.
+ * You must use exactly one of the fields pngSticker, tgsSticker, or webmSticker.
*
* @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.
@@ -1222,8 +1225,9 @@ public:
* @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
- * @param pngSticker Optional. 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 fileId 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, or upload a new one using multipart/form-data.
- * @param tgsSticker Optional. TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
+ * @param pngSticker Optional. 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 fileId 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, or upload a new one using multipart/form-data. https://core.telegram.org/bots/api#sending-files
+ * @param tgsSticker Optional. TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#animated-sticker-requirements for technical requirements
+ * @param webmSticker Optional. WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirements
*
* @return Returns True on success.
*/
@@ -1233,18 +1237,25 @@ public:
const std::string& emojis,
bool containsMasks = false,
MaskPosition::Ptr maskPosition = nullptr,
- boost::variant<InputFile::Ptr, std::string> pngSticker = "",
- boost::variant<InputFile::Ptr, std::string> tgsSticker = "") const;
+ boost::variant<InputFile::Ptr, const std::string&> pngSticker = "",
+ InputFile::Ptr tgsSticker = nullptr,
+ InputFile::Ptr webmSticker = nullptr) const;
/**
- * @brief Use this method to add a new sticker to a set created by the bot. You must use exactly one of the fields png_sticker or tgs_sticker. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers.
+ * @brief Use this method to add a new sticker to a set created by the bot.
+ *
+ * You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker.
+ * Animated stickers can be added to animated sticker sets and only to them.
+ * Animated sticker sets can have up to 50 stickers.
+ * Static sticker sets can have up to 120 stickers.
*
* @param userId User identifier of sticker set owner
* @param name Sticker set name
* @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
- * @param pngSticker Optional. 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 fileId 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, or upload a new one using multipart/form-data.
- * @param tgsSticker Optional. TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
+ * @param pngSticker Optional. 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 fileId 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, or upload a new one using multipart/form-data. https://core.telegram.org/bots/api#sending-files
+ * @param tgsSticker Optional. TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#animated-sticker-requirements for technical requirements
+ * @param webmSticker Optional. WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirements
*
* @return Returns True on success.
*/
@@ -1252,8 +1263,9 @@ public:
const std::string& name,
const std::string& emojis,
MaskPosition::Ptr maskPosition = nullptr,
- boost::variant<InputFile::Ptr, std::string> pngSticker = "",
- boost::variant<InputFile::Ptr, std::string> tgsSticker = "") const;
+ boost::variant<InputFile::Ptr, const std::string&> pngSticker = "",
+ InputFile::Ptr tgsSticker = nullptr,
+ InputFile::Ptr webmSticker = nullptr) const;
/**
* @brief Use this method to move a sticker in a set created by the bot to a specific position.
diff --git a/include/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h
index 540e157..2dd35fa 100644
--- a/include/tgbot/types/Sticker.h
+++ b/include/tgbot/types/Sticker.h
@@ -47,7 +47,12 @@ public:
bool isAnimated;
/**
- * @brief Optional. Sticker thumbnail in the .webp or .jpg format
+ * @brief True, if the sticker is a video sticker
+ */
+ bool isVideo;
+
+ /**
+ * @brief Optional. Sticker thumbnail in the .WEBP or .JPG format
*/
PhotoSize::Ptr thumb;
@@ -67,7 +72,7 @@ public:
MaskPosition::Ptr maskPosition;
/**
- * @brief Optional. File size
+ * @brief Optional. File size in bytes
*/
std::int32_t fileSize;
};
diff --git a/include/tgbot/types/StickerSet.h b/include/tgbot/types/StickerSet.h
index 4009096..0ef940f 100644
--- a/include/tgbot/types/StickerSet.h
+++ b/include/tgbot/types/StickerSet.h
@@ -35,6 +35,11 @@ public:
bool isAnimated;
/**
+ * @brief True, if the sticker set contains video stickers
+ */
+ bool isVideo;
+
+ /**
* @brief True, if the sticker set contains masks
*/
bool containsMasks;
@@ -45,7 +50,7 @@ public:
std::vector<Sticker::Ptr> stickers;
/**
- * @brief Optional. Sticker set thumbnail in the .WEBP or .TGS format
+ * @brief Optional. Sticker set thumbnail in the .WEBP, .TGS, or .WEBM format
*/
PhotoSize::Ptr thumb;
};
diff --git a/src/Api.cpp b/src/Api.cpp
index bb63721..9538485 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -1634,27 +1634,28 @@ bool Api::createNewStickerSet(std::int64_t userId,
const std::string& emojis,
bool containsMasks,
MaskPosition::Ptr maskPosition,
- boost::variant<InputFile::Ptr, std::string> pngSticker,
- boost::variant<InputFile::Ptr, std::string> tgsSticker) const {
+ boost::variant<InputFile::Ptr, const std::string&> pngSticker,
+ InputFile::Ptr tgsSticker,
+ InputFile::Ptr webmSticker) const {
vector<HttpReqArg> args;
- args.reserve(8);
+ args.reserve(9);
args.emplace_back("user_id", userId);
args.emplace_back("name", name);
args.emplace_back("title", title);
- args.emplace_back("emojis", emojis);
- if (pngSticker.which() == 0 /* InputFile::Ptr */) {
+ if (pngSticker.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(pngSticker);
args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName);
- } else /* std::string */ {
- args.emplace_back("png_sticker", boost::get<std::string>(pngSticker));
+ } else { // const std::string&
+ args.emplace_back("png_sticker", boost::get<const std::string&>(pngSticker));
}
- if (tgsSticker.which() == 0 /* InputFile::Ptr */) {
- auto file = boost::get<InputFile::Ptr>(tgsSticker);
- args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName);
- } else /* std::string */ {
- args.emplace_back("tgs_sticker", boost::get<std::string>(tgsSticker));
+ if (tgsSticker != nullptr) {
+ args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName);
+ }
+ if (webmSticker != nullptr) {
+ args.emplace_back("webm_sticker", webmSticker->data, true, webmSticker->mimeType, webmSticker->fileName);
}
+ args.emplace_back("emojis", emojis);
if (containsMasks) {
args.emplace_back("contains_mask", containsMasks);
}
@@ -1666,29 +1667,31 @@ bool Api::createNewStickerSet(std::int64_t userId,
}
bool Api::addStickerToSet(std::int64_t userId,
- const std::string& name,
- const std::string& emojis,
- MaskPosition::Ptr maskPosition,
- boost::variant<InputFile::Ptr, std::string> pngSticker,
- boost::variant<InputFile::Ptr, std::string> tgsSticker) const {
+ const std::string& name,
+ const std::string& emojis,
+ MaskPosition::Ptr maskPosition,
+ boost::variant<InputFile::Ptr, const std::string&> pngSticker,
+ InputFile::Ptr tgsSticker,
+ InputFile::Ptr webmSticker) const {
vector<HttpReqArg> args;
- args.reserve(6);
+ args.reserve(7);
args.emplace_back("user_id", userId);
args.emplace_back("name", name);
- args.emplace_back("emojis", emojis);
- if (pngSticker.which() == 0 /* InputFile::Ptr */) {
+
+ if (pngSticker.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(pngSticker);
args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName);
- } else /* std::string */ {
- args.emplace_back("png_sticker", boost::get<std::string>(pngSticker));
+ } else { // const std::string&
+ args.emplace_back("png_sticker", boost::get<const std::string&>(pngSticker));
}
- if (tgsSticker.which() == 0 /* InputFile::Ptr */) {
- auto file = boost::get<InputFile::Ptr>(tgsSticker);
- args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName);
- } else /* std::string */ {
- args.emplace_back("tgs_sticker", boost::get<std::string>(tgsSticker));
+ if (tgsSticker != nullptr) {
+ args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName);
}
+ if (webmSticker != nullptr) {
+ args.emplace_back("webm_sticker", webmSticker->data, true, webmSticker->mimeType, webmSticker->fileName);
+ }
+ args.emplace_back("emojis", emojis);
if (maskPosition != nullptr) {
args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition));
}
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 85b44e8..daf80c8 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -386,6 +386,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::pt
result->width = data.get<std::int32_t>("width", 0);
result->height = data.get<std::int32_t>("height", 0);
result->isAnimated = data.get<bool>("is_animated", false);
+ result->isVideo = data.get<bool>("is_video", false);
result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
result->emoji = data.get<std::string>("emoji", "");
result->setName = data.get<std::string>("set_name", "");
@@ -405,6 +406,7 @@ std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const {
appendToJson(result, "width", object->width);
appendToJson(result, "height", object->height);
appendToJson(result, "is_animated", object->isAnimated);
+ appendToJson(result, "is_video", object->isVideo);
appendToJson(result, "thumb", parsePhotoSize(object->thumb));
appendToJson(result, "emoji", object->emoji);
appendToJson(result, "set_name", object->setName);
@@ -420,6 +422,7 @@ StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const boost::property_tr
result->name = data.get<std::string>("name", "");
result->title = data.get<std::string>("title", "");
result->isAnimated = data.get<bool>("is_animated", false);
+ result->isVideo = data.get<bool>("is_video", false);
result->containsMasks = data.get<bool>("contains_masks", false);
result->stickers = parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "stickers");
result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
@@ -435,6 +438,7 @@ std::string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const {
appendToJson(result, "name", object->name);
appendToJson(result, "title", object->title);
appendToJson(result, "is_animated", object->isAnimated);
+ appendToJson(result, "is_video", object->isVideo);
appendToJson(result, "contains_masks", object->containsMasks);
appendToJson(result, "stickers", parseArray(&TgTypeParser::parseSticker, object->stickers));
appendToJson(result, "thumb", parsePhotoSize(object->thumb));