summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-rw-r--r--.gitignore7
-rw-r--r--CMakeLists.txt8
-rw-r--r--Dockerfile2
-rw-r--r--Dockerfile_test19
-rw-r--r--README.md51
-rw-r--r--include/tgbot/Api.h734
-rw-r--r--include/tgbot/EventBroadcaster.h167
-rw-r--r--include/tgbot/EventHandler.h4
-rw-r--r--include/tgbot/TgTypeParser.h473
-rw-r--r--include/tgbot/tools/StringTools.h9
-rw-r--r--samples/echobot-curl-client/CMakeLists.txt6
-rw-r--r--samples/echobot-curl-client/Dockerfile4
-rw-r--r--samples/echobot-setmycommands/CMakeLists.txt12
-rw-r--r--samples/echobot-setmycommands/Dockerfile4
-rw-r--r--samples/echobot-submodule/CMakeLists.txt6
-rw-r--r--samples/echobot-submodule/Dockerfile4
-rw-r--r--samples/echobot-webhook-server/CMakeLists.txt6
-rw-r--r--samples/echobot-webhook-server/Dockerfile4
-rw-r--r--samples/echobot/CMakeLists.txt6
-rw-r--r--samples/inline-keyboard/CMakeLists.txt6
-rw-r--r--samples/inline-keyboard/Dockerfile2
-rw-r--r--samples/photo/CMakeLists.txt6
-rw-r--r--samples/received-text-processing/CMakeLists.txt6
-rw-r--r--samples/received-text-processing/Dockerfile8
-rw-r--r--samples/reply-keyboard/CMakeLists.txt21
-rw-r--r--samples/reply-keyboard/Dockerfile8
-rw-r--r--src/Api.cpp717
-rw-r--r--src/EventHandler.cpp47
-rw-r--r--src/TgTypeParser.cpp3185
-rw-r--r--src/net/TgLongPoll.cpp8
-rw-r--r--src/tools/StringTools.cpp18
-rw-r--r--[-rwxr-xr-x]tools/docker-run-sample0
-rw-r--r--[-rwxr-xr-x]tools/docker-run-sample-webhook0
-rw-r--r--[-rwxr-xr-x]tools/docker-test0
-rw-r--r--[-rwxr-xr-x]tools/docs-generate0
-rw-r--r--[-rwxr-xr-x]tools/docs-push-gh-pages0
-rw-r--r--[-rwxr-xr-x]tools/list-includes0
-rw-r--r--[-rwxr-xr-x]tools/list-srcs0
39 files changed, 3099 insertions, 2460 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..fcadb2c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text eol=lf
diff --git a/.gitignore b/.gitignore
index 9f1d7bb..56b06ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
CMakeCache.txt
CMakeFiles
+CMakeSettings.json
Makefile
*.cmake
install_manifest.txt
@@ -16,10 +17,10 @@ docs/
cmake-build-*
# Visual Studio
-/.vs/
+.vs/
.vscode/
-/build/
-/out/
+build/
+out/
# MacOS dependecies
.DS_Store
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 664bf67..b50b03a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.10.2)
project(TgBot)
# options
@@ -51,7 +51,7 @@ find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
## curl
-find_package(CURL 7.56.0)
+find_package(CURL 7.58.0)
if (CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
add_definitions(-DHAVE_CURL)
@@ -60,9 +60,9 @@ endif()
## boost
set(Boost_USE_MULTITHREADED ON)
if (ENABLE_TESTS)
- find_package(Boost 1.59.0 COMPONENTS system unit_test_framework REQUIRED)
+ find_package(Boost 1.65.1 COMPONENTS system unit_test_framework REQUIRED)
else()
- find_package(Boost 1.59.0 COMPONENTS system REQUIRED)
+ find_package(Boost 1.65.1 COMPONENTS system REQUIRED)
endif()
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR_RELEASE})
diff --git a/Dockerfile b/Dockerfile
index 1cbf811..5bcf6c7 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM debian:stretch
+FROM debian:buster
MAINTAINER Oleg Morozenkov <m@oleg.rocks>
RUN apt-get -qq update && \
diff --git a/Dockerfile_test b/Dockerfile_test
index ad52a88..6306115 100644
--- a/Dockerfile_test
+++ b/Dockerfile_test
@@ -40,6 +40,20 @@ WORKDIR /usr/src/tgbot-cpp/samples/echobot-curl-client
RUN rm -rf CMakeCache.txt CMakeFiles/ && \
cmake . && make -j$(nproc)
+WORKDIR /usr/src/tgbot-cpp/samples/echobot-setmycommands
+RUN rm -rf CMakeCache.txt CMakeFiles/ && \
+ cmake . && make -j$(nproc)
+
+WORKDIR /usr/src/tgbot-cpp
+RUN rm -rf samples/echobot-submodule/tgbot-cpp/
+COPY include samples/echobot-submodule/tgbot-cpp/include
+COPY src samples/echobot-submodule/tgbot-cpp/src
+COPY CMakeLists.txt samples/echobot-submodule/tgbot-cpp/
+
+WORKDIR /usr/src/tgbot-cpp/samples/echobot-submodule
+RUN rm -rf CMakeCache.txt CMakeFiles/ && \
+ cmake . && make -j$(nproc)
+
WORKDIR /usr/src/tgbot-cpp/samples/echobot-webhook-server
RUN rm -rf CMakeCache.txt CMakeFiles/ && \
cmake . && make -j$(nproc)
@@ -56,7 +70,10 @@ WORKDIR /usr/src/tgbot-cpp/samples/received-text-processing
RUN rm -rf CMakeCache.txt CMakeFiles/ && \
cmake . && make -j$(nproc)
+WORKDIR /usr/src/tgbot-cpp/samples/reply-keyboard
+RUN rm -rf CMakeCache.txt CMakeFiles/ && \
+ cmake . && make -j$(nproc)
+
WORKDIR /usr/src/tgbot-cpp
ENV CTEST_OUTPUT_ON_FAILURE=1
CMD make test
-
diff --git a/README.md b/README.md
index d3aeb69..99e1ce8 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,57 @@ You can treat this repository as a submodule of your project, for example, see [
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/).
+## Installation Windows
+
+### Download vcpkg and tgbot-cpp
+
+Taken from [Vcpkg - Quick Start: Windows](https://github.com/Microsoft/vcpkg/#quick-start-windows):
+
+Prerequisites:
+- Windows 7 or newer
+- Git
+- Visual Studio 2015 Update 3 or greater with the English language pack
+
+First, download and bootstrap vcpkg itself; it can be installed anywhere,
+but generally we recommend using vcpkg as a submodule for CMake projects,
+and installing it globally for Visual Studio projects.
+We recommend somewhere like `C:\src\vcpkg` or `C:\dev\vcpkg`,
+since otherwise you may run into path issues for some port build systems.
+
+```cmd
+> git clone https://github.com/microsoft/vcpkg
+> .\vcpkg\bootstrap-vcpkg.bat
+```
+
+In order to use vcpkg with Visual Studio,
+run the following command (may require administrator elevation):
+
+```cmd
+> .\vcpkg\vcpkg integrate install
+```
+
+To install the libraries for Windows x64, run:
+
+```cmd
+> .\vcpkg\vcpkg install tgbot-cpp:x64-windows
+```
+
+To install for Windows x86, run:
+
+```cmd
+> .\vcpkg\vcpkg install tgbot-cpp
+```
+
+The library will now be installed and Visual Studio should be able to find the vcpkg installation.
+
+### Setup project with CMakeLists
+
+Use the [example CMakeLists.txt](samples/echobot/CMakeLists.txt) with changes:
+
+Remove `/usr/local/include`
+
+Change `/usr/local/lib/libTgBot.a` to `C:/src/vcpkg/installed/x64-windows/lib/TgBot.lib` or something simmilar according to your own installation path.
+
## Bot compilation
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 78fb4fa..9dd2f5e 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -1,9 +1,11 @@
#ifndef TGBOT_API_H
#define TGBOT_API_H
+#include "tgbot/TgException.h"
#include "tgbot/TgTypeParser.h"
#include "tgbot/net/HttpClient.h"
#include "tgbot/net/HttpReqArg.h"
+#include "tgbot/tools/StringTools.h"
#include "tgbot/types/User.h"
#include "tgbot/types/Message.h"
#include "tgbot/types/MessageId.h"
@@ -30,6 +32,7 @@
#include <cstdint>
#include <memory>
#include <string>
+#include <utility>
#include <vector>
namespace TgBot {
@@ -51,7 +54,7 @@ public:
Api(std::string token, const HttpClient& httpClient, const std::string& url);
/**
- * @brief Use this method to receive incoming updates using long polling.
+ * @brief Use this method to receive incoming updates using long polling (https://en.wikipedia.org/wiki/Push_technology#Long_polling).
*
* This method will not work if an outgoing webhook is set up.
* In order to avoid getting duplicate updates, recalculate offset after each server response.
@@ -61,7 +64,7 @@ public:
* @param timeout Optional. Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.
* @param allowedUpdates Optional. A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chatMember (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the Api::getUpdates, so unwanted updates may be received for a short period of time.
*
- * @return An Array of Update objects is returned.
+ * @return Returns an Array of Update objects.
*/
std::vector<Update::Ptr> getUpdates(std::int32_t offset = 0,
std::int32_t limit = 100,
@@ -88,8 +91,8 @@ public:
*
* @param url HTTPS URL to send updates to. Use an empty string to remove webhook integration
* @param certificate Optional. Upload your public key certificate so that the root certificate in use can be checked. See https://core.telegram.org/bots/self-signed for details.
- * @param maxConnection Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput.
- * @param allowedUpdates Optional. A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chatMember (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time.
+ * @param maxConnections Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput.
+ * @param allowedUpdates Optional. A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chatMember (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the Api::setWebhook, so unwanted updates may be received for a short period of time.
* @param ipAddress Optional. The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS
* @param dropPendingUpdates Optional. Pass True to drop all pending updates
* @param secretToken Optional. A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you.
@@ -98,18 +101,18 @@ public:
*/
bool setWebhook(const std::string& url,
InputFile::Ptr certificate = nullptr,
- std::int32_t maxConnection = 40,
+ std::int32_t maxConnections = 40,
const StringArrayPtr& allowedUpdates = nullptr,
const std::string& ipAddress = "",
bool dropPendingUpdates = false,
const std::string& secretToken = "") const;
/**
- * @brief Use this method to remove webhook integration if you decide to switch back to @ref Api::getUpdates.
+ * @brief Use this method to remove webhook integration if you decide to switch back to Api::getUpdates.
*
* @param dropPendingUpdates Optional. Pass True to drop all pending updates
*
- * @return True on success.
+ * @return Returns True on success.
*/
bool deleteWebhook(bool dropPendingUpdates = false) const;
@@ -117,19 +120,44 @@ public:
* @brief Use this method to get current webhook status.
*
* Requires no parameters.
- * If the bot is using getUpdates, will return an object with the url field empty.
+ * If the bot is using Api::getUpdates, will return an object with the url field empty.
*
- * @return On success, returns a WebhookInfo object.
+ * @return On success, returns a WebhookInfo object. If the bot is using getUpdates, will return a nullptr.
*/
WebhookInfo::Ptr getWebhookInfo() const;
/**
- * @brief A simple method for testing your bot's auth token.
- * @return Basic information about the bot in form of a User object.
+ * @brief A simple method for testing your bot's authentication token.
+ *
+ * Requires no parameters.
+ *
+ * @return Returns basic information about the bot in form of a User object.
*/
User::Ptr getMe() const;
/**
+ * @brief Use this method to log out from the cloud Bot API server before launching the bot locally.
+ *
+ * You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates.
+ * After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes.
+ * Requires no parameters.
+ *
+ * @return Returns True on success.
+ */
+ bool logOut() const;
+
+ /**
+ * @brief Use this method to close the bot instance before moving it from one local server to another.
+ *
+ * You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart.
+ * The method will return error 429 in the first 10 minutes after the bot is launched.
+ * Requires no parameters.
+ *
+ * @return Returns True on success.
+ */
+ bool close() const;
+
+ /**
* @brief Use this method to send text messages.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@@ -140,13 +168,13 @@ public:
* @param parseMode Optional. Mode for parsing entities in the message text. See https://core.telegram.org/bots/api#formatting-options for more details.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param entities Optional. A JSON-serialized list of special entities that appear in message text, which can be specified instead of parseMode
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendMessage(boost::variant<std::int64_t, const std::string&> chatId,
+ Message::Ptr sendMessage(boost::variant<std::int64_t, std::string> chatId,
const std::string& text,
bool disableWebPagePreview = false,
std::int32_t replyToMessageId = 0,
@@ -170,8 +198,8 @@ public:
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr forwardMessage(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<std::int64_t, const std::string&> fromChatId,
+ Message::Ptr forwardMessage(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<std::int64_t, std::string> fromChatId,
std::int32_t messageId,
bool disableNotification = false,
bool protectContent = false) const;
@@ -180,6 +208,7 @@ public:
* @brief Use this method to copy messages of any kind.
*
* Service messages and invoice messages can't be copied.
+ * A quiz poll can be copied only if the value of the field correctOptionId is known to the bot.
* The method is analogous to the method Api::forwardMessage, but the copied message doesn't have a link to the original message.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@@ -190,14 +219,14 @@ public:
* @param captionEntities Optional. A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of parseMode
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return Returns the MessageId of the sent message on success.
*/
- MessageId::Ptr copyMessage(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<std::int64_t, const std::string&> fromChatId,
+ MessageId::Ptr copyMessage(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<std::int64_t, std::string> fromChatId,
std::int32_t messageId,
const std::string& caption = "",
const std::string& parseMode = "",
@@ -219,13 +248,13 @@ public:
* @param parseMode Optional. Mode for parsing entities in the photo caption. See https://core.telegram.org/bots/api#formatting-options for more details.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendPhoto(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> photo,
+ Message::Ptr sendPhoto(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> photo,
const std::string& caption = "",
std::int32_t replyToMessageId = 0,
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
@@ -255,18 +284,18 @@ public:
* @param parseMode Optional. Mode for parsing entities in the audio caption. See https://core.telegram.org/bots/api#formatting-options for more details.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendAudio(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> audio,
+ Message::Ptr sendAudio(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> audio,
const std::string& caption = "",
std::int32_t duration = 0,
const std::string& performer = "",
const std::string& title = "",
- boost::variant<InputFile::Ptr, const std::string&> thumb = "",
+ boost::variant<InputFile::Ptr, std::string> thumb = "",
std::int32_t replyToMessageId = 0,
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
const std::string& parseMode = "",
@@ -290,14 +319,14 @@ public:
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode
* @param disableContentTypeDetection Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendDocument(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> document,
- boost::variant<InputFile::Ptr, const std::string&> thumb = "",
+ Message::Ptr sendDocument(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> document,
+ boost::variant<InputFile::Ptr, std::string> thumb = "",
const std::string& caption = "",
std::int32_t replyToMessageId = 0,
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
@@ -309,13 +338,13 @@ public:
bool protectContent = false) const;
/**
- * @brief Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
+ * @brief Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document).
*
* Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param video Video to send. Pass a fileId as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. https://core.telegram.org/bots/api#sending-files
- * @param supportsStreaming Optional. Pass True, if the uploaded video is suitable for streaming
+ * @param supportsStreaming Optional. Pass True if the uploaded video is suitable for streaming
* @param duration Optional. Duration of sent video in seconds
* @param width Optional. Video width
* @param height Optional. Video height
@@ -326,18 +355,18 @@ public:
* @param parseMode Optional. Mode for parsing entities in the video caption. See https://core.telegram.org/bots/api#formatting-options for more details.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendVideo(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> video,
+ Message::Ptr sendVideo(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> video,
bool supportsStreaming = false,
std::int32_t duration = 0,
std::int32_t width = 0,
std::int32_t height = 0,
- boost::variant<InputFile::Ptr, const std::string&> thumb = "",
+ boost::variant<InputFile::Ptr, std::string> thumb = "",
const std::string& caption = "",
std::int32_t replyToMessageId = 0,
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
@@ -364,17 +393,17 @@ public:
* @param parseMode Optional. Mode for parsing entities in the animation caption. See https://core.telegram.org/bots/api#formatting-options for more details.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendAnimation(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> animation,
+ Message::Ptr sendAnimation(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> animation,
std::int32_t duration = 0,
std::int32_t width = 0,
std::int32_t height = 0,
- boost::variant<InputFile::Ptr, const std::string&> thumb = "",
+ boost::variant<InputFile::Ptr, std::string> thumb = "",
const std::string& caption = "",
std::int32_t replyToMessageId = 0,
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
@@ -399,13 +428,13 @@ public:
* @param parseMode Optional. Mode for parsing entities in the voice message caption. See https://core.telegram.org/bots/api#formatting-options for more details.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendVoice(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> voice,
+ Message::Ptr sendVoice(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> voice,
const std::string& caption = "",
std::int32_t duration = 0,
std::int32_t replyToMessageId = 0,
@@ -419,28 +448,28 @@ public:
/**
* @brief Use this method to send video messages.
*
- * As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
+ * As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
- * @param videoNote Video note to send. Pass a fileId as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. Sending video notes by a URL is currently unsupported. https://core.telegram.org/bots/api#sending-files
+ * @param videoNote Video note to send. Pass a fileId as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. https://core.telegram.org/bots/api#sending-files. Sending video notes by a URL is currently unsupported
* @param replyToMessageId Optional. If the message is a reply, ID of the original message
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param duration Optional. Duration of sent video in seconds
* @param length Optional. Video width and height, i.e. diameter of the video message
* @param thumb Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. 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>. https://core.telegram.org/bots/api#sending-files
* @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendVideoNote(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> videoNote,
+ Message::Ptr sendVideoNote(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> videoNote,
std::int64_t replyToMessageId = 0,
bool disableNotification = false,
std::int32_t duration = 0,
std::int32_t length = 0,
- boost::variant<InputFile::Ptr, const std::string&> thumb = "",
+ boost::variant<InputFile::Ptr, std::string> thumb = "",
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
bool allowSendingWithoutReply = false,
bool protectContent = false) const;
@@ -448,18 +477,18 @@ public:
/**
* @brief Use this method to send a group of photos, videos, documents or audios as an album.
*
- * Documents and audio files can be only group in an album with messages of the same type.
+ * Documents and audio files can be only grouped in an album with messages of the same type.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param media A JSON-serialized array describing messages to be sent, must include 2-10 items
* @param disableNotification Optional. Sends messages silently. Users will receive a notification with no sound.
* @param replyToMessageId Optional. If the messages are a reply, ID of the original message
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent messages from forwarding and saving
*
* @return On success, an array of Messages that were sent is returned.
*/
- std::vector<Message::Ptr> sendMediaGroup(boost::variant<std::int64_t, const std::string&> chatId,
+ std::vector<Message::Ptr> sendMediaGroup(boost::variant<std::int64_t, std::string> chatId,
const std::vector<InputMedia::Ptr>& media,
bool disableNotification = false,
std::int32_t replyToMessageId = 0,
@@ -479,12 +508,12 @@ public:
* @param horizontalAccuracy Optional. The radius of uncertainty for the location, measured in meters; 0-1500
* @param heading Optional. For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
* @param proximityAlertRadius Optional. For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendLocation(boost::variant<std::int64_t, const std::string&> chatId,
+ Message::Ptr sendLocation(boost::variant<std::int64_t, std::string> chatId,
float latitude,
float longitude,
std::int32_t livePeriod = 0,
@@ -499,6 +528,7 @@ public:
/**
* @brief Use this method to edit live location messages.
+ *
* A location can be edited until its livePeriod expires or editing is explicitly disabled by a call to Api::stopMessageLiveLocation.
*
* @param latitude Latitude of new location
@@ -509,29 +539,33 @@ public:
* @param replyMarkup Optional. A JSON-serialized object for a new inline keyboard.
* @param horizontalAccuracy Optional. The radius of uncertainty for the location, measured in meters; 0-1500
* @param heading Optional. Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
- * @param proximityAlertRadius Optional. Maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
+ * @param proximityAlertRadius Optional. The maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
*
- * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
+ * @return On success, the edited Message is returned.
*/
Message::Ptr editMessageLiveLocation(float latitude,
float longitude,
- std::int64_t chatId = 0,
+ boost::variant<std::int64_t, std::string> chatId = "",
std::int32_t messageId = 0,
- std::int32_t inlineMessageId = 0,
+ const std::string& inlineMessageId = "",
InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared<InlineKeyboardMarkup>(),
float horizontalAccuracy = 0,
std::int32_t heading = 0,
std::int32_t proximityAlertRadius = 0) const;
/**
- * @brief Use this method to edit live location messages sent by the bot or via the bot (for inline bots).
- * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat of the target channel.
- * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message.
- * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message.
+ * @brief Use this method to stop updating a live location message before livePeriod expires.
+ *
+ * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message with live location to stop
+ * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message
* @param replyMarkup Optional. A JSON-serialized object for a new inline keyboard.
- * @return On success, if the edited message was sent by the bot, the edited Message is returned, otherwise nullptr is returned.
+ *
+ * @return On success, the edited Message is returned.
*/
- Message::Ptr stopMessageLiveLocation(std::int64_t chatId = 0, std::int32_t messageId = 0, std::int32_t inlineMessageId = 0,
+ Message::Ptr stopMessageLiveLocation(boost::variant<std::int64_t, std::string> chatId = "",
+ std::int32_t messageId = 0,
+ const std::string& inlineMessageId = "",
InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared<InlineKeyboardMarkup>()) const;
/**
@@ -549,12 +583,12 @@ public:
* @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
* @param googlePlaceId Optional. Google Places identifier of the venue
* @param googlePlaceType Optional. Google Places type of the venue. (See https://developers.google.com/places/web-service/supported_types)
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendVenue(boost::variant<std::int64_t, const std::string&> chatId,
+ Message::Ptr sendVenue(boost::variant<std::int64_t, std::string> chatId,
float latitude,
float longitude,
const std::string& title,
@@ -580,12 +614,12 @@ public:
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message
* @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove keyboard or to force a reply from the user.
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendContact(boost::variant<std::int64_t, const std::string&> chatId,
+ Message::Ptr sendContact(boost::variant<std::int64_t, std::string> chatId,
const std::string& phoneNumber,
const std::string& firstName,
const std::string& lastName = "",
@@ -615,12 +649,12 @@ public:
* @param openPeriod Optional. Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with closeDate.
* @param closeDate Optional. Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with openPeriod.
* @param isClosed Optional. Pass True, if the poll needs to be immediately closed. This can be useful for poll preview.
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendPoll(boost::variant<std::int64_t, const std::string&> chatId,
+ Message::Ptr sendPoll(boost::variant<std::int64_t, std::string> chatId,
const std::string& question,
const std::vector<std::string>& options,
bool disableNotification = false,
@@ -629,7 +663,7 @@ public:
bool isAnonymous = true,
const std::string& type = "",
bool allowsMultipleAnswers = false,
- std::int32_t correctOptionId = 0,
+ std::int32_t correctOptionId = -1,
const std::string& explanation = "",
const std::string& explanationParseMode = "",
const std::vector<MessageEntity::Ptr>& explanationEntities = std::vector<MessageEntity::Ptr>(),
@@ -647,12 +681,12 @@ public:
* @param replyToMessageId Optional. If the message is a reply, ID of the original message
* @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
* @param emoji Optional. Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Dice can have values 1-6 for “🎲”, “🎯” and “🎳”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲”
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendDice(boost::variant<std::int64_t, const std::string&> chatId,
+ Message::Ptr sendDice(boost::variant<std::int64_t, std::string> chatId,
bool disableNotification = false,
std::int32_t replyToMessageId = 0,
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
@@ -680,64 +714,74 @@ public:
/**
* @brief Use this method to get a list of profile pictures for a user.
- * @param userId Unique identifier of the target user.
+ *
+ * @param userId Unique identifier of the target user
* @param offset Optional. Sequential number of the first photo to be returned. By default, all photos are returned.
- * @param limit Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
- * @return A UserProfilePhotos object.
+ * @param limit Optional. Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.
+ *
+ * @return Returns a UserProfilePhotos object.
*/
- UserProfilePhotos::Ptr getUserProfilePhotos(std::int64_t userId, std::int32_t offset = 0, std::int32_t limit = 100) const;
+ UserProfilePhotos::Ptr getUserProfilePhotos(std::int64_t userId,
+ std::int32_t offset = 0,
+ std::int32_t limit = 100) const;
/**
- * @brief Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size.
- * @param fileId File identifier to get info about
- * @return A File object.
+ * @brief Use this method to get basic information about a file and prepare it for downloading.
+ *
+ * For the moment, bots can download files of up to 20MB in size.
+ * The file can then be downloaded via Api::downloadFile, where filePath is taken from the response.
+ * It is guaranteed that the filePath will be valid for at least 1 hour.
+ * When the link expires, a new one can be requested by calling Api::getFile again.
+ *
+ * This function may not preserve the original file name and MIME type.
+ * You should save the file's MIME type and name (if available) when the File object is received.
+ *
+ * @param fileId File identifier to get information about
+ *
+ * @return On success, a File object is returned.
*/
File::Ptr getFile(const std::string& fileId) const;
/**
- * @brief Downloads file from Telegram and saves it in memory.
- * @param filePath Telegram file path.
- * @param args Additional api parameters.
- * @return File contents in a string.
- */
- std::string downloadFile(const std::string& filePath, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
-
- /**
- * @brief Use this method to kick a user from a group, a supergroup or a channel.
+ * @brief Use this method to ban a user in a group, a supergroup or a channel.
+ *
* In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first.
- * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
*
* @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
* @param userId Unique identifier of the target user
* @param untilDate Optional. Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.
* @param revokeMessages Optional. Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.
*
- * @return True on success.
+ * @return Returns True on success.
*/
- bool banChatMember(std::int64_t chatId,
+ bool banChatMember(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId,
- std::uint64_t untilDate = 0,
+ std::int32_t untilDate = 0,
bool revokeMessages = true) const;
/**
- * @brief Use this method to unban a previously kicked user in a supergroup or channel.
+ * @brief Use this method to unban a previously banned user in a supergroup or channel.
*
* The user will not return to the group or channel automatically, but will be able to join via link, etc.
* The bot must be an administrator for this to work.
* By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it.
* So if the user is a member of the chat they will also be removed from the chat.
- * If you don't want this, use the parameter only_if_banned.
+ * If you don't want this, use the parameter onlyIfBanned.
*
- * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @username)
+ * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
* @param userId Unique identifier of the target user
- * @param onlyIfBanned Optional. True = Do nothing if the user is not banned
+ * @param onlyIfBanned Optional. Pass True to do nothing if the user is not banned
*
- * @return True on success
+ * @return Returns True on success.
*/
- bool unbanChatMember(std::int64_t chatId, std::int64_t userId, bool onlyIfBanned = false) const;
+ bool unbanChatMember(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t userId,
+ bool onlyIfBanned = false) const;
/**
* @brief Use this method to restrict a user in a supergroup.
+ *
* The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights.
* Pass True for all permissions to lift restrictions from a user.
*
@@ -746,12 +790,12 @@ public:
* @param permissions A JSON-serialized object for new user permissions
* @param untilDate Optional. Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever
*
- * @return True on success
+ * @return Returns True on success.
*/
- bool restrictChatMember(std::int64_t chatId,
+ bool restrictChatMember(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId,
ChatPermissions::Ptr permissions,
- std::uint64_t untilDate = 0) const;
+ std::int64_t untilDate = 0) const;
/**
* @brief Use this method to promote or demote a user in a supergroup or a channel.
@@ -775,7 +819,7 @@ public:
*
* @return Returns True on success.
*/
- bool promoteChatMember(boost::variant<std::int64_t, const std::string&> chatId,
+ bool promoteChatMember(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId,
bool canChangeInfo = false,
bool canPostMessages = false,
@@ -796,25 +840,29 @@ public:
* @param userId Unique identifier of the target user
* @param customTitle New custom title for the administrator; 0-16 characters, emoji are not allowed
*
- * @return True on success
+ * @return Returns True on success.
*/
- bool setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const;
+ bool setChatAdministratorCustomTitle(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t userId,
+ const std::string& customTitle) const;
/**
* @brief Use this method to ban a channel chat in a supergroup or a channel.
+ *
* Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels.
* The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param senderChatId Unique identifier of the target sender chat
*
- * @return True on success.
+ * @return Returns True on success.
*/
- bool banChatSenderChat(std::int64_t chatId,
+ bool banChatSenderChat(boost::variant<std::int64_t, std::string> chatId,
std::int64_t senderChatId) const;
/**
* @brief Use this method to unban a previously banned channel chat in a supergroup or channel.
+ *
* The bot must be an administrator for this to work and must have the appropriate administrator rights.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@@ -822,38 +870,53 @@ public:
*
* @return Returns True on success.
*/
- bool unbanChatSenderChat(std::int64_t chatId,
+ bool unbanChatSenderChat(boost::variant<std::int64_t, std::string> chatId,
std::int64_t senderChatId) const;
/**
- * @brief Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success.
- * @param chatId Unique identifier for the target chat of the target supergroup.
- * @param permissions New default chat permissions.
- * @return True on success
+ * @brief Use this method to set default chat permissions for all members.
+ *
+ * The bot must be an administrator in the group or a supergroup for this to work and must have the canRestrictMembers administrator rights.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
+ * @param permissions A JSON-serialized object for new default chat permissions
+ *
+ * @return Returns True on success.
*/
- bool setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const;
+ bool setChatPermissions(boost::variant<std::int64_t, std::string> chatId,
+ ChatPermissions::Ptr permissions) const;
/**
- * @brief Use this method to generate a new invite link for a chat; any previously generated link is revoked.
- * @param chatId Unique identifier for the target chat.
- * @return The new invite link as String on success.
+ * @brief Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked.
+ *
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
+ *
+ * Each administrator in a chat generates their own invite links.
+ * Bots can't use invite links generated by other administrators.
+ * If you want your bot to work with invite links, it will need to generate its own link using Api::exportChatInviteLink or by calling the Api::getChat method.
+ * If your bot needs to generate a new primary invite link replacing its previous one, use Api::exportChatInviteLink again.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ *
+ * @return Returns the new invite link as String on success.
*/
- std::string exportChatInviteLink(std::int64_t chatId) const;
+ std::string exportChatInviteLink(boost::variant<std::int64_t, std::string> chatId) const;
/**
* @brief Use this method to create an additional invite link for a chat.
- * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
+ *
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
* The link can be revoked using the method Api::revokeChatInviteLink.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param expireDate Optional. Point in time (Unix timestamp) when the link will expire
- * @param memberLimit Optional. Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
+ * @param memberLimit Optional. The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
* @param name Optional. Invite link name; 0-32 characters
* @param createsJoinRequest Optional. True, if users joining the chat via the link need to be approved by chat administrators. If True, memberLimit can't be specified
*
- * @return the new invite link as ChatInviteLink object.
+ * @return Returns the new invite link as ChatInviteLink object.
*/
- ChatInviteLink::Ptr createChatInviteLink(std::int64_t chatId,
+ ChatInviteLink::Ptr createChatInviteLink(boost::variant<std::int64_t, std::string> chatId,
std::int32_t expireDate = 0,
std::int32_t memberLimit = 0,
const std::string& name = "",
@@ -861,7 +924,8 @@ public:
/**
* @brief Use this method to edit a non-primary invite link created by the bot.
- * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
+ *
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param inviteLink The invite link to edit
@@ -870,9 +934,9 @@ public:
* @param name Optional. Invite link name; 0-32 characters
* @param createsJoinRequest Optional. True, if users joining the chat via the link need to be approved by chat administrators. If True, memberLimit can't be specified
*
- * @return the edited invite link as a ChatInviteLink object.
+ * @return Returns the edited invite link as a ChatInviteLink object.
*/
- ChatInviteLink::Ptr editChatInviteLink(std::int64_t chatId,
+ ChatInviteLink::Ptr editChatInviteLink(boost::variant<std::int64_t, std::string> chatId,
const std::string& inviteLink,
std::int32_t expireDate = 0,
std::int32_t memberLimit = 0,
@@ -881,31 +945,34 @@ public:
/**
* @brief Use this method to revoke an invite link created by the bot.
+ *
* If the primary link is revoked, a new link is automatically generated.
- * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
*
- * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param chatId Unique identifier of the target chat or username of the target channel (in the format @channelusername)
* @param inviteLink The invite link to revoke
*
- * @return the revoked invite link as ChatInviteLink object.
+ * @return Returns the revoked invite link as ChatInviteLink object.
*/
- ChatInviteLink::Ptr revokeChatInviteLink(std::int64_t chatId,
+ ChatInviteLink::Ptr revokeChatInviteLink(boost::variant<std::int64_t, std::string> chatId,
const std::string& inviteLink) const;
/**
* @brief Use this method to approve a chat join request.
+ *
* The bot must be an administrator in the chat for this to work and must have the canInviteUsers administrator right.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param userId Unique identifier of the target user
*
- * @return True on success.
+ * @return Returns True on success.
*/
- bool approveChatJoinRequest(std::int64_t chatId,
+ bool approveChatJoinRequest(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId) const;
/**
* @brief Use this method to decline a chat join request.
+ *
* The bot must be an administrator in the chat for this to work and must have the canInviteUsers administrator right.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@@ -913,154 +980,207 @@ public:
*
* @return True on success.
*/
- bool declineChatJoinRequest(std::int64_t chatId,
+ bool declineChatJoinRequest(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId) const;
/**
* @brief Use this method to set a new profile photo for the chat.
*
* Photos can't be changed for private chats.
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
*
- * @param chatId Unique identifier for the target chat.
- * @param photo New chat photo.
- * @return True on success
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param photo New chat photo, uploaded using multipart/form-data
+ *
+ * @return Returns True on success.
*/
- bool setChatPhoto(std::int64_t chatId, InputFile::Ptr photo) const;
+ bool setChatPhoto(boost::variant<std::int64_t, std::string> chatId,
+ InputFile::Ptr photo) const;
/**
* @brief Use this method to delete a chat photo.
*
* Photos can't be changed for private chats.
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
*
- * @param chatId Unique identifier for the target chat.
- * @return True on success
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ *
+ * @return Returns True on success.
*/
- bool deleteChatPhoto(std::int64_t chatId) const;
+ bool deleteChatPhoto(boost::variant<std::int64_t, std::string> chatId) const;
/**
* @brief Use this method to change the title of a chat.
*
* Titles can't be changed for private chats.
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
*
- * @param chatId Unique identifier for the target chat.
- * @param title New chat title, 1-255 characters.
- * @return True on success
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param title New chat title, 1-255 characters
+ *
+ * @return Returns True on success.
*/
- bool setChatTitle(std::int64_t chatId, const std::string& title) const;
+ bool setChatTitle(boost::variant<std::int64_t, std::string> chatId,
+ const std::string& title) const;
/**
- * @brief Use this method to change the description of a supergroup or a channel.
- * @param chatId Unique identifier for the target chat.
- * @param description New chat description, 1-255 characters.
- * @return True on success
+ * @brief Use this method to change the description of a group, a supergroup or a channel.
+ *
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param description New chat description, 0-255 characters
+ *
+ * @return Returns True on success.
*/
- bool setChatDescription(std::int64_t chatId, const std::string& description) const;
+ bool setChatDescription(boost::variant<std::int64_t, std::string> chatId,
+ const std::string& description = "") const;
/**
- * @brief Use this method to pin a message in a group, a supergroup, or a channel.
- * @param chatId Unique identifier for the target chat or username of the target channel.
- * @param messageId Identifier of a message to pin.
- * @param disableNotification Optional. Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels.
- * @return True on success
+ * @brief Use this method to add a message to the list of pinned messages in a chat.
+ *
+ * If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'canPinMessages' administrator right in a supergroup or 'canEditMessages' administrator right in a channel.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param messageId Identifier of a message to pin
+ * @param disableNotification Optional. Pass True if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats.
+ *
+ * @return Returns True on success.
*/
- bool pinChatMessage(std::int64_t chatId, std::int32_t messageId, bool disableNotification = false) const;
+ bool pinChatMessage(boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId,
+ bool disableNotification = false) const;
/**
* @brief Use this method to remove a message from the list of pinned messages in a chat.
- * If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel.
+ *
+ * If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'canPinMessages' administrator right in a supergroup or 'canEditMessages' administrator right in a channel.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param messageId Optional. Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.
*
- * @return True on success.
+ * @return Returns True on success.
*/
- bool unpinChatMessage(std::int64_t chatId, std::int32_t messageId = 0) const;
+ bool unpinChatMessage(boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId = 0) const;
/**
* @brief Use this method to clear the list of pinned messages in a chat.
- * If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel.
+ *
+ * If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'canPinMessages' administrator right in a supergroup or 'canEditMessages' administrator right in a channel.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
*
- * @return True on success.
+ * @return Returns True on success.
*/
- bool unpinAllChatMessages(std::int64_t chatId) const;
+ bool unpinAllChatMessages(boost::variant<std::int64_t, std::string> chatId) const;
/**
* @brief Use this method for your bot to leave a group, supergroup or channel.
- * @param chatId Unique identifier for the target chat of the target supergroup or channel.
- * @return True on success
+ *
+ * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
+ *
+ * @return Returns True on success.
*/
- bool leaveChat(std::int64_t chatId) const;
+ bool leaveChat(boost::variant<std::int64_t, std::string> chatId) const;
/**
* @brief Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
*
* @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
*
- * @return @ref Chat object on success.
+ * @return Returns a Chat object on success.
*/
- Chat::Ptr getChat(std::int64_t chatId) const;
+ Chat::Ptr getChat(boost::variant<std::int64_t, std::string> chatId) const;
/**
- * @brief Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
- * @param chatId Unique identifier for the target chat of the target supergroup or channel.
- * @return ChatMember object.
+ * @brief Use this method to get a list of administrators in a chat, which aren't bots.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
+ *
+ * @return Returns an Array of ChatMember objects.
*/
- std::vector<ChatMember::Ptr> getChatAdministrators(std::int64_t chatId) const;
+ std::vector<ChatMember::Ptr> getChatAdministrators(boost::variant<std::int64_t, std::string> chatId) const;
/**
* @brief Use this method to get the number of members in a chat.
*
* @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
*
- * @return Int on success.
+ * @return Returns Int on success.
*/
- std::int32_t getChatMemberCount(std::int64_t chatId) const;
+ std::int32_t getChatMemberCount(boost::variant<std::int64_t, std::string> chatId) const;
/**
- * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success.
- * @param chatId Unique identifier for the target chat of the target supergroup or channel.
+ * @brief Use this method to get information about a member of a chat.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
* @param userId Unique identifier of the target user
- * @return ChatMember object.
+ *
+ * @return Returns a ChatMember object on success.
*/
- ChatMember::Ptr getChatMember(std::int64_t chatId, std::int64_t userId) const;
+ ChatMember::Ptr getChatMember(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t userId) const;
/**
- * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success.
- * @param chatId Unique identifier for the target chat of the target supergroup or channel.
- * @param stickerSetName Name of the sticker set to be set as the group sticker set.
+ * @brief Use this method to set a new group sticker set for a supergroup.
+ *
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
+ * Use the field canSetStickerSet optionally returned in Api::getChat requests to check if the bot can use this method.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
+ * @param stickerSetName Name of the sticker set to be set as the group sticker set
+ *
* @return Returns True on success.
*/
- bool setChatStickerSet(std::int64_t chatId, const std::string& stickerSetName) const;
+ bool setChatStickerSet(boost::variant<std::int64_t, std::string> chatId,
+ const std::string& stickerSetName) const;
/**
- * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success.
- * @param chatId Unique identifier for the target chat of the target supergroup or channel.
+ * @brief Use this method to delete a group sticker set from a supergroup.
+ *
+ * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
+ * Use the field canSetSticker_set optionally returned in Api::getChat requests to check if the bot can use this method.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
+ *
* @return Returns True on success.
*/
- bool deleteChatStickerSet(std::int64_t chatId) const;
+ bool deleteChatStickerSet(boost::variant<std::int64_t, std::string> chatId) const;
/**
- * @brief Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
+ * @brief Use this method to send answers to callback queries sent from inline keyboards.
+ *
+ * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
+ *
+ * Alternatively, the user can be redirected to the specified Game URL.
+ * For this option to work, you must first create a game for your bot via @BotFather and accept the terms.
+ * Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
+ *
* @param callbackQueryId Unique identifier for the query to be answered
- * @param text Optional Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
- * @param showAlert Optional If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
- * @param url Optional URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @Botfather, specify the URL that opens your game – note that this will only work if the query comes from a callback_game button
- * @param cacheTime Optional The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
- * @return True on success
+ * @param text Optional. Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
+ * @param showAlert Optional. If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
+ * @param url Optional. URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @BotFather, specify the URL that opens your game - note that this will only work if the query comes from an InlineKeyboardButton button.
+ * @param cacheTime Optional. The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
+ *
+ * @return On success, True is returned.
*/
- bool answerCallbackQuery(const std::string& callbackQueryId, const std::string& text = "", bool showAlert = false, const std::string& url = "", std::int32_t cacheTime = 0) const;
+ bool answerCallbackQuery(const std::string& callbackQueryId,
+ const std::string& text = "",
+ bool showAlert = false,
+ const std::string& url = "",
+ std::int32_t cacheTime = 0) const;
/**
* @brief Use this method to change the list of the bot's commands.
+ *
* See https://core.telegram.org/bots#commands for more details about bot commands.
*
* @param commands A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
* @param scope Optional. A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
* @param languageCode Optional. A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
*
- * @return True on success.
+ * @return Returns True on success.
*/
bool setMyCommands(const std::vector<BotCommand::Ptr>& commands,
BotCommandScope::Ptr scope = nullptr,
@@ -1068,12 +1188,13 @@ public:
/**
* @brief Use this method to delete the list of the bot's commands for the given scope and user language.
+ *
* After deletion, higher level commands will be shown to affected users.
*
* @param scope Optional. A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
* @param languageCode Optional. A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
*
- * @return True on success.
+ * @return Returns True on success.
*/
bool deleteMyCommands(BotCommandScope::Ptr scope = nullptr,
const std::string& languageCode = "") const;
@@ -1084,7 +1205,7 @@ public:
* @param scope Optional. A JSON-serialized object, describing scope of users. Defaults to BotCommandScopeDefault.
* @param languageCode Optional. A two-letter ISO 639-1 language code or an empty string
*
- * @return Array of BotCommand on success. If commands aren't set, an empty list is returned.
+ * @return Returns an Array of BotCommand objects. If commands aren't set, an empty list is returned.
*/
std::vector<BotCommand::Ptr> getMyCommands(BotCommandScope::Ptr scope = nullptr,
const std::string& languageCode = "") const;
@@ -1093,7 +1214,7 @@ public:
* @brief Use this method to change the bot's menu button in a private chat, or the default menu button.
*
* @param chatId Optional. Unique identifier for the target private chat. If not specified, default bot's menu button will be changed
- * @param menuButton Optional. A JSON-serialized object for the new bot's menu button. Defaults to MenuButtonDefault
+ * @param menuButton Optional. A JSON-serialized object for the bot's new menu button. Defaults to MenuButtonDefault
*
* @return Returns True on success.
*/
@@ -1143,10 +1264,10 @@ public:
* @param replyMarkup Optional. A JSON-serialized object for an inline keyboard.
* @param entities Optional. List of special entities that appear in message text, which can be specified instead of parseMode
*
- * @return On success, the edited Message is returned.
+ * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned.
*/
Message::Ptr editMessageText(const std::string& text,
- std::int64_t chatId = 0,
+ boost::variant<std::int64_t, std::string> chatId = 0,
std::int32_t messageId = 0,
const std::string& inlineMessageId = "",
const std::string& parseMode = "",
@@ -1165,9 +1286,9 @@ public:
* @param parseMode Optional. Mode for parsing entities in the message caption. See https://core.telegram.org/bots/api#formatting-options for more details.
* @param captionEntities Optional. List of special entities that appear in the caption, which can be specified instead of parseMode
*
- * @return On success, the edited Message is returned.
+ * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned.
*/
- Message::Ptr editMessageCaption(std::int64_t chatId = 0,
+ Message::Ptr editMessageCaption(boost::variant<std::int64_t, std::string> chatId = 0,
std::int32_t messageId = 0,
const std::string& caption = "",
const std::string& inlineMessageId = "",
@@ -1176,67 +1297,87 @@ public:
const std::vector<MessageEntity::Ptr>& captionEntities = std::vector<MessageEntity::Ptr>()) const;
/**
- * @brief Use this method to edit audio, document, photo, or video messages.
- *
+ * @brief Use this method to edit animation, 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 fileId or specify a URL.
+ * If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise.
+ * When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its fileId 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.
+ * @param media A JSON-serialized object for a new media content of the message
+ * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message to edit
+ * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message
+ * @param replyMarkup Optional. A JSON-serialized object for a new inline keyboard.
+ *
+ * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned.
*/
- Message::Ptr editMessageMedia(InputMedia::Ptr media, std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "",
+ Message::Ptr editMessageMedia(InputMedia::Ptr media,
+ boost::variant<std::int64_t, std::string> chatId = 0,
+ std::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
- * @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 Message object on success, otherwise nullptr
+ * @brief Use this method to edit only the reply markup of messages.
+ *
+ * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message to edit
+ * @param inlineMessageId Optional. Required if chatId and messageId 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 is not an inline message, the edited Message is returned, otherwise nullptr is returned.
*/
- Message::Ptr editMessageReplyMarkup(std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "",
+ Message::Ptr editMessageReplyMarkup(boost::variant<std::int64_t, std::string> chatId = 0,
+ std::int32_t messageId = 0,
+ const std::string& inlineMessageId = "",
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const;
/**
* @brief Use this method to stop a poll which was sent by the bot.
- * @param chatId Unique identifier for the target chat or username of the target channel.
- * @param messageId Identifier of the original message with the poll.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param messageId Identifier of the original message with the poll
* @param replyMarkup Optional. A JSON-serialized object for a new message inline keyboard.
*
- * @return On success, the stopped Poll with the final results is returned.
+ * @return On success, the stopped Poll is returned.
*/
-
- Poll::Ptr stopPoll(std::int64_t chatId, std::int64_t messageId, InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared<InlineKeyboardMarkup>()) const;
+ Poll::Ptr stopPoll(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t messageId,
+ InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared<InlineKeyboardMarkup>()) const;
/**
- * @brief Use this method to delete messages sent by bot (or by other users if bot is admin).
- * @param chatId Unique identifier for the target chat or username of the target channel.
- * @param messageId Unique identifier for the target message.
+ * @brief Use this method to delete a message, including service messages, with the following limitations:
+ *
+ * - A message can only be deleted if it was sent less than 48 hours ago.
+ * - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
+ * - Bots can delete outgoing messages in private chats, groups, and supergroups.
+ * - Bots can delete incoming messages in private chats.
+ * - Bots granted canPostMessages permissions can delete outgoing messages in channels.
+ * - If the bot is an administrator of a group, it can delete any message there.
+ * - If the bot has canDeleteMessages permission in a supergroup or a channel, it can delete any message there.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param messageId Identifier of the message to delete
+ *
+ * @return Returns True on success.
*/
- void deleteMessage(std::int64_t chatId, std::int32_t messageId) const;
+ bool deleteMessage(boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId) const;
/**
- * @brief Use this method to send static .WEBP or animated .TGS stickers.
+ * @brief Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers.
*
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param sticker Sticker to send. Pass a fileId as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP file from the Internet, or upload a new one using multipart/form-data. https://core.telegram.org/bots/api#sending-files
* @param replyToMessageId Optional. If the message is a reply, ID of the original message
* @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendSticker(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> sticker,
+ Message::Ptr sendSticker(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> sticker,
std::int32_t replyToMessageId = 0,
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
bool disableNotification = false,
@@ -1262,12 +1403,15 @@ public:
std::vector<Sticker::Ptr> getCustomEmojiStickers(const std::vector<std::string>& customEmojiIds) const;
/**
- * @brief 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.
+ * @brief Use this method to upload a .PNG file with a sticker for later use in Api::createNewStickerSet and Api::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. https://core.telegram.org/bots/api#sending-files
+ *
* @return Returns the uploaded File on success.
*/
- File::Ptr uploadStickerFile(std::int64_t userId, InputFile::Ptr pngSticker) const;
+ 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.
@@ -1292,7 +1436,7 @@ public:
const std::string& title,
const std::string& emojis,
MaskPosition::Ptr maskPosition = nullptr,
- boost::variant<InputFile::Ptr, const std::string&> pngSticker = "",
+ boost::variant<InputFile::Ptr, std::string> pngSticker = "",
InputFile::Ptr tgsSticker = nullptr,
InputFile::Ptr webmSticker = nullptr,
const std::string& stickerType = "") const;
@@ -1300,7 +1444,7 @@ public:
/**
* @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.
+ * You must use exactly one of the fields pngSticker, tgsSticker, or webmSticker.
* 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.
@@ -1319,7 +1463,7 @@ public:
const std::string& name,
const std::string& emojis,
MaskPosition::Ptr maskPosition = nullptr,
- boost::variant<InputFile::Ptr, const std::string&> pngSticker = "",
+ boost::variant<InputFile::Ptr, std::string> pngSticker = "",
InputFile::Ptr tgsSticker = nullptr,
InputFile::Ptr webmSticker = nullptr) const;
@@ -1329,45 +1473,58 @@ public:
* @param sticker File identifier of the sticker
* @param position New sticker position in the set, zero-based
*
- * @return True on success.
+ * @return Returns True on success.
*/
bool setStickerPositionInSet(const std::string& sticker,
- std::uint32_t position) const;
+ std::int32_t position) const;
/**
* @brief Use this method to delete a sticker from a set created by the bot.
*
* @param sticker File identifier of the sticker
*
- * @return True on success.
+ * @return Returns True on success.
*/
bool deleteStickerFromSet(const std::string& sticker) const;
/**
- * @brief Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only.
+ * @brief Use this method to set the thumbnail of a sticker set.
+ *
+ * Animated thumbnails can be set for animated sticker sets only.
+ * Video thumbnails can be set only for video sticker sets only.
*
* @param name Sticker set name
* @param userId User identifier of the sticker set owner
- * @param thumb Optional. A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/animated_stickers#technical-requirements for animated sticker technical requirements. 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. Animated sticker set thumbnail can't be uploaded via HTTP URL.
+ * @param thumb Optional. A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements, or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. 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. Animated sticker set thumbnails can't be uploaded via HTTP URL.
*
* @return Returns True on success.
*/
- bool setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant<InputFile::Ptr, std::string> thumb = "") const;
+ bool setStickerSetThumb(const std::string& name,
+ std::int64_t userId,
+ boost::variant<InputFile::Ptr, std::string> thumb = "") const;
/**
* @brief Use this method to send answers to an inline query.
- * No mode that 50 results per query are allowed.
- * @param inlineQueryId Unique identifier for the answered query.
- * @param results Array of results for the inline query.
- * @param cacheTime The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
- * @param isPersonal Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.
- * @param nextOffset Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.
- * @param switchPmText If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter
- * @param switchPmParameter Parameter for the start message sent to the bot when user presses the switch button
- * @return True on success
+ *
+ * No more than 50 results per query are allowed.
+ *
+ * @param inlineQueryId Unique identifier for the answered query
+ * @param results A JSON-serialized array of results for the inline query
+ * @param cacheTime Optional. The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
+ * @param isPersonal Optional. Pass True if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
+ * @param nextOffset Optional. Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes.
+ * @param switchPmText Optional. If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switchPmParameter
+ * @param switchPmParameter Optional. Deep-linking parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed. Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an OAuth link. Once done, the bot can offer an InlineKeyboardMarkup button so that the user can easily return to the chat where they wanted to use the bot's inline capabilities.
+ *
+ * @return On success, True is returned.
*/
- bool answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
- std::int32_t cacheTime = 300, bool isPersonal = false, const std::string& nextOffset = "", const std::string& switchPmText = "", const std::string& switchPmParameter = "") const;
+ bool answerInlineQuery(const std::string& inlineQueryId,
+ const std::vector<InlineQueryResult::Ptr>& results,
+ std::int32_t cacheTime = 300,
+ bool isPersonal = false,
+ const std::string& nextOffset = "",
+ const std::string& switchPmText = "",
+ const std::string& switchPmParameter = "") const;
/**
* @brief Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated.
@@ -1413,7 +1570,7 @@ public:
*
* @return On success, the sent Message is returned.
*/
- Message::Ptr sendInvoice(boost::variant<std::int64_t, const std::string&> chatId,
+ Message::Ptr sendInvoice(boost::variant<std::int64_t, std::string> chatId,
const std::string& title,
const std::string& description,
const std::string& payload,
@@ -1491,15 +1648,19 @@ public:
/**
* @brief Use this method to reply to shipping queries.
*
- * If you sent an invoice requesting a shipping address and the parameter isFlexible was specified, the Bot API will send an Update with a shipping_query field to the bot.
+ * If you sent an invoice requesting a shipping address and the parameter isFlexible was specified, the Bot API will send an Update with a shippingQuery field to the bot.
*
- * @param shippingQueryId Unique identifier for the query to be answered.
- * @param ok Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
+ * @param shippingQueryId Unique identifier for the query to be answered
+ * @param ok Pass True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
* @param shippingOptions Optional. Required if ok is True. A JSON-serialized array of available shipping options.
* @param errorMessage Optional. Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
+ *
* @return On success, True is returned.
*/
- bool answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector<ShippingOption::Ptr>& shippingOptions = std::vector<ShippingOption::Ptr>(), const std::string& errorMessage = "") const;
+ bool answerShippingQuery(const std::string& shippingQueryId,
+ bool ok,
+ const std::vector<ShippingOption::Ptr>& shippingOptions = std::vector<ShippingOption::Ptr>(),
+ const std::string& errorMessage = "") const;
/**
* @brief Use this method to respond to such pre-checkout queries.
@@ -1510,9 +1671,12 @@ public:
* @param preCheckoutQueryId Unique identifier for the query to be answered
* @param ok Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
* @param errorMessage Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
+ *
* @return On success, True is returned.
*/
- bool answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage = "") const;
+ bool answerPreCheckoutQuery(const std::string& preCheckoutQueryId,
+ bool ok,
+ const std::string& errorMessage = "") const;
/**
* @brief Informs a user that some of the Telegram Passport elements they provided contains errors.
@@ -1525,19 +1689,20 @@ public:
* @param userId User identifier
* @param errors A JSON-serialized array describing the errors
*
- * @return True on success.
+ * @return Returns True on success.
*/
- bool setPassportDataErrors(std::int64_t userId, const std::vector<PassportElementError::Ptr>& errors) const;
+ bool setPassportDataErrors(std::int64_t userId,
+ const std::vector<PassportElementError::Ptr>& errors) const;
/**
* @brief Use this method to send a game.
*
* @param chatId Unique identifier for the target chat
- * @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
+ * @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via @BotFather.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message
* @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one 'Play gameTitle' button will be shown. If not empty, the first button must launch the game.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
- * @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found
* @param protectContent Optional. Protects the contents of the sent message from forwarding and saving
*
* @return On success, the sent Message is returned.
@@ -1551,28 +1716,35 @@ public:
bool protectContent = false) const;
/**
- * @brief Use this method to set the score of the specified user in a game.
+ * @brief Use this method to set the score of the specified user in a game message.
*
* Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
*
- * @param userId User identifier.
- * @param score New score, must be non-negative.
- * @param force Optional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters.
- * @param disableEditMessage Optional. Pass True, if the game message should not be automatically edited to include the current scoreboard.
+ * @param userId User identifier
+ * @param score New score, must be non-negative
+ * @param force Optional. Pass True if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
+ * @param disableEditMessage Optional. Pass True if the game message should not be automatically edited to include the current scoreboard
* @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat
* @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message
* @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message
- * @return On success, if the message was sent by the bot, returns the edited Message, otherwise returns nullptr.
+ *
+ * @return On success, if the message is not an inline message, the Message is returned, otherwise nullptr is returned.
*/
- Message::Ptr setGameScore(std::int64_t userId, std::int32_t score, bool force = false, bool disableEditMessage = false,
- std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "") const;
+ Message::Ptr setGameScore(std::int64_t userId,
+ std::int32_t score,
+ bool force = false,
+ bool disableEditMessage = false,
+ std::int64_t chatId = 0,
+ std::int32_t messageId = 0,
+ const std::string& inlineMessageId = "") const;
/**
* @brief Use this method to get data for high score tables.
+ *
* Will return the score of the specified user and several of their neighbors in a game.
*
* This method will currently return scores for the target user, plus two of their closest neighbors on each side.
- * Will also return the top three users if the user and his neighbors are not among them.
+ * Will also return the top three users if the user and their neighbors are not among them.
* Please note that this behavior is subject to change.
*
* @param userId Target user id
@@ -1580,12 +1752,32 @@ public:
* @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message
* @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message
*
- * @return On success, returns an Array of GameHighScore objects.
+ * @return Returns an Array of GameHighScore objects.
*/
std::vector<GameHighScore::Ptr> getGameHighScores(std::int64_t userId,
std::int64_t chatId = 0,
std::int32_t messageId = 0,
const std::string& inlineMessageId = "") const;
+
+ /**
+ * @brief Download a file from Telegram and save it in memory.
+ *
+ * @param filePath Telegram file path from Api::getFile
+ * @param args Additional api parameters
+ *
+ * @return File content in a string.
+ */
+ std::string downloadFile(const std::string& filePath,
+ const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
+
+ /**
+ * @brief Check if user has blocked the bot
+ *
+ * @param chatId Unique identifier for the target chat
+ *
+ * @return Returns True if bot is blocked by user
+ */
+ bool blockedByUser(std::int64_t chatId) const;
private:
boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h
index 44cad96..8773f35 100644
--- a/include/tgbot/EventBroadcaster.h
+++ b/include/tgbot/EventBroadcaster.h
@@ -6,12 +6,18 @@
#include "tgbot/types/InlineQuery.h"
#include "tgbot/types/ChosenInlineResult.h"
#include "tgbot/types/CallbackQuery.h"
+#include "tgbot/types/ShippingQuery.h"
+#include "tgbot/types/PreCheckoutQuery.h"
+#include "tgbot/types/Poll.h"
+#include "tgbot/types/PollAnswer.h"
+#include "tgbot/types/ChatMemberUpdated.h"
+#include "tgbot/types/ChatJoinRequest.h"
+#include <functional>
#include <initializer_list>
#include <string>
-#include <functional>
-#include <vector>
#include <unordered_map>
+#include <vector>
namespace TgBot {
@@ -31,9 +37,15 @@ public:
typedef std::function<void (const InlineQuery::Ptr)> InlineQueryListener;
typedef std::function<void (const ChosenInlineResult::Ptr)> ChosenInlineResultListener;
typedef std::function<void (const CallbackQuery::Ptr)> CallbackQueryListener;
+ typedef std::function<void (const ShippingQuery::Ptr)> ShippingQueryListener;
+ typedef std::function<void (const PreCheckoutQuery::Ptr)> PreCheckoutQueryListener;
+ typedef std::function<void (const Poll::Ptr)> PollListener;
+ typedef std::function<void (const PollAnswer::Ptr)> PollAnswerListener;
+ typedef std::function<void (const ChatMemberUpdated::Ptr)> ChatMemberUpdatedListener;
+ typedef std::function<void (const ChatJoinRequest::Ptr)> ChatJoinRequestListener;
/**
- * @brief Registers listener which receives all messages which the bot can ever receive.
+ * @brief Registers listener which receives new incoming message of any kind - text, photo, sticker, etc.
* @param listener Listener.
*/
inline void onAnyMessage(const MessageListener& listener) {
@@ -43,21 +55,30 @@ public:
/**
* @brief Registers listener which receives all messages with commands (messages with leading '/' char).
* @param commandName Command name which listener can handle.
- * @param listener Listener.
+ * @param listener Listener. Pass nullptr to remove listener of command
*/
inline void onCommand(const std::string& commandName, const MessageListener& listener) {
- _onCommandListeners[commandName] = listener;
+ if (listener) {
+ _onCommandListeners[commandName] = listener;
+ } else {
+ _onCommandListeners.erase(commandName);
+ }
}
/**
* @brief Registers listener which receives all messages with commands (messages with leading '/' char).
* @param commandsList Commands names which listener can handle.
- * @param listener Listener.
+ * @param listener Listener. Pass nullptr to remove listener of commands
*/
inline void onCommand(const std::initializer_list<std::string>& commandsList, const MessageListener& listener) {
- for (const auto& command : commandsList)
- {
- _onCommandListeners[command] = listener;
+ if (listener) {
+ for (const auto& command : commandsList) {
+ _onCommandListeners[command] = listener;
+ }
+ } else {
+ for (const auto& command : commandsList) {
+ _onCommandListeners.erase(command);
+ }
}
}
@@ -78,7 +99,15 @@ public:
}
/**
- * @brief Registers listener which receives all the inline query.
+ * @brief Registers listener which receives new versions of a message that is known to the bot and was edited
+ * @param listener Listener.
+ */
+ inline void onEditedMessage(const MessageListener& listener) {
+ _onEditedMessageListeners.push_back(listener);
+ }
+
+ /**
+ * @brief Registers listener which receives new incoming inline queries
* @param listener Listener.
*/
inline void onInlineQuery(const InlineQueryListener& listener) {
@@ -86,17 +115,93 @@ public:
}
/**
- * @brief Registers listener which receives all the chosen inline result.
+ * @brief Registers listener which receives the results of an inline query that was chosen by a user and sent to their chat partner.
+ * Please see https://core.telegram.org/bots/inline#collecting-feedback for details on how to enable these updates for your bot.
+ *
* @param listener Listener.
*/
inline void onChosenInlineResult(const ChosenInlineResultListener& listener){
_onChosenInlineResultListeners.push_back(listener);
}
+ /**
+ * @brief Registers listener which receives new incoming callback queries
+ * @param listener Listener.
+ */
inline void onCallbackQuery(const CallbackQueryListener& listener){
_onCallbackQueryListeners.push_back(listener);
}
+ /**
+ * @brief Registers listener which receives new incoming shipping queries.
+ * Only for invoices with flexible price
+ *
+ * @param listener Listener.
+ */
+ inline void onShippingQuery(const ShippingQueryListener& listener){
+ _onShippingQueryListeners.push_back(listener);
+ }
+
+ /**
+ * @brief Registers listener which receives new incoming pre-checkout queries.
+ * Contains full information about checkout
+ *
+ * @param listener Listener.
+ */
+ inline void onPreCheckoutQuery(const PreCheckoutQueryListener& listener){
+ _onPreCheckoutQueryListeners.push_back(listener);
+ }
+
+ /**
+ * @brief Registers listener which receives new poll states.
+ * Bots receive only updates about stopped polls and polls, which are sent by the bot
+ *
+ * @param listener Listener.
+ */
+ inline void onPoll(const PollListener& listener){
+ _onPollListeners.push_back(listener);
+ }
+
+ /**
+ * @brief Registers listener which receives an answer if a user changed their answer in a non-anonymous poll.
+ * Bots receive new votes only in polls that were sent by the bot itself.
+ *
+ * @param listener Listener.
+ */
+ inline void onPollAnswer(const PollAnswerListener& listener){
+ _onPollAnswerListeners.push_back(listener);
+ }
+
+ /**
+ * @brief Registers listener which receives the bot's chat member status if it was updated in a chat.
+ * For private chats, this update is received only when the bot is blocked or unblocked by the user.
+ *
+ * @param listener Listener.
+ */
+ inline void onMyChatMember(const ChatMemberUpdatedListener& listener){
+ _onMyChatMemberListeners.push_back(listener);
+ }
+
+ /**
+ * @brief Registers listener which receives a status if a chat member's status was updated in a chat.
+ * The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowedUpdates to receive these updates.
+ *
+ * @param listener Listener.
+ */
+ inline void onChatMember(const ChatMemberUpdatedListener& listener){
+ _onChatMemberListeners.push_back(listener);
+ }
+
+ /**
+ * @brief Registers listener which receives requests to join the chat.
+ * The bot must have the canInviteUsers administrator right in the chat to receive these updates.
+ *
+ * @param listener Listener.
+ */
+ inline void onChatJoinRequest(const ChatJoinRequestListener& listener){
+ _onChatJoinRequestListeners.push_back(listener);
+ }
+
private:
template<typename ListenerType, typename ObjectType>
inline void broadcast(const std::vector<ListenerType>& listeners, const ObjectType object) const {
@@ -129,6 +234,10 @@ private:
broadcast<MessageListener, Message::Ptr>(_onNonCommandMessageListeners, message);
}
+ inline void broadcastEditedMessage(const Message::Ptr& message) const {
+ broadcast<MessageListener, Message::Ptr>(_onEditedMessageListeners, message);
+ }
+
inline void broadcastInlineQuery(const InlineQuery::Ptr& query) const {
broadcast<InlineQueryListener, InlineQuery::Ptr>(_onInlineQueryListeners, query);
}
@@ -141,13 +250,49 @@ private:
broadcast<CallbackQueryListener, CallbackQuery::Ptr>(_onCallbackQueryListeners, result);
}
+ inline void broadcastShippingQuery(const ShippingQuery::Ptr& result) const {
+ broadcast<ShippingQueryListener, ShippingQuery::Ptr>(_onShippingQueryListeners, result);
+ }
+
+ inline void broadcastPreCheckoutQuery(const PreCheckoutQuery::Ptr& result) const {
+ broadcast<PreCheckoutQueryListener, PreCheckoutQuery::Ptr>(_onPreCheckoutQueryListeners, result);
+ }
+
+ inline void broadcastPoll(const Poll::Ptr& result) const {
+ broadcast<PollListener, Poll::Ptr>(_onPollListeners, result);
+ }
+
+ inline void broadcastPollAnswer(const PollAnswer::Ptr& result) const {
+ broadcast<PollAnswerListener, PollAnswer::Ptr>(_onPollAnswerListeners, result);
+ }
+
+ inline void broadcastMyChatMember(const ChatMemberUpdated::Ptr& result) const {
+ broadcast<ChatMemberUpdatedListener, ChatMemberUpdated::Ptr>(_onMyChatMemberListeners, result);
+ }
+
+ inline void broadcastChatMember(const ChatMemberUpdated::Ptr& result) const {
+ broadcast<ChatMemberUpdatedListener, ChatMemberUpdated::Ptr>(_onChatMemberListeners, result);
+ }
+
+ inline void broadcastChatJoinRequest(const ChatJoinRequest::Ptr& result) const {
+ broadcast<ChatJoinRequestListener, ChatJoinRequest::Ptr>(_onChatJoinRequestListeners, result);
+ }
+
std::vector<MessageListener> _onAnyMessageListeners;
std::unordered_map<std::string, MessageListener> _onCommandListeners;
std::vector<MessageListener> _onUnknownCommandListeners;
std::vector<MessageListener> _onNonCommandMessageListeners;
+ std::vector<MessageListener> _onEditedMessageListeners;
std::vector<InlineQueryListener> _onInlineQueryListeners;
std::vector<ChosenInlineResultListener> _onChosenInlineResultListeners;
std::vector<CallbackQueryListener> _onCallbackQueryListeners;
+ std::vector<ShippingQueryListener> _onShippingQueryListeners;
+ std::vector<PreCheckoutQueryListener> _onPreCheckoutQueryListeners;
+ std::vector<PollListener> _onPollListeners;
+ std::vector<PollAnswerListener> _onPollAnswerListeners;
+ std::vector<ChatMemberUpdatedListener> _onMyChatMemberListeners;
+ std::vector<ChatMemberUpdatedListener> _onChatMemberListeners;
+ std::vector<ChatJoinRequestListener> _onChatJoinRequestListeners;
};
}
diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h
index 3f92ca2..88a9bce 100644
--- a/include/tgbot/EventHandler.h
+++ b/include/tgbot/EventHandler.h
@@ -5,6 +5,10 @@
#include "tgbot/types/Update.h"
#include "tgbot/tools/StringTools.h"
+#include <algorithm>
+#include <cstddef>
+#include <string>
+
namespace TgBot {
class TGBOT_API EventHandler {
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index cef1b60..e7f4cd5 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -2,27 +2,27 @@
#define TGBOT_TGTYPEPARSER_H
#include "tgbot/export.h"
+#include "tgbot/types/Update.h"
+#include "tgbot/types/WebhookInfo.h"
#include "tgbot/types/User.h"
#include "tgbot/types/Chat.h"
#include "tgbot/types/Message.h"
#include "tgbot/types/MessageId.h"
+#include "tgbot/types/MessageEntity.h"
#include "tgbot/types/PhotoSize.h"
+#include "tgbot/types/Animation.h"
#include "tgbot/types/Audio.h"
#include "tgbot/types/Document.h"
-#include "tgbot/types/Sticker.h"
-#include "tgbot/types/StickerSet.h"
-#include "tgbot/types/Poll.h"
-#include "tgbot/types/Dice.h"
-#include "tgbot/types/PollAnswer.h"
-#include "tgbot/types/PollOption.h"
-#include "tgbot/types/ChatPermissions.h"
-#include "tgbot/types/ChatLocation.h"
-#include "tgbot/types/MaskPosition.h"
#include "tgbot/types/Video.h"
-#include "tgbot/types/Voice.h"
#include "tgbot/types/VideoNote.h"
+#include "tgbot/types/Voice.h"
#include "tgbot/types/Contact.h"
+#include "tgbot/types/Dice.h"
+#include "tgbot/types/PollOption.h"
+#include "tgbot/types/PollAnswer.h"
+#include "tgbot/types/Poll.h"
#include "tgbot/types/Location.h"
+#include "tgbot/types/Venue.h"
#include "tgbot/types/WebAppData.h"
#include "tgbot/types/ProximityAlertTriggered.h"
#include "tgbot/types/MessageAutoDeleteTimerChanged.h"
@@ -30,7 +30,6 @@
#include "tgbot/types/VideoChatStarted.h"
#include "tgbot/types/VideoChatEnded.h"
#include "tgbot/types/VideoChatParticipantsInvited.h"
-#include "tgbot/types/Update.h"
#include "tgbot/types/UserProfilePhotos.h"
#include "tgbot/types/File.h"
#include "tgbot/types/WebAppInfo.h"
@@ -38,7 +37,14 @@
#include "tgbot/types/KeyboardButton.h"
#include "tgbot/types/KeyboardButtonPollType.h"
#include "tgbot/types/ReplyKeyboardRemove.h"
+#include "tgbot/types/InlineKeyboardMarkup.h"
+#include "tgbot/types/InlineKeyboardButton.h"
+#include "tgbot/types/LoginUrl.h"
+#include "tgbot/types/CallbackQuery.h"
#include "tgbot/types/ForceReply.h"
+#include "tgbot/types/ChatPhoto.h"
+#include "tgbot/types/ChatInviteLink.h"
+#include "tgbot/types/ChatAdministratorRights.h"
#include "tgbot/types/ChatMember.h"
#include "tgbot/types/ChatMemberOwner.h"
#include "tgbot/types/ChatMemberAdministrator.h"
@@ -48,57 +54,8 @@
#include "tgbot/types/ChatMemberBanned.h"
#include "tgbot/types/ChatMemberUpdated.h"
#include "tgbot/types/ChatJoinRequest.h"
-#include "tgbot/types/ChatPhoto.h"
-#include "tgbot/types/ChatAdministratorRights.h"
-#include "tgbot/types/ResponseParameters.h"
-#include "tgbot/types/GenericReply.h"
-#include "tgbot/types/InlineQuery.h"
-#include "tgbot/types/InlineQueryResult.h"
-#include "tgbot/types/InlineQueryResultCachedAudio.h"
-#include "tgbot/types/InlineQueryResultCachedDocument.h"
-#include "tgbot/types/InlineQueryResultCachedGif.h"
-#include "tgbot/types/InlineQueryResultCachedMpeg4Gif.h"
-#include "tgbot/types/InlineQueryResultCachedPhoto.h"
-#include "tgbot/types/InlineQueryResultCachedSticker.h"
-#include "tgbot/types/InlineQueryResultCachedVideo.h"
-#include "tgbot/types/InlineQueryResultCachedVoice.h"
-#include "tgbot/types/InlineQueryResultArticle.h"
-#include "tgbot/types/InlineQueryResultAudio.h"
-#include "tgbot/types/InlineQueryResultContact.h"
-#include "tgbot/types/InlineQueryResultGame.h"
-#include "tgbot/types/InlineQueryResultDocument.h"
-#include "tgbot/types/InlineQueryResultGif.h"
-#include "tgbot/types/InlineQueryResultLocation.h"
-#include "tgbot/types/InlineQueryResultMpeg4Gif.h"
-#include "tgbot/types/InlineQueryResultPhoto.h"
-#include "tgbot/types/InlineQueryResultVenue.h"
-#include "tgbot/types/InlineQueryResultVideo.h"
-#include "tgbot/types/InlineQueryResultVoice.h"
-#include "tgbot/types/ChosenInlineResult.h"
-#include "tgbot/types/SentWebAppMessage.h"
-#include "tgbot/types/Animation.h"
-#include "tgbot/types/Game.h"
-#include "tgbot/types/CallbackGame.h"
-#include "tgbot/types/GameHighScore.h"
-#include "tgbot/types/CallbackQuery.h"
-#include "tgbot/types/InlineKeyboardMarkup.h"
-#include "tgbot/types/InlineKeyboardButton.h"
-#include "tgbot/types/LoginUrl.h"
-#include "tgbot/types/WebhookInfo.h"
-#include "tgbot/types/InputMessageContent.h"
-#include "tgbot/types/InputTextMessageContent.h"
-#include "tgbot/types/InputLocationMessageContent.h"
-#include "tgbot/types/InputVenueMessageContent.h"
-#include "tgbot/types/InputContactMessageContent.h"
-#include "tgbot/types/InputInvoiceMessageContent.h"
-#include "tgbot/types/Invoice.h"
-#include "tgbot/types/OrderInfo.h"
-#include "tgbot/types/PreCheckoutQuery.h"
-#include "tgbot/types/ShippingAddress.h"
-#include "tgbot/types/ShippingQuery.h"
-#include "tgbot/types/ShippingOption.h"
-#include "tgbot/types/SuccessfulPayment.h"
-#include "tgbot/types/LabeledPrice.h"
+#include "tgbot/types/ChatPermissions.h"
+#include "tgbot/types/ChatLocation.h"
#include "tgbot/types/BotCommand.h"
#include "tgbot/types/BotCommandScope.h"
#include "tgbot/types/BotCommandScopeDefault.h"
@@ -112,12 +69,54 @@
#include "tgbot/types/MenuButtonCommands.h"
#include "tgbot/types/MenuButtonWebApp.h"
#include "tgbot/types/MenuButtonDefault.h"
+#include "tgbot/types/ResponseParameters.h"
#include "tgbot/types/InputMedia.h"
#include "tgbot/types/InputMediaPhoto.h"
#include "tgbot/types/InputMediaVideo.h"
+#include "tgbot/types/InputMediaAnimation.h"
#include "tgbot/types/InputMediaAudio.h"
#include "tgbot/types/InputMediaDocument.h"
-#include "tgbot/types/InputMediaAnimation.h"
+#include "tgbot/types/Sticker.h"
+#include "tgbot/types/StickerSet.h"
+#include "tgbot/types/MaskPosition.h"
+#include "tgbot/types/InlineQuery.h"
+#include "tgbot/types/InlineQueryResult.h"
+#include "tgbot/types/InlineQueryResultArticle.h"
+#include "tgbot/types/InlineQueryResultPhoto.h"
+#include "tgbot/types/InlineQueryResultGif.h"
+#include "tgbot/types/InlineQueryResultMpeg4Gif.h"
+#include "tgbot/types/InlineQueryResultVideo.h"
+#include "tgbot/types/InlineQueryResultAudio.h"
+#include "tgbot/types/InlineQueryResultVoice.h"
+#include "tgbot/types/InlineQueryResultDocument.h"
+#include "tgbot/types/InlineQueryResultLocation.h"
+#include "tgbot/types/InlineQueryResultVenue.h"
+#include "tgbot/types/InlineQueryResultContact.h"
+#include "tgbot/types/InlineQueryResultGame.h"
+#include "tgbot/types/InlineQueryResultCachedPhoto.h"
+#include "tgbot/types/InlineQueryResultCachedGif.h"
+#include "tgbot/types/InlineQueryResultCachedMpeg4Gif.h"
+#include "tgbot/types/InlineQueryResultCachedSticker.h"
+#include "tgbot/types/InlineQueryResultCachedDocument.h"
+#include "tgbot/types/InlineQueryResultCachedVideo.h"
+#include "tgbot/types/InlineQueryResultCachedVoice.h"
+#include "tgbot/types/InlineQueryResultCachedAudio.h"
+#include "tgbot/types/InputMessageContent.h"
+#include "tgbot/types/InputTextMessageContent.h"
+#include "tgbot/types/InputLocationMessageContent.h"
+#include "tgbot/types/InputVenueMessageContent.h"
+#include "tgbot/types/InputContactMessageContent.h"
+#include "tgbot/types/InputInvoiceMessageContent.h"
+#include "tgbot/types/ChosenInlineResult.h"
+#include "tgbot/types/SentWebAppMessage.h"
+#include "tgbot/types/LabeledPrice.h"
+#include "tgbot/types/Invoice.h"
+#include "tgbot/types/ShippingAddress.h"
+#include "tgbot/types/OrderInfo.h"
+#include "tgbot/types/ShippingOption.h"
+#include "tgbot/types/SuccessfulPayment.h"
+#include "tgbot/types/ShippingQuery.h"
+#include "tgbot/types/PreCheckoutQuery.h"
#include "tgbot/types/PassportData.h"
#include "tgbot/types/PassportFile.h"
#include "tgbot/types/PassportElementError.h"
@@ -130,15 +129,19 @@
#include "tgbot/types/PassportElementErrorTranslationFile.h"
#include "tgbot/types/PassportElementErrorTranslationFiles.h"
#include "tgbot/types/PassportElementErrorUnspecified.h"
+#include "tgbot/types/Game.h"
+#include "tgbot/types/CallbackGame.h"
+#include "tgbot/types/GameHighScore.h"
+#include "tgbot/types/GenericReply.h"
-#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
+#include <boost/property_tree/ptree.hpp>
#include <memory>
#include <sstream>
#include <string>
-#include <vector>
#include <utility>
+#include <vector>
namespace TgBot {
@@ -151,14 +154,17 @@ public:
template<typename T>
using TgTypeToJsonFunc = std::string (TgTypeParser::*)(const std::shared_ptr<T>&) const;
- Chat::Ptr parseJsonAndGetChat(const boost::property_tree::ptree& data) const;
- std::string parseChat(const Chat::Ptr& object) const;
+ Update::Ptr parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const;
+ std::string parseUpdate(const Update::Ptr& object) const;
+
+ WebhookInfo::Ptr parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const;
+ std::string parseWebhookInfo(const WebhookInfo::Ptr& object) const;
User::Ptr parseJsonAndGetUser(const boost::property_tree::ptree& data) const;
std::string parseUser(const User::Ptr& object) const;
- MessageEntity::Ptr parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const;
- std::string parseMessageEntity(const MessageEntity::Ptr& object) const;
+ Chat::Ptr parseJsonAndGetChat(const boost::property_tree::ptree& data) const;
+ std::string parseChat(const Chat::Ptr& object) const;
Message::Ptr parseJsonAndGetMessage(const boost::property_tree::ptree& data) const;
std::string parseMessage(const Message::Ptr& object) const;
@@ -166,65 +172,44 @@ public:
MessageId::Ptr parseJsonAndGetMessageId(const boost::property_tree::ptree& data) const;
std::string parseMessageId(const MessageId::Ptr& object) const;
+ MessageEntity::Ptr parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const;
+ std::string parseMessageEntity(const MessageEntity::Ptr& object) const;
+
PhotoSize::Ptr parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const;
std::string parsePhotoSize(const PhotoSize::Ptr& object) const;
+ Animation::Ptr parseJsonAndGetAnimation(const boost::property_tree::ptree& data) const;
+ std::string parseAnimation(const Animation::Ptr& object) const;
+
Audio::Ptr parseJsonAndGetAudio(const boost::property_tree::ptree& data) const;
std::string parseAudio(const Audio::Ptr& object) const;
Document::Ptr parseJsonAndGetDocument(const boost::property_tree::ptree& data) const;
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;
+ Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const;
+ std::string parseVideo(const Video::Ptr& object) const;
- StickerSet::Ptr parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const;
- std::string parseStickerSet(const StickerSet::Ptr& object) const;
+ VideoNote::Ptr parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const;
+ std::string parseVideoNote(const VideoNote::Ptr& object) const;
- MaskPosition::Ptr parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const;
- std::string parseMaskPosition(const MaskPosition::Ptr& object) const;
+ Voice::Ptr parseJsonAndGetVoice(const boost::property_tree::ptree& data) const;
+ std::string parseVoice(const Voice::Ptr& object) const;
- Poll::Ptr parseJsonAndGetPoll(const boost::property_tree::ptree& data) const;
- std::string parsePoll(const Poll::Ptr& object) const;
+ Contact::Ptr parseJsonAndGetContact(const boost::property_tree::ptree& data) const;
+ std::string parseContact(const Contact::Ptr& object) const;
Dice::Ptr parseJsonAndGetDice(const boost::property_tree::ptree& data) const;
std::string parseDice(const Dice::Ptr& object) const;
- PollAnswer::Ptr parseJsonAndGetPollAnswer(const boost::property_tree::ptree& data) const;
- std::string parsePollAnswer(const PollAnswer::Ptr& object) const;
-
PollOption::Ptr parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const;
std::string parsePollOption(const PollOption::Ptr& object) const;
- ChatPermissions::Ptr parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const;
- std::string parseChatPermissions(const ChatPermissions::Ptr& object) const;
-
- ChatLocation::Ptr parseJsonAndGetChatLocation(const boost::property_tree::ptree& data) const;
- std::string parseChatLocation(const ChatLocation::Ptr& object) const;
-
- 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;
-
- Game::Ptr parseJsonAndGetGame(const boost::property_tree::ptree& data) const;
- std::string parseGame(const Game::Ptr& object) const;
-
- CallbackGame::Ptr parseJsonAndGetCallbackGame(const boost::property_tree::ptree& data) const;
- std::string parseCallbackGame(const CallbackGame::Ptr& object) const;
-
- GameHighScore::Ptr parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const;
- std::string parseGameHighScore(const GameHighScore::Ptr& object) const;
-
- Animation::Ptr parseJsonAndGetAnimation(const boost::property_tree::ptree& data) const;
- std::string parseAnimation(const Animation::Ptr& object) const;
+ PollAnswer::Ptr parseJsonAndGetPollAnswer(const boost::property_tree::ptree& data) const;
+ std::string parsePollAnswer(const PollAnswer::Ptr& object) const;
- Contact::Ptr parseJsonAndGetContact(const boost::property_tree::ptree& data) const;
- std::string parseContact(const Contact::Ptr& object) const;
+ Poll::Ptr parseJsonAndGetPoll(const boost::property_tree::ptree& data) const;
+ std::string parsePoll(const Poll::Ptr& object) const;
Location::Ptr parseJsonAndGetLocation(const boost::property_tree::ptree& data) const;
std::string parseLocation(const Location::Ptr& object) const;
@@ -253,30 +238,9 @@ public:
VideoChatParticipantsInvited::Ptr parseJsonAndGetVideoChatParticipantsInvited(const boost::property_tree::ptree& data) const;
std::string parseVideoChatParticipantsInvited(const VideoChatParticipantsInvited::Ptr& object) const;
- Update::Ptr parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const;
- std::string parseUpdate(const Update::Ptr& object) const;
-
UserProfilePhotos::Ptr parseJsonAndGetUserProfilePhotos(const boost::property_tree::ptree& data) const;
std::string parseUserProfilePhotos(const UserProfilePhotos::Ptr& object) const;
- InputMedia::Ptr parseJsonAndGetInputMedia(const boost::property_tree::ptree& data) const;
- std::string parseInputMedia(const InputMedia::Ptr& object) const;
-
- InputMediaPhoto::Ptr parseJsonAndGetInputMediaPhoto(const boost::property_tree::ptree& data) const;
- std::string parseInputMediaPhoto(const InputMediaPhoto::Ptr& object) const;
-
- InputMediaVideo::Ptr parseJsonAndGetInputMediaVideo(const boost::property_tree::ptree& data) const;
- std::string parseInputMediaVideo(const InputMediaVideo::Ptr& object) const;
-
- InputMediaAnimation::Ptr parseJsonAndGetInputMediaAnimation(const boost::property_tree::ptree& data) const;
- std::string parseInputMediaAnimation(const InputMediaAnimation::Ptr& object) const;
-
- InputMediaAudio::Ptr parseJsonAndGetInputMediaAudio(const boost::property_tree::ptree& data) const;
- std::string parseInputMediaAudio(const InputMediaAudio::Ptr& object) const;
-
- InputMediaDocument::Ptr parseJsonAndGetInputMediaDocument(const boost::property_tree::ptree& data) const;
- std::string parseInputMediaDocument(const InputMediaDocument::Ptr& object) const;
-
File::Ptr parseJsonAndGetFile(const boost::property_tree::ptree& data) const;
std::string parseFile(const File::Ptr& object) const;
@@ -295,9 +259,30 @@ public:
ReplyKeyboardRemove::Ptr parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const;
std::string parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const;
+ InlineKeyboardMarkup::Ptr parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const;
+ std::string parseInlineKeyboardMarkup(const InlineKeyboardMarkup::Ptr& object) const;
+
+ InlineKeyboardButton::Ptr parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const;
+ std::string parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const;
+
+ LoginUrl::Ptr parseJsonAndGetLoginUrl(const boost::property_tree::ptree& data) const;
+ std::string parseLoginUrl(const LoginUrl::Ptr& object) const;
+
+ CallbackQuery::Ptr parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const;
+ std::string parseCallbackQuery(const CallbackQuery::Ptr& object) const;
+
ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const;
std::string parseForceReply(const ForceReply::Ptr& object) const;
+ ChatPhoto::Ptr parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const;
+ std::string parseChatPhoto(const ChatPhoto::Ptr& object) const;
+
+ ChatInviteLink::Ptr parseJsonAndGetChatInviteLink(const boost::property_tree::ptree& data) const;
+ std::string parseChatInviteLink(const ChatInviteLink::Ptr& object) const;
+
+ ChatAdministratorRights::Ptr parseJsonAndGetChatAdministratorRights(const boost::property_tree::ptree& data) const;
+ std::string parseChatAdministratorRights(const ChatAdministratorRights::Ptr& object) const;
+
ChatMember::Ptr parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const;
std::string parseChatMember(const ChatMember::Ptr& object) const;
@@ -325,62 +310,107 @@ public:
ChatJoinRequest::Ptr parseJsonAndGetChatJoinRequest(const boost::property_tree::ptree& data) const;
std::string parseChatJoinRequest(const ChatJoinRequest::Ptr& object) const;
- ChatPhoto::Ptr parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const;
- std::string parseChatPhoto(const ChatPhoto::Ptr& object) const;
+ ChatPermissions::Ptr parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const;
+ std::string parseChatPermissions(const ChatPermissions::Ptr& object) const;
- ChatInviteLink::Ptr parseJsonAndGetChatInviteLink(const boost::property_tree::ptree& data) const;
- std::string parseChatInviteLink(const ChatInviteLink::Ptr& object) const;
+ ChatLocation::Ptr parseJsonAndGetChatLocation(const boost::property_tree::ptree& data) const;
+ std::string parseChatLocation(const ChatLocation::Ptr& object) const;
- ChatAdministratorRights::Ptr parseJsonAndGetChatAdministratorRights(const boost::property_tree::ptree& data) const;
- std::string parseChatAdministratorRights(const ChatAdministratorRights::Ptr& object) const;
+ BotCommand::Ptr parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommand(const BotCommand::Ptr& object) const;
+
+ BotCommandScope::Ptr parseJsonAndGetBotCommandScope(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommandScope(const BotCommandScope::Ptr& object) const;
+
+ BotCommandScopeDefault::Ptr parseJsonAndGetBotCommandScopeDefault(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommandScopeDefault(const BotCommandScopeDefault::Ptr& object) const;
+
+ BotCommandScopeAllPrivateChats::Ptr parseJsonAndGetBotCommandScopeAllPrivateChats(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommandScopeAllPrivateChats(const BotCommandScopeAllPrivateChats::Ptr& object) const;
+
+ BotCommandScopeAllGroupChats::Ptr parseJsonAndGetBotCommandScopeAllGroupChats(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommandScopeAllGroupChats(const BotCommandScopeAllGroupChats::Ptr& object) const;
+
+ BotCommandScopeAllChatAdministrators::Ptr parseJsonAndGetBotCommandScopeAllChatAdministrators(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommandScopeAllChatAdministrators(const BotCommandScopeAllChatAdministrators::Ptr& object) const;
+
+ BotCommandScopeChat::Ptr parseJsonAndGetBotCommandScopeChat(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommandScopeChat(const BotCommandScopeChat::Ptr& object) const;
+
+ BotCommandScopeChatAdministrators::Ptr parseJsonAndGetBotCommandScopeChatAdministrators(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommandScopeChatAdministrators(const BotCommandScopeChatAdministrators::Ptr& object) const;
+
+ BotCommandScopeChatMember::Ptr parseJsonAndGetBotCommandScopeChatMember(const boost::property_tree::ptree& data) const;
+ std::string parseBotCommandScopeChatMember(const BotCommandScopeChatMember::Ptr& object) const;
+
+ MenuButton::Ptr parseJsonAndGetMenuButton(const boost::property_tree::ptree& data) const;
+ std::string parseMenuButton(const MenuButton::Ptr& object) const;
+
+ MenuButtonCommands::Ptr parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& data) const;
+ std::string parseMenuButtonCommands(const MenuButtonCommands::Ptr& object) const;
+
+ MenuButtonWebApp::Ptr parseJsonAndGetMenuButtonWebApp(const boost::property_tree::ptree& data) const;
+ std::string parseMenuButtonWebApp(const MenuButtonWebApp::Ptr& object) const;
+
+ MenuButtonDefault::Ptr parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& data) const;
+ std::string parseMenuButtonDefault(const MenuButtonDefault::Ptr& object) const;
ResponseParameters::Ptr parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const;
std::string parseResponseParameters(const ResponseParameters::Ptr& object) const;
- GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const;
- std::string parseGenericReply(const GenericReply::Ptr& object) const;
+ InputMedia::Ptr parseJsonAndGetInputMedia(const boost::property_tree::ptree& data) const;
+ std::string parseInputMedia(const InputMedia::Ptr& object) const;
- InlineQuery::Ptr parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const;
- std::string parseInlineQuery(const InlineQuery::Ptr& object) const;
+ InputMediaPhoto::Ptr parseJsonAndGetInputMediaPhoto(const boost::property_tree::ptree& data) const;
+ std::string parseInputMediaPhoto(const InputMediaPhoto::Ptr& object) const;
- InlineQueryResult::Ptr parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResult(const InlineQueryResult::Ptr& object) const;
+ InputMediaVideo::Ptr parseJsonAndGetInputMediaVideo(const boost::property_tree::ptree& data) const;
+ std::string parseInputMediaVideo(const InputMediaVideo::Ptr& object) const;
- InlineQueryResultCachedAudio::Ptr parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const;
+ InputMediaAnimation::Ptr parseJsonAndGetInputMediaAnimation(const boost::property_tree::ptree& data) const;
+ std::string parseInputMediaAnimation(const InputMediaAnimation::Ptr& object) const;
- InlineQueryResultCachedDocument::Ptr parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const;
+ InputMediaAudio::Ptr parseJsonAndGetInputMediaAudio(const boost::property_tree::ptree& data) const;
+ std::string parseInputMediaAudio(const InputMediaAudio::Ptr& object) const;
- InlineQueryResultCachedGif::Ptr parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const;
+ InputMediaDocument::Ptr parseJsonAndGetInputMediaDocument(const boost::property_tree::ptree& data) const;
+ std::string parseInputMediaDocument(const InputMediaDocument::Ptr& object) const;
- InlineQueryResultCachedMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const;
+ Sticker::Ptr parseJsonAndGetSticker(const boost::property_tree::ptree& data) const;
+ std::string parseSticker(const Sticker::Ptr& object) const;
- InlineQueryResultCachedPhoto::Ptr parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const;
+ StickerSet::Ptr parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const;
+ std::string parseStickerSet(const StickerSet::Ptr& object) const;
- InlineQueryResultCachedSticker::Ptr parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const;
+ MaskPosition::Ptr parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const;
+ std::string parseMaskPosition(const MaskPosition::Ptr& object) const;
- InlineQueryResultCachedVideo::Ptr parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const;
+ InlineQuery::Ptr parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQuery(const InlineQuery::Ptr& object) const;
- InlineQueryResultCachedVoice::Ptr parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const;
+ InlineQueryResult::Ptr parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResult(const InlineQueryResult::Ptr& object) const;
InlineQueryResultArticle::Ptr parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const;
std::string parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const;
+ InlineQueryResultPhoto::Ptr parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const;
+
+ InlineQueryResultGif::Ptr parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const;
+
+ InlineQueryResultMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultMpeg4Gif(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultMpeg4Gif(const InlineQueryResultMpeg4Gif::Ptr& object) const;
+
+ InlineQueryResultVideo::Ptr parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const;
+
InlineQueryResultAudio::Ptr parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const;
std::string parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const;
- InlineQueryResultContact::Ptr parseJsonAndGetInlineQueryResultContact(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const;
-
- InlineQueryResultGame::Ptr parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const;
+ InlineQueryResultVoice::Ptr parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const;
InlineQueryResultDocument::Ptr parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const;
std::string parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const;
@@ -391,41 +421,35 @@ public:
InlineQueryResultVenue::Ptr parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const;
std::string parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const;
- InlineQueryResultVoice::Ptr parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const;
-
- InlineQueryResultPhoto::Ptr parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const;
-
- InlineQueryResultGif::Ptr parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const;
+ InlineQueryResultContact::Ptr parseJsonAndGetInlineQueryResultContact(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const;
- InlineQueryResultMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultMpeg4Gif(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultMpeg4Gif(const InlineQueryResultMpeg4Gif::Ptr& object) const;
+ InlineQueryResultGame::Ptr parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const;
- InlineQueryResultVideo::Ptr parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const;
- std::string parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const;
+ InlineQueryResultCachedPhoto::Ptr parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const;
- ChosenInlineResult::Ptr parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const;
- std::string parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const;
+ InlineQueryResultCachedGif::Ptr parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const;
- SentWebAppMessage::Ptr parseJsonAndGetSentWebAppMessage(const boost::property_tree::ptree& data) const;
- std::string parseSentWebAppMessage(const SentWebAppMessage::Ptr& object) const;
+ InlineQueryResultCachedMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const;
- CallbackQuery::Ptr parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const;
- std::string parseCallbackQuery(const CallbackQuery::Ptr& object) const;
+ InlineQueryResultCachedSticker::Ptr parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const;
- InlineKeyboardMarkup::Ptr parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const;
- std::string parseInlineKeyboardMarkup(const InlineKeyboardMarkup::Ptr& object) const;
+ InlineQueryResultCachedDocument::Ptr parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const;
- InlineKeyboardButton::Ptr parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const;
- std::string parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const;
+ InlineQueryResultCachedVideo::Ptr parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const;
- LoginUrl::Ptr parseJsonAndGetLoginUrl(const boost::property_tree::ptree& data) const;
- std::string parseLoginUrl(const LoginUrl::Ptr& object) const;
+ InlineQueryResultCachedVoice::Ptr parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const;
- WebhookInfo::Ptr parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const;
- std::string parseWebhookInfo(const WebhookInfo::Ptr& object) const;
+ InlineQueryResultCachedAudio::Ptr parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const;
+ std::string parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const;
InputMessageContent::Ptr parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const;
std::string parseInputMessageContent(const InputMessageContent::Ptr& object) const;
@@ -445,68 +469,35 @@ public:
InputInvoiceMessageContent::Ptr parseJsonAndGetInputInvoiceMessageContent(const boost::property_tree::ptree& data) const;
std::string parseInputInvoiceMessageContent(const InputInvoiceMessageContent::Ptr& object) const;
- Invoice::Ptr parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const;
- std::string parseInvoice(const Invoice::Ptr& object) const;
+ ChosenInlineResult::Ptr parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const;
+ std::string parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const;
+
+ SentWebAppMessage::Ptr parseJsonAndGetSentWebAppMessage(const boost::property_tree::ptree& data) const;
+ std::string parseSentWebAppMessage(const SentWebAppMessage::Ptr& object) const;
LabeledPrice::Ptr parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const;
std::string parseLabeledPrice(const LabeledPrice::Ptr& object) const;
- BotCommand::Ptr parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const;
- std::string parseBotCommand(const BotCommand::Ptr& object) const;
-
- BotCommandScope::Ptr parseJsonAndGetBotCommandScope(const boost::property_tree::ptree& data) const;
- std::string parseBotCommandScope(const BotCommandScope::Ptr& object) const;
-
- BotCommandScopeDefault::Ptr parseJsonAndGetBotCommandScopeDefault(const boost::property_tree::ptree& data) const;
- std::string parseBotCommandScopeDefault(const BotCommandScopeDefault::Ptr& object) const;
-
- BotCommandScopeAllPrivateChats::Ptr parseJsonAndGetBotCommandScopeAllPrivateChats(const boost::property_tree::ptree& data) const;
- std::string parseBotCommandScopeAllPrivateChats(const BotCommandScopeAllPrivateChats::Ptr& object) const;
-
- BotCommandScopeAllGroupChats::Ptr parseJsonAndGetBotCommandScopeAllGroupChats(const boost::property_tree::ptree& data) const;
- std::string parseBotCommandScopeAllGroupChats(const BotCommandScopeAllGroupChats::Ptr& object) const;
-
- BotCommandScopeAllChatAdministrators::Ptr parseJsonAndGetBotCommandScopeAllChatAdministrators(const boost::property_tree::ptree& data) const;
- std::string parseBotCommandScopeAllChatAdministrators(const BotCommandScopeAllChatAdministrators::Ptr& object) const;
-
- BotCommandScopeChat::Ptr parseJsonAndGetBotCommandScopeChat(const boost::property_tree::ptree& data) const;
- std::string parseBotCommandScopeChat(const BotCommandScopeChat::Ptr& object) const;
-
- BotCommandScopeChatAdministrators::Ptr parseJsonAndGetBotCommandScopeChatAdministrators(const boost::property_tree::ptree& data) const;
- std::string parseBotCommandScopeChatAdministrators(const BotCommandScopeChatAdministrators::Ptr& object) const;
-
- BotCommandScopeChatMember::Ptr parseJsonAndGetBotCommandScopeChatMember(const boost::property_tree::ptree& data) const;
- std::string parseBotCommandScopeChatMember(const BotCommandScopeChatMember::Ptr& object) const;
-
- MenuButton::Ptr parseJsonAndGetMenuButton(const boost::property_tree::ptree& data) const;
- std::string parseMenuButton(const MenuButton::Ptr& object) const;
-
- MenuButtonCommands::Ptr parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& data) const;
- std::string parseMenuButtonCommands(const MenuButtonCommands::Ptr& object) const;
-
- MenuButtonWebApp::Ptr parseJsonAndGetMenuButtonWebApp(const boost::property_tree::ptree& data) const;
- std::string parseMenuButtonWebApp(const MenuButtonWebApp::Ptr& object) const;
+ Invoice::Ptr parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const;
+ std::string parseInvoice(const Invoice::Ptr& object) const;
- MenuButtonDefault::Ptr parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& data) const;
- std::string parseMenuButtonDefault(const MenuButtonDefault::Ptr& object) const;
+ ShippingAddress::Ptr parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const;
+ std::string parseShippingAddress(const ShippingAddress::Ptr& object) const;
OrderInfo::Ptr parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const;
std::string parseOrderInfo(const OrderInfo::Ptr& object) const;
- PreCheckoutQuery::Ptr parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const;
- std::string parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const;
-
- ShippingAddress::Ptr parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const;
- std::string parseShippingAddress(const ShippingAddress::Ptr& object) const;
-
ShippingOption::Ptr parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const;
std::string parseShippingOption(const ShippingOption::Ptr& object) const;
+ SuccessfulPayment::Ptr parseJsonAndGetSuccessfulPayment(const boost::property_tree::ptree& data) const;
+ std::string parseSuccessfulPayment(const SuccessfulPayment::Ptr& object) const;
+
ShippingQuery::Ptr parseJsonAndGetShippingQuery(const boost::property_tree::ptree& data) const;
std::string parseShippingQuery(const ShippingQuery::Ptr& object) const;
- SuccessfulPayment::Ptr parseJsonAndGetSuccessfulPayment(const boost::property_tree::ptree& data) const;
- std::string parseSuccessfulPayment(const SuccessfulPayment::Ptr& object) const;
+ PreCheckoutQuery::Ptr parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const;
+ std::string parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const;
PassportData::Ptr parseJsonAndGetPassportData(const boost::property_tree::ptree& data) const;
std::string parsePassportData(const PassportData::Ptr& object) const;
@@ -550,6 +541,18 @@ public:
PassportElementErrorUnspecified::Ptr parseJsonAndGetPassportElementErrorUnspecified(const boost::property_tree::ptree& data) const;
std::string parsePassportElementErrorUnspecified(const PassportElementErrorUnspecified::Ptr& object) const;
+ Game::Ptr parseJsonAndGetGame(const boost::property_tree::ptree& data) const;
+ std::string parseGame(const Game::Ptr& object) const;
+
+ CallbackGame::Ptr parseJsonAndGetCallbackGame(const boost::property_tree::ptree& data) const;
+ std::string parseCallbackGame(const CallbackGame::Ptr& object) const;
+
+ GameHighScore::Ptr parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const;
+ std::string parseGameHighScore(const GameHighScore::Ptr& object) const;
+
+ GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const;
+ std::string parseGenericReply(const GenericReply::Ptr& object) const;
+
inline boost::property_tree::ptree parseJson(const std::string& json) const {
boost::property_tree::ptree tree;
std::istringstream input(json);
diff --git a/include/tgbot/tools/StringTools.h b/include/tgbot/tools/StringTools.h
index fa3a2f5..a833fc2 100644
--- a/include/tgbot/tools/StringTools.h
+++ b/include/tgbot/tools/StringTools.h
@@ -63,6 +63,15 @@ TGBOT_API
std::string urlDecode(const std::string& value);
/**
+ * Escapes a string with illegal characters ("\/) for json
+ *
+ * @param value input string
+ *
+ * @return An encoded string
+ */
+std::string escapeJsonString(const std::string& value);
+
+/**
* Splits string to smaller substrings which have between them a delimiter. Resulting substrings won't have delimiter.
* @param str Source string
* @param delimiter Delimiter
diff --git a/samples/echobot-curl-client/CMakeLists.txt b/samples/echobot-curl-client/CMakeLists.txt
index 75d9c58..74b45c5 100644
--- a/samples/echobot-curl-client/CMakeLists.txt
+++ b/samples/echobot-curl-client/CMakeLists.txt
@@ -1,7 +1,9 @@
-cmake_minimum_required(VERSION 2.8.4)
+cmake_minimum_required(VERSION 3.10.2)
project(echobot-curl-client)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)
find_package(Threads REQUIRED)
diff --git a/samples/echobot-curl-client/Dockerfile b/samples/echobot-curl-client/Dockerfile
index a7aa61a..2954ceb 100644
--- a/samples/echobot-curl-client/Dockerfile
+++ b/samples/echobot-curl-client/Dockerfile
@@ -1,8 +1,8 @@
FROM reo7sp/tgbot-cpp
MAINTAINER Oleg Morozenkov <a@reo7sp.ru>
-WORKDIR /usr/src/echobot
+WORKDIR /usr/src/echobot-curl-client
COPY . .
RUN cmake .
RUN make -j4
-CMD ./echobot
+CMD ./echobot-curl-client
diff --git a/samples/echobot-setmycommands/CMakeLists.txt b/samples/echobot-setmycommands/CMakeLists.txt
index 7019e8f..f8d4ad2 100644
--- a/samples/echobot-setmycommands/CMakeLists.txt
+++ b/samples/echobot-setmycommands/CMakeLists.txt
@@ -1,7 +1,9 @@
-cmake_minimum_required(VERSION 2.8.4)
-project(echobot)
+cmake_minimum_required(VERSION 3.10.2)
+project(echobot-setmycommands)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)
find_package(Threads REQUIRED)
@@ -14,6 +16,6 @@ if (CURL_FOUND)
add_definitions(-DHAVE_CURL)
endif()
-add_executable(echobot src/main.cpp)
+add_executable(echobot-setmycommands src/main.cpp)
-target_link_libraries(echobot /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES})
+target_link_libraries(echobot-setmycommands /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES})
diff --git a/samples/echobot-setmycommands/Dockerfile b/samples/echobot-setmycommands/Dockerfile
index a7aa61a..c103a7d 100644
--- a/samples/echobot-setmycommands/Dockerfile
+++ b/samples/echobot-setmycommands/Dockerfile
@@ -1,8 +1,8 @@
FROM reo7sp/tgbot-cpp
MAINTAINER Oleg Morozenkov <a@reo7sp.ru>
-WORKDIR /usr/src/echobot
+WORKDIR /usr/src/echobot-setmycommands
COPY . .
RUN cmake .
RUN make -j4
-CMD ./echobot
+CMD ./echobot-setmycommands
diff --git a/samples/echobot-submodule/CMakeLists.txt b/samples/echobot-submodule/CMakeLists.txt
index fbb9087..e7a16f1 100644
--- a/samples/echobot-submodule/CMakeLists.txt
+++ b/samples/echobot-submodule/CMakeLists.txt
@@ -1,7 +1,9 @@
-cmake_minimum_required(VERSION 2.8.4)
+cmake_minimum_required(VERSION 3.10.2)
project(echobot-submodule)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)
find_package(Threads REQUIRED)
diff --git a/samples/echobot-submodule/Dockerfile b/samples/echobot-submodule/Dockerfile
index a7aa61a..5e5191a 100644
--- a/samples/echobot-submodule/Dockerfile
+++ b/samples/echobot-submodule/Dockerfile
@@ -1,8 +1,8 @@
FROM reo7sp/tgbot-cpp
MAINTAINER Oleg Morozenkov <a@reo7sp.ru>
-WORKDIR /usr/src/echobot
+WORKDIR /usr/src/echobot-submodule
COPY . .
RUN cmake .
RUN make -j4
-CMD ./echobot
+CMD ./echobot-submodule
diff --git a/samples/echobot-webhook-server/CMakeLists.txt b/samples/echobot-webhook-server/CMakeLists.txt
index 49bcef1..3f4e8b8 100644
--- a/samples/echobot-webhook-server/CMakeLists.txt
+++ b/samples/echobot-webhook-server/CMakeLists.txt
@@ -1,7 +1,9 @@
-cmake_minimum_required(VERSION 2.8.4)
+cmake_minimum_required(VERSION 3.10.2)
project(echobot-webhook-server)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)
find_package(Threads REQUIRED)
diff --git a/samples/echobot-webhook-server/Dockerfile b/samples/echobot-webhook-server/Dockerfile
index a7aa61a..2aa4048 100644
--- a/samples/echobot-webhook-server/Dockerfile
+++ b/samples/echobot-webhook-server/Dockerfile
@@ -1,8 +1,8 @@
FROM reo7sp/tgbot-cpp
MAINTAINER Oleg Morozenkov <a@reo7sp.ru>
-WORKDIR /usr/src/echobot
+WORKDIR /usr/src/echobot-webhook-server
COPY . .
RUN cmake .
RUN make -j4
-CMD ./echobot
+CMD ./echobot-webhook-server
diff --git a/samples/echobot/CMakeLists.txt b/samples/echobot/CMakeLists.txt
index 7019e8f..20f5297 100644
--- a/samples/echobot/CMakeLists.txt
+++ b/samples/echobot/CMakeLists.txt
@@ -1,7 +1,9 @@
-cmake_minimum_required(VERSION 2.8.4)
+cmake_minimum_required(VERSION 3.10.2)
project(echobot)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)
find_package(Threads REQUIRED)
diff --git a/samples/inline-keyboard/CMakeLists.txt b/samples/inline-keyboard/CMakeLists.txt
index fe7c9bd..01d8718 100644
--- a/samples/inline-keyboard/CMakeLists.txt
+++ b/samples/inline-keyboard/CMakeLists.txt
@@ -1,7 +1,9 @@
-cmake_minimum_required(VERSION 2.8.4)
+cmake_minimum_required(VERSION 3.10.2)
project(inline-keyboard)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)
find_package(Threads REQUIRED)
diff --git a/samples/inline-keyboard/Dockerfile b/samples/inline-keyboard/Dockerfile
index a65d5a1..7e8e97a 100644
--- a/samples/inline-keyboard/Dockerfile
+++ b/samples/inline-keyboard/Dockerfile
@@ -4,5 +4,5 @@ MAINTAINER Oleg Morozenkov <a@reo7sp.ru>
WORKDIR /usr/src/inline-keyboard
COPY . .
RUN cmake .
-RUN make
+RUN make -j4
CMD ./inline-keyboard
diff --git a/samples/photo/CMakeLists.txt b/samples/photo/CMakeLists.txt
index ae4b2eb..a4edadc 100644
--- a/samples/photo/CMakeLists.txt
+++ b/samples/photo/CMakeLists.txt
@@ -1,7 +1,9 @@
-cmake_minimum_required(VERSION 2.8.4)
+cmake_minimum_required(VERSION 3.10.2)
project(photo)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)
find_package(Threads REQUIRED)
diff --git a/samples/received-text-processing/CMakeLists.txt b/samples/received-text-processing/CMakeLists.txt
index 2e351d1..a6bc7dd 100644
--- a/samples/received-text-processing/CMakeLists.txt
+++ b/samples/received-text-processing/CMakeLists.txt
@@ -1,7 +1,9 @@
-cmake_minimum_required(VERSION 2.8.4)
+cmake_minimum_required(VERSION 3.10.2)
project(received-text-processing)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)
find_package(Threads REQUIRED)
diff --git a/samples/received-text-processing/Dockerfile b/samples/received-text-processing/Dockerfile
new file mode 100644
index 0000000..004c09f
--- /dev/null
+++ b/samples/received-text-processing/Dockerfile
@@ -0,0 +1,8 @@
+FROM reo7sp/tgbot-cpp
+MAINTAINER Oleg Morozenkov <a@reo7sp.ru>
+
+WORKDIR /usr/src/received-text-processing
+COPY . .
+RUN cmake .
+RUN make -j4
+CMD ./received-text-processing
diff --git a/samples/reply-keyboard/CMakeLists.txt b/samples/reply-keyboard/CMakeLists.txt
new file mode 100644
index 0000000..4510692
--- /dev/null
+++ b/samples/reply-keyboard/CMakeLists.txt
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 3.10.2)
+project(reply-keyboard)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
+set(Boost_USE_MULTITHREADED ON)
+
+find_package(Threads REQUIRED)
+find_package(OpenSSL REQUIRED)
+find_package(Boost COMPONENTS system REQUIRED)
+find_package(CURL)
+include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
+if (CURL_FOUND)
+ include_directories(${CURL_INCLUDE_DIRS})
+ add_definitions(-DHAVE_CURL)
+endif()
+
+add_executable(reply-keyboard src/main.cpp)
+
+target_link_libraries(reply-keyboard /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES})
diff --git a/samples/reply-keyboard/Dockerfile b/samples/reply-keyboard/Dockerfile
new file mode 100644
index 0000000..712e200
--- /dev/null
+++ b/samples/reply-keyboard/Dockerfile
@@ -0,0 +1,8 @@
+FROM reo7sp/tgbot-cpp
+MAINTAINER Oleg Morozenkov <a@reo7sp.ru>
+
+WORKDIR /usr/src/reply-keyboard
+COPY . .
+RUN cmake .
+RUN make -j4
+CMD ./reply-keyboard
diff --git a/src/Api.cpp b/src/Api.cpp
index 4107a4e..9eefc09 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -1,53 +1,46 @@
#include "tgbot/Api.h"
-#include "tgbot/tools/StringTools.h"
-
-#include "tgbot/TgException.h"
-#include "tgbot/TgTypeParser.h"
-
-#include <cstdint>
-#include <string>
-#include <vector>
-#include <utility>
-
-using namespace std;
-using namespace boost::property_tree;
-
namespace TgBot {
-Api::Api(string token, const HttpClient& httpClient, const std::string& url)
+Api::Api(std::string token, const HttpClient& httpClient, const std::string& url)
: _token(std::move(token)), _httpClient(httpClient), _tgTypeParser(), _url(url) {
}
-vector<Update::Ptr> Api::getUpdates(std::int32_t offset, std::int32_t limit, std::int32_t timeout, const StringArrayPtr& allowedUpdates) const {
- vector<HttpReqArg> args;
+std::vector<Update::Ptr> Api::getUpdates(std::int32_t offset,
+ std::int32_t limit,
+ std::int32_t timeout,
+ const StringArrayPtr& allowedUpdates) const {
+ std::vector<HttpReqArg> args;
args.reserve(4);
- if (offset) {
+
+ if (offset != 0) {
args.emplace_back("offset", offset);
}
- limit = max(1, min(100, limit));
- args.emplace_back("limit", limit);
- if (timeout) {
+ if (limit != 100) {
+ args.emplace_back("limit", std::max(1, std::min(100, limit)));
+ }
+ if (timeout != 0) {
args.emplace_back("timeout", timeout);
}
if (allowedUpdates != nullptr) {
- string allowedUpdatesJson = _tgTypeParser.parseArray<string>(
- [] (const string& s)->string {
+ std::string allowedUpdatesJson = _tgTypeParser.parseArray<std::string>(
+ [] (const std::string& s)->std::string {
return s;
}, *allowedUpdates);
args.emplace_back("allowed_updates", allowedUpdatesJson);
}
+
return _tgTypeParser.parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args));
}
bool Api::setWebhook(const std::string& url,
InputFile::Ptr certificate,
- std::int32_t maxConnection,
+ std::int32_t maxConnections,
const StringArrayPtr& allowedUpdates,
const std::string& ipAddress,
bool dropPendingUpdates,
const std::string& secretToken) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(7);
args.emplace_back("url", url);
@@ -57,12 +50,12 @@ bool Api::setWebhook(const std::string& url,
if (!ipAddress.empty()) {
args.emplace_back("ip_address", ipAddress);
}
- if (maxConnection != 40) {
- args.emplace_back("max_connections", maxConnection);
+ if (maxConnections != 40) {
+ args.emplace_back("max_connections", std::max(1, std::min(100, maxConnections)));
}
if (allowedUpdates != nullptr) {
- auto allowedUpdatesJson = _tgTypeParser.parseArray<string>(
- [] (const string& s)->string {
+ auto allowedUpdatesJson = _tgTypeParser.parseArray<std::string>(
+ [] (const std::string& s)->std::string {
return s;
}, *allowedUpdates);
args.emplace_back("allowed_updates", allowedUpdatesJson);
@@ -78,7 +71,7 @@ bool Api::setWebhook(const std::string& url,
}
bool Api::deleteWebhook(bool dropPendingUpdates) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(1);
if (dropPendingUpdates) {
@@ -89,12 +82,13 @@ bool Api::deleteWebhook(bool dropPendingUpdates) const {
}
WebhookInfo::Ptr Api::getWebhookInfo() const {
- ptree p = sendRequest("getWebhookInfo");
+ boost::property_tree::ptree p = sendRequest("getWebhookInfo");
if (!p.get_child_optional("url")) {
return nullptr;
}
- if (p.get<string>("url", "") != string("")) {
+
+ if (p.get<std::string>("url", "") != std::string("")) {
return _tgTypeParser.parseJsonAndGetWebhookInfo(p);
} else {
return nullptr;
@@ -105,7 +99,15 @@ User::Ptr Api::getMe() const {
return _tgTypeParser.parseJsonAndGetUser(sendRequest("getMe"));
}
-Message::Ptr Api::sendMessage(boost::variant<std::int64_t, const std::string&> chatId,
+bool Api::logOut() const {
+ return sendRequest("logOut").get<bool>("", false);
+}
+
+bool Api::close() const {
+ return sendRequest("close").get<bool>("", false);
+}
+
+Message::Ptr Api::sendMessage(boost::variant<std::int64_t, std::string> chatId,
const std::string& text,
bool disableWebPagePreview,
std::int32_t replyToMessageId,
@@ -115,7 +117,7 @@ Message::Ptr Api::sendMessage(boost::variant<std::int64_t, const std::string&> c
const std::vector<MessageEntity::Ptr>& entities,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(10);
args.emplace_back("chat_id", chatId);
@@ -135,7 +137,7 @@ Message::Ptr Api::sendMessage(boost::variant<std::int64_t, const std::string&> c
if (protectContent) {
args.emplace_back("protect_content", protectContent);
}
- if (replyToMessageId) {
+ if (replyToMessageId != 0) {
args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (allowSendingWithoutReply) {
@@ -148,12 +150,12 @@ Message::Ptr Api::sendMessage(boost::variant<std::int64_t, const std::string&> c
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args));
}
-Message::Ptr Api::forwardMessage(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<std::int64_t, const std::string&> fromChatId,
+Message::Ptr Api::forwardMessage(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<std::int64_t, std::string> fromChatId,
std::int32_t messageId,
bool disableNotification,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(5);
args.emplace_back("chat_id", chatId);
@@ -169,8 +171,8 @@ Message::Ptr Api::forwardMessage(boost::variant<std::int64_t, const std::string&
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args));
}
-MessageId::Ptr Api::copyMessage(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<std::int64_t, const std::string&> fromChatId,
+MessageId::Ptr Api::copyMessage(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<std::int64_t, std::string> fromChatId,
std::int32_t messageId,
const std::string& caption,
const std::string& parseMode,
@@ -180,7 +182,7 @@ MessageId::Ptr Api::copyMessage(boost::variant<std::int64_t, const std::string&>
bool allowSendingWithoutReply,
GenericReply::Ptr replyMarkup,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(11);
args.emplace_back("chat_id", chatId);
@@ -214,8 +216,8 @@ MessageId::Ptr Api::copyMessage(boost::variant<std::int64_t, const std::string&>
return _tgTypeParser.parseJsonAndGetMessageId(sendRequest("copyMessage", args));
}
-Message::Ptr Api::sendPhoto(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> photo,
+Message::Ptr Api::sendPhoto(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> photo,
const std::string& caption,
std::int32_t replyToMessageId,
GenericReply::Ptr replyMarkup,
@@ -224,15 +226,15 @@ Message::Ptr Api::sendPhoto(boost::variant<std::int64_t, const std::string&> cha
const std::vector<MessageEntity::Ptr>& captionEntities,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(10);
args.emplace_back("chat_id", chatId);
if (photo.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(photo);
args.emplace_back("photo", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- args.emplace_back("photo", boost::get<const std::string&>(photo));
+ } else { // std::string
+ args.emplace_back("photo", boost::get<std::string>(photo));
}
if (!caption.empty()) {
args.emplace_back("caption", caption);
@@ -262,13 +264,13 @@ Message::Ptr Api::sendPhoto(boost::variant<std::int64_t, const std::string&> cha
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args));
}
-Message::Ptr Api::sendAudio(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> audio,
+Message::Ptr Api::sendAudio(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> audio,
const std::string& caption,
std::int32_t duration,
const std::string& performer,
const std::string& title,
- boost::variant<InputFile::Ptr, const std::string&> thumb,
+ boost::variant<InputFile::Ptr, std::string> thumb,
std::int32_t replyToMessageId,
GenericReply::Ptr replyMarkup,
const std::string& parseMode,
@@ -276,15 +278,15 @@ Message::Ptr Api::sendAudio(boost::variant<std::int64_t, const std::string&> cha
const std::vector<MessageEntity::Ptr>& captionEntities,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(14);
args.emplace_back("chat_id", chatId);
if (audio.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(audio);
args.emplace_back("audio", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- args.emplace_back("audio", boost::get<const std::string&>(audio));
+ } else { // std::string
+ args.emplace_back("audio", boost::get<std::string>(audio));
}
if (!caption.empty()) {
args.emplace_back("caption", caption);
@@ -307,8 +309,8 @@ Message::Ptr Api::sendAudio(boost::variant<std::int64_t, const std::string&> cha
if (thumb.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(thumb);
args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- auto thumbStr = boost::get<const std::string&>(thumb);
+ } else { // std::string
+ auto thumbStr = boost::get<std::string>(thumb);
if (!thumbStr.empty()) {
args.emplace_back("thumb", thumbStr);
}
@@ -332,9 +334,9 @@ Message::Ptr Api::sendAudio(boost::variant<std::int64_t, const std::string&> cha
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args));
}
-Message::Ptr Api::sendDocument(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> document,
- boost::variant<InputFile::Ptr, const std::string&> thumb,
+Message::Ptr Api::sendDocument(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> document,
+ boost::variant<InputFile::Ptr, std::string> thumb,
const std::string& caption,
std::int32_t replyToMessageId,
GenericReply::Ptr replyMarkup,
@@ -344,21 +346,21 @@ Message::Ptr Api::sendDocument(boost::variant<std::int64_t, const std::string&>
bool disableContentTypeDetection,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(12);
args.emplace_back("chat_id", chatId);
if (document.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(document);
args.emplace_back("document", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- args.emplace_back("document", boost::get<const std::string&>(document));
+ } else { // std::string
+ args.emplace_back("document", boost::get<std::string>(document));
}
if (thumb.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(thumb);
args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- auto thumbStr = boost::get<const std::string&>(thumb);
+ } else { // std::string
+ auto thumbStr = boost::get<std::string>(thumb);
if (!thumbStr.empty()) {
args.emplace_back("thumb", thumbStr);
}
@@ -394,13 +396,13 @@ Message::Ptr Api::sendDocument(boost::variant<std::int64_t, const std::string&>
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDocument", args));
}
-Message::Ptr Api::sendVideo(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> video,
+Message::Ptr Api::sendVideo(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> video,
bool supportsStreaming,
std::int32_t duration,
std::int32_t width,
std::int32_t height,
- boost::variant<InputFile::Ptr, const std::string&> thumb,
+ boost::variant<InputFile::Ptr, std::string> thumb,
const std::string& caption ,
std::int32_t replyToMessageId,
GenericReply::Ptr replyMarkup,
@@ -409,15 +411,15 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, const std::string&> cha
const std::vector<MessageEntity::Ptr>& captionEntities,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(15);
args.emplace_back("chat_id", chatId);
if (video.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(video);
args.emplace_back("video", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- args.emplace_back("video", boost::get<const std::string&>(video));
+ } else { // std::string
+ args.emplace_back("video", boost::get<std::string>(video));
}
if (duration) {
args.emplace_back("duration", duration);
@@ -431,8 +433,8 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, const std::string&> cha
if (thumb.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(thumb);
args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- auto thumbStr = boost::get<const std::string&>(thumb);
+ } else { // std::string
+ auto thumbStr = boost::get<std::string>(thumb);
if (!thumbStr.empty()) {
args.emplace_back("thumb", thumbStr);
}
@@ -468,12 +470,12 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, const std::string&> cha
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args));
}
-Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> animation,
+Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> animation,
std::int32_t duration,
std::int32_t width,
std::int32_t height,
- boost::variant<InputFile::Ptr, const std::string&> thumb,
+ boost::variant<InputFile::Ptr, std::string> thumb,
const std::string& caption,
std::int32_t replyToMessageId,
GenericReply::Ptr replyMarkup,
@@ -482,15 +484,15 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, const std::string&>
const std::vector<MessageEntity::Ptr>& captionEntities,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(14);
args.emplace_back("chat_id", chatId);
if (animation.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(animation);
args.emplace_back("animation", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- args.emplace_back("animation", boost::get<const std::string&>(animation));
+ } else { // std::string
+ args.emplace_back("animation", boost::get<std::string>(animation));
}
if (duration) {
args.emplace_back("duration", duration);
@@ -504,8 +506,8 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, const std::string&>
if (thumb.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(thumb);
args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- auto thumbStr = boost::get<const std::string&>(thumb);
+ } else { // std::string
+ auto thumbStr = boost::get<std::string>(thumb);
if (!thumbStr.empty()) {
args.emplace_back("thumb", thumbStr);
}
@@ -538,8 +540,8 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, const std::string&>
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args));
}
-Message::Ptr Api::sendVoice(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> voice,
+Message::Ptr Api::sendVoice(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> voice,
const std::string& caption,
std::int32_t duration,
std::int32_t replyToMessageId,
@@ -549,15 +551,15 @@ Message::Ptr Api::sendVoice(boost::variant<std::int64_t, const std::string&> cha
const std::vector<MessageEntity::Ptr>& captionEntities,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(11);
args.emplace_back("chat_id", chatId);
if (voice.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(voice);
args.emplace_back("voice", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- args.emplace_back("voice", boost::get<const std::string&>(voice));
+ } else { // std::string
+ args.emplace_back("voice", boost::get<std::string>(voice));
}
if (!caption.empty()) {
args.emplace_back("caption", caption);
@@ -590,25 +592,25 @@ Message::Ptr Api::sendVoice(boost::variant<std::int64_t, const std::string&> cha
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args));
}
-Message::Ptr Api::sendVideoNote(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> videoNote,
+Message::Ptr Api::sendVideoNote(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> videoNote,
std::int64_t replyToMessageId,
bool disableNotification,
std::int32_t duration,
std::int32_t length,
- boost::variant<InputFile::Ptr, const std::string&> thumb,
+ boost::variant<InputFile::Ptr, std::string> thumb,
GenericReply::Ptr replyMarkup,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(10);
args.emplace_back("chat_id", chatId);
if (videoNote.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(videoNote);
args.emplace_back("video_note", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- args.emplace_back("video_note", boost::get<const std::string&>(videoNote));
+ } else { // std::string
+ args.emplace_back("video_note", boost::get<std::string>(videoNote));
}
if (duration) {
args.emplace_back("duration", duration);
@@ -619,8 +621,8 @@ Message::Ptr Api::sendVideoNote(boost::variant<std::int64_t, const std::string&>
if (thumb.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(thumb);
args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- auto thumbStr = boost::get<const std::string&>(thumb);
+ } else { // std::string
+ auto thumbStr = boost::get<std::string>(thumb);
if (!thumbStr.empty()) {
args.emplace_back("thumb", thumbStr);
}
@@ -644,13 +646,13 @@ Message::Ptr Api::sendVideoNote(boost::variant<std::int64_t, const std::string&>
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideoNote", args));
}
-vector<Message::Ptr> Api::sendMediaGroup(boost::variant<std::int64_t, const std::string&> chatId,
- const std::vector<InputMedia::Ptr>& media,
- bool disableNotification,
- std::int32_t replyToMessageId,
- bool allowSendingWithoutReply,
- bool protectContent) const {
- vector<HttpReqArg> args;
+std::vector<Message::Ptr> Api::sendMediaGroup(boost::variant<std::int64_t, std::string> chatId,
+ const std::vector<InputMedia::Ptr>& media,
+ bool disableNotification,
+ std::int32_t replyToMessageId,
+ bool allowSendingWithoutReply,
+ bool protectContent) const {
+ std::vector<HttpReqArg> args;
args.reserve(6);
args.emplace_back("chat_id", chatId);
@@ -671,7 +673,7 @@ vector<Message::Ptr> Api::sendMediaGroup(boost::variant<std::int64_t, const std:
return _tgTypeParser.parseJsonAndGetArray<Message>(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args));
}
-Message::Ptr Api::sendLocation(boost::variant<std::int64_t, const std::string&> chatId,
+Message::Ptr Api::sendLocation(boost::variant<std::int64_t, std::string> chatId,
float latitude,
float longitude,
std::int32_t livePeriod,
@@ -683,7 +685,7 @@ Message::Ptr Api::sendLocation(boost::variant<std::int64_t, const std::string&>
std::int32_t proximityAlertRadius,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(12);
args.emplace_back("chat_id", chatId);
@@ -693,13 +695,13 @@ Message::Ptr Api::sendLocation(boost::variant<std::int64_t, const std::string&>
args.emplace_back("horizontal_accuracy", horizontalAccuracy);
}
if (livePeriod) {
- args.emplace_back("live_period", livePeriod);
+ args.emplace_back("live_period", std::max(60, std::min(86400, livePeriod)));
}
if (heading) {
- args.emplace_back("heading", heading);
+ args.emplace_back("heading", std::max(1, std::min(360, heading)));
}
if (proximityAlertRadius) {
- args.emplace_back("proximity_alert_radius", proximityAlertRadius);
+ args.emplace_back("proximity_alert_radius", std::max(1, std::min(100000, proximityAlertRadius)));
}
if (disableNotification) {
args.emplace_back("disable_notification", disableNotification);
@@ -722,23 +724,23 @@ Message::Ptr Api::sendLocation(boost::variant<std::int64_t, const std::string&>
Message::Ptr Api::editMessageLiveLocation(float latitude,
float longitude,
- std::int64_t chatId,
+ boost::variant<std::int64_t, std::string> chatId,
std::int32_t messageId,
- std::int32_t inlineMessageId,
+ const std::string& inlineMessageId,
InlineKeyboardMarkup::Ptr replyMarkup,
float horizontalAccuracy,
std::int32_t heading,
std::int32_t proximityAlertRadius) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(9);
- if (chatId) {
+ if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) {
args.emplace_back("chat_id", chatId);
}
if (messageId) {
args.emplace_back("message_id", messageId);
}
- if (inlineMessageId) {
+ if (!inlineMessageId.empty()) {
args.emplace_back("inline_message_id", inlineMessageId);
}
args.emplace_back("latitude", latitude);
@@ -759,25 +761,30 @@ Message::Ptr Api::editMessageLiveLocation(float latitude,
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args));
}
-Message::Ptr Api::stopMessageLiveLocation(std::int64_t chatId, std::int32_t messageId, std::int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
- vector<HttpReqArg> args;
+Message::Ptr Api::stopMessageLiveLocation(boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId,
+ const std::string& inlineMessageId,
+ InlineKeyboardMarkup::Ptr replyMarkup) const {
+ std::vector<HttpReqArg> args;
args.reserve(4);
- if (chatId) {
+
+ if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) {
args.emplace_back("chat_id", chatId);
}
if (messageId) {
args.emplace_back("message_id", messageId);
}
- if (inlineMessageId) {
+ if (!inlineMessageId.empty()) {
args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup));
}
- return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args));
+
+ return _tgTypeParser.parseJsonAndGetMessage(sendRequest("stopMessageLiveLocation", args));
}
-Message::Ptr Api::sendVenue(boost::variant<std::int64_t, const std::string&> chatId,
+Message::Ptr Api::sendVenue(boost::variant<std::int64_t, std::string> chatId,
float latitude,
float longitude,
const std::string& title,
@@ -791,7 +798,7 @@ Message::Ptr Api::sendVenue(boost::variant<std::int64_t, const std::string&> cha
const std::string& googlePlaceType,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(14);
args.emplace_back("chat_id", chatId);
@@ -830,7 +837,7 @@ Message::Ptr Api::sendVenue(boost::variant<std::int64_t, const std::string&> cha
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args));
}
-Message::Ptr Api::sendContact(boost::variant<std::int64_t, const std::string&> chatId,
+Message::Ptr Api::sendContact(boost::variant<std::int64_t, std::string> chatId,
const std::string& phoneNumber,
const std::string& firstName,
const std::string& lastName ,
@@ -840,7 +847,7 @@ Message::Ptr Api::sendContact(boost::variant<std::int64_t, const std::string&> c
GenericReply::Ptr replyMarkup,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(10);
args.emplace_back("chat_id", chatId);
@@ -871,7 +878,7 @@ Message::Ptr Api::sendContact(boost::variant<std::int64_t, const std::string&> c
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendContact", args));
}
-Message::Ptr Api::sendPoll(boost::variant<std::int64_t, const std::string&> chatId,
+Message::Ptr Api::sendPoll(boost::variant<std::int64_t, std::string> chatId,
const std::string& question,
const std::vector<std::string>& options,
bool disableNotification,
@@ -889,13 +896,14 @@ Message::Ptr Api::sendPoll(boost::variant<std::int64_t, const std::string&> chat
bool isClosed,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(18);
args.emplace_back("chat_id", chatId);
args.emplace_back("question", question);
- args.emplace_back("options", _tgTypeParser.parseArray<std::string>([] (const std::string& option) -> std::string {
- return "\"" + StringTools::urlEncode(option) + "\"";
+ args.emplace_back("options", _tgTypeParser.parseArray<std::string>(
+ [](const std::string& option)->std::string {
+ return "\"" + StringTools::escapeJsonString(option) + "\"";
}, options));
if (!isAnonymous) {
args.emplace_back("is_anonymous", isAnonymous);
@@ -906,7 +914,7 @@ Message::Ptr Api::sendPoll(boost::variant<std::int64_t, const std::string&> chat
if (allowsMultipleAnswers) {
args.emplace_back("allows_multiple_answers", allowsMultipleAnswers);
}
- if (correctOptionId != 0) {
+ if (correctOptionId != -1) {
args.emplace_back("correct_option_id", correctOptionId);
}
if (!explanation.empty()) {
@@ -946,14 +954,14 @@ Message::Ptr Api::sendPoll(boost::variant<std::int64_t, const std::string&> chat
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args));
}
-Message::Ptr Api::sendDice(boost::variant<std::int64_t, const std::string&> chatId,
+Message::Ptr Api::sendDice(boost::variant<std::int64_t, std::string> chatId,
bool disableNotification,
std::int32_t replyToMessageId,
GenericReply::Ptr replyMarkup,
const std::string& emoji,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(7);
args.emplace_back("chat_id", chatId);
@@ -981,7 +989,7 @@ Message::Ptr Api::sendDice(boost::variant<std::int64_t, const std::string&> chat
bool Api::sendChatAction(std::int64_t chatId,
const std::string& action) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("chat_id", chatId);
@@ -990,67 +998,73 @@ bool Api::sendChatAction(std::int64_t chatId,
return sendRequest("sendChatAction", args).get<bool>("", false);
}
-UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, std::int32_t offset, std::int32_t limit) const {
- vector<HttpReqArg> args;
+UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId,
+ std::int32_t offset,
+ std::int32_t limit) const {
+ std::vector<HttpReqArg> args;
args.reserve(3);
+
args.emplace_back("user_id", userId);
if (offset) {
args.emplace_back("offset", offset);
}
- limit = max(1, min(100, limit));
- args.emplace_back("limit", limit);
+ if (limit != 100) {
+ args.emplace_back("limit", std::max(1, std::min(100, limit)));
+ }
+
return _tgTypeParser.parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args));
}
-File::Ptr Api::getFile(const string& fileId) const {
- vector<HttpReqArg> args;
+File::Ptr Api::getFile(const std::string& fileId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
- args.emplace_back("file_id", fileId);
- return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args));
-}
-string Api::downloadFile(const string& filePath, const std::vector<HttpReqArg>& args) const {
- string url(_url);
- url += "/file/bot";
- url += _token;
- url += "/";
- url += filePath;
-
- string serverResponse = _httpClient.makeRequest(url, args);
+ args.emplace_back("file_id", fileId);
- return serverResponse;
+ return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args));
}
-bool Api::banChatMember(std::int64_t chatId,
+bool Api::banChatMember(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId,
- std::uint64_t untilDate,
+ std::int32_t untilDate,
bool revokeMessages) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(4);
args.emplace_back("chat_id", chatId);
args.emplace_back("user_id", userId);
- args.emplace_back("until_date", untilDate);
- args.emplace_back("revoke_messages", revokeMessages);
+ if (untilDate != 0) {
+ args.emplace_back("until_date", untilDate);
+ }
+ if (revokeMessages) {
+ args.emplace_back("revoke_messages", revokeMessages);
+ }
return sendRequest("banChatMember", args).get<bool>("", false);
}
-bool Api::unbanChatMember(std::int64_t chatId, std::int64_t userId, bool onlyIfBanned) const {
- vector<HttpReqArg> args;
+bool Api::unbanChatMember(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t userId,
+ bool onlyIfBanned) const {
+ std::vector<HttpReqArg> args;
args.reserve(3);
args.emplace_back("chat_id", chatId);
args.emplace_back("user_id", userId);
- args.emplace_back("only_if_banned", onlyIfBanned);
+ if (onlyIfBanned) {
+ args.emplace_back("only_if_banned", onlyIfBanned);
+ }
return sendRequest("unbanChatMember", args).get<bool>("", false);
}
-bool Api::restrictChatMember(std::int64_t chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions,
- std::uint64_t untilDate) const {
- vector<HttpReqArg> args;
+bool Api::restrictChatMember(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t userId,
+ TgBot::ChatPermissions::Ptr permissions,
+ std::int64_t untilDate) const {
+ std::vector<HttpReqArg> args;
args.reserve(4);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("user_id", userId);
args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions));
@@ -1061,7 +1075,7 @@ bool Api::restrictChatMember(std::int64_t chatId, std::int64_t userId, TgBot::Ch
return sendRequest("restrictChatMember", args).get<bool>("", false);
}
-bool Api::promoteChatMember(boost::variant<std::int64_t, const std::string&> chatId,
+bool Api::promoteChatMember(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId,
bool canChangeInfo,
bool canPostMessages,
@@ -1074,7 +1088,7 @@ bool Api::promoteChatMember(boost::variant<std::int64_t, const std::string&> cha
bool canManageChat,
bool canManageVideoChats,
bool canRestrictMembers) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(13);
args.emplace_back("chat_id", chatId);
@@ -1116,8 +1130,10 @@ bool Api::promoteChatMember(boost::variant<std::int64_t, const std::string&> cha
return sendRequest("promoteChatMember", args).get<bool>("", false);
}
-bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const {
- vector<HttpReqArg> args;
+bool Api::setChatAdministratorCustomTitle(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t userId,
+ const std::string& customTitle) const {
+ std::vector<HttpReqArg> args;
args.reserve(3);
args.emplace_back("chat_id", chatId);
@@ -1127,9 +1143,9 @@ bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t user
return sendRequest("setChatAdministratorCustomTitle", args).get<bool>("", false);
}
-bool Api::banChatSenderChat(std::int64_t chatId,
- std::int64_t senderChatId) const {
- vector<HttpReqArg> args;
+bool Api::banChatSenderChat(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t senderChatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("chat_id", chatId);
@@ -1138,9 +1154,9 @@ bool Api::banChatSenderChat(std::int64_t chatId,
return sendRequest("banChatSenderChat", args).get<bool>("", false);
}
-bool Api::unbanChatSenderChat(std::int64_t chatId,
+bool Api::unbanChatSenderChat(boost::variant<std::int64_t, std::string> chatId,
std::int64_t senderChatId) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("chat_id", chatId);
@@ -1149,27 +1165,32 @@ bool Api::unbanChatSenderChat(std::int64_t chatId,
return sendRequest("unbanChatSenderChat", args).get<bool>("", false);
}
-bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const {
- vector<HttpReqArg> args;
+bool Api::setChatPermissions(boost::variant<std::int64_t, std::string> chatId,
+ ChatPermissions::Ptr permissions) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions));
+
return sendRequest("setChatPermissions", args).get<bool>("", false);
}
-string Api::exportChatInviteLink(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+std::string Api::exportChatInviteLink(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
+
args.emplace_back("chat_id", chatId);
+
return sendRequest("exportChatInviteLink", args).get("", "");
}
-ChatInviteLink::Ptr Api::createChatInviteLink(std::int64_t chatId,
+ChatInviteLink::Ptr Api::createChatInviteLink(boost::variant<std::int64_t, std::string> chatId,
std::int32_t expireDate,
std::int32_t memberLimit,
const std::string& name,
bool createsJoinRequest) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(5);
args.emplace_back("chat_id", chatId);
@@ -1189,13 +1210,13 @@ ChatInviteLink::Ptr Api::createChatInviteLink(std::int64_t chatId,
return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("createChatInviteLink", args));
}
-ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId,
+ChatInviteLink::Ptr Api::editChatInviteLink(boost::variant<std::int64_t, std::string> chatId,
const std::string& inviteLink,
std::int32_t expireDate,
std::int32_t memberLimit,
const std::string& name,
bool createsJoinRequest) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(6);
args.emplace_back("chat_id", chatId);
@@ -1216,9 +1237,9 @@ ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId,
return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("editChatInviteLink", args));
}
-ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId,
+ChatInviteLink::Ptr Api::revokeChatInviteLink(boost::variant<std::int64_t, std::string> chatId,
const std::string& inviteLink) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("chat_id", chatId);
@@ -1227,9 +1248,9 @@ ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId,
return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("revokeChatInviteLink", args));
}
-bool Api::approveChatJoinRequest(std::int64_t chatId,
+bool Api::approveChatJoinRequest(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("chat_id", chatId);
@@ -1238,9 +1259,9 @@ bool Api::approveChatJoinRequest(std::int64_t chatId,
return sendRequest("approveChatJoinRequest", args).get<bool>("", false);
}
-bool Api::declineChatJoinRequest(std::int64_t chatId,
+bool Api::declineChatJoinRequest(boost::variant<std::int64_t, std::string> chatId,
std::int64_t userId) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("chat_id", chatId);
@@ -1249,60 +1270,80 @@ bool Api::declineChatJoinRequest(std::int64_t chatId,
return sendRequest("declineChatJoinRequest", args).get<bool>("", false);
}
-bool Api::setChatPhoto(std::int64_t chatId, const InputFile::Ptr photo) const {
- vector<HttpReqArg> args;
+bool Api::setChatPhoto(boost::variant<std::int64_t, std::string> chatId,
+ const InputFile::Ptr photo) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName);
+
return sendRequest("setChatPhoto", args).get<bool>("", false);
}
-bool Api::deleteChatPhoto(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+bool Api::deleteChatPhoto(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
+
args.emplace_back("chat_id", chatId);
+
return sendRequest("deleteChatPhoto", args).get<bool>("", false);
}
-bool Api::setChatTitle(std::int64_t chatId, const string& title) const {
- vector<HttpReqArg> args;
+bool Api::setChatTitle(boost::variant<std::int64_t, std::string> chatId,
+ const std::string& title) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("title", title);
+
return sendRequest("setChatTitle", args).get<bool>("", false);
}
-bool Api::setChatDescription(std::int64_t chatId, const string& description) const {
- vector<HttpReqArg> args;
+bool Api::setChatDescription(boost::variant<std::int64_t, std::string> chatId,
+ const std::string& description) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("chat_id", chatId);
- args.emplace_back("description", description);
+ if (!description.empty()) {
+ args.emplace_back("description", description);
+ }
+
return sendRequest("setChatDescription", args).get<bool>("", false);
}
-bool Api::pinChatMessage(std::int64_t chatId, std::int32_t messageId, bool disableNotification) const {
- vector<HttpReqArg> args;
+bool Api::pinChatMessage(boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId,
+ bool disableNotification) const {
+ std::vector<HttpReqArg> args;
args.reserve(3);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("message_id", messageId);
if (disableNotification) {
args.emplace_back("disable_notification", disableNotification);
}
+
return sendRequest("pinChatMessage", args).get<bool>("", false);
}
-bool Api::unpinChatMessage(std::int64_t chatId, std::int32_t messageId) const {
- vector<HttpReqArg> args;
+bool Api::unpinChatMessage(boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("chat_id", chatId);
- args.emplace_back("message_id", messageId);
+ if (messageId != 0) {
+ args.emplace_back("message_id", messageId);
+ }
return sendRequest("unpinChatMessage", args).get<bool>("", false);
}
-bool Api::unpinAllChatMessages(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+bool Api::unpinAllChatMessages(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
args.emplace_back("chat_id", chatId);
@@ -1310,15 +1351,17 @@ bool Api::unpinAllChatMessages(std::int64_t chatId) const {
return sendRequest("unpinAllChatMessages", args).get<bool>("", false);
}
-bool Api::leaveChat(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+bool Api::leaveChat(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
+
args.emplace_back("chat_id", chatId);
+
return sendRequest("leaveChat", args).get<bool>("", false);
}
-Chat::Ptr Api::getChat(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+Chat::Ptr Api::getChat(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
args.emplace_back("chat_id", chatId);
@@ -1326,15 +1369,17 @@ Chat::Ptr Api::getChat(std::int64_t chatId) const {
return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args));
}
-vector<ChatMember::Ptr> Api::getChatAdministrators(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+std::vector<ChatMember::Ptr> Api::getChatAdministrators(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
+
args.emplace_back("chat_id", chatId);
+
return _tgTypeParser.parseJsonAndGetArray<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args));
}
-int32_t Api::getChatMemberCount(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+int32_t Api::getChatMemberCount(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
args.emplace_back("chat_id", chatId);
@@ -1342,32 +1387,45 @@ int32_t Api::getChatMemberCount(std::int64_t chatId) const {
return sendRequest("getChatMemberCount", args).get<int32_t>("", 0);
}
-ChatMember::Ptr Api::getChatMember(std::int64_t chatId, std::int64_t userId) const {
- vector<HttpReqArg> args;
+ChatMember::Ptr Api::getChatMember(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t userId) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("user_id", userId);
+
return _tgTypeParser.parseJsonAndGetChatMember(sendRequest("getChatMember", args));
}
-bool Api::setChatStickerSet(std::int64_t chatId, const string& stickerSetName) const {
- vector<HttpReqArg> args;
+bool Api::setChatStickerSet(boost::variant<std::int64_t, std::string> chatId,
+ const std::string& stickerSetName) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("sticker_set_name ", stickerSetName);
+
return sendRequest("setChatStickerSet", args).get<bool>("", false);
}
-bool Api::deleteChatStickerSet(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+bool Api::deleteChatStickerSet(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
+
args.emplace_back("chat_id", chatId);
+
return sendRequest("deleteChatStickerSet", args).get<bool>("", false);
}
-bool Api::answerCallbackQuery(const string& callbackQueryId, const string& text, bool showAlert, const string& url, std::int32_t cacheTime) const {
- vector<HttpReqArg> args;
+bool Api::answerCallbackQuery(const std::string& callbackQueryId,
+ const std::string& text,
+ bool showAlert,
+ const std::string& url,
+ std::int32_t cacheTime) const {
+ std::vector<HttpReqArg> args;
args.reserve(5);
+
args.emplace_back("callback_query_id", callbackQueryId);
if (!text.empty()) {
args.emplace_back("text", text);
@@ -1381,13 +1439,14 @@ bool Api::answerCallbackQuery(const string& callbackQueryId, const string& text,
if (cacheTime) {
args.emplace_back("cache_time", cacheTime);
}
+
return sendRequest("answerCallbackQuery", args).get<bool>("", false);
}
bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands,
BotCommandScope::Ptr scope,
const std::string& languageCode) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(3);
args.emplace_back("commands", _tgTypeParser.parseArray<BotCommand>(&TgTypeParser::parseBotCommand, commands));
@@ -1403,7 +1462,7 @@ bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands,
bool Api::deleteMyCommands(BotCommandScope::Ptr scope,
const std::string& languageCode) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
if (scope != nullptr) {
@@ -1418,7 +1477,7 @@ bool Api::deleteMyCommands(BotCommandScope::Ptr scope,
std::vector<BotCommand::Ptr> Api::getMyCommands(BotCommandScope::Ptr scope,
const std::string& languageCode) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
;
if (scope != nullptr) {
@@ -1433,7 +1492,7 @@ std::vector<BotCommand::Ptr> Api::getMyCommands(BotCommandScope::Ptr scope,
bool Api::setChatMenuButton(std::int64_t chatId,
MenuButton::Ptr menuButton) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
if (chatId != 0) {
@@ -1447,7 +1506,7 @@ bool Api::setChatMenuButton(std::int64_t chatId,
}
MenuButton::Ptr Api::getChatMenuButton(std::int64_t chatId) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(1);
if (chatId != 0) {
@@ -1458,8 +1517,8 @@ MenuButton::Ptr Api::getChatMenuButton(std::int64_t chatId) const {
}
bool Api::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights,
- bool forChannels) const {
- vector<HttpReqArg> args;
+ bool forChannels) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
if (rights != nullptr) {
@@ -1473,7 +1532,7 @@ bool Api::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights,
}
ChatAdministratorRights::Ptr Api::getMyDefaultAdministratorRights(bool forChannels) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(1);
if (forChannels) {
@@ -1484,17 +1543,17 @@ ChatAdministratorRights::Ptr Api::getMyDefaultAdministratorRights(bool forChanne
}
Message::Ptr Api::editMessageText(const std::string& text,
- std::int64_t chatId,
+ boost::variant<std::int64_t, std::string> chatId,
std::int32_t messageId,
const std::string& inlineMessageId,
const std::string& parseMode,
bool disableWebPagePreview,
GenericReply::Ptr replyMarkup,
const std::vector<MessageEntity::Ptr>& entities) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(8);
- if (chatId) {
+ if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) {
args.emplace_back("chat_id", chatId);
}
if (messageId) {
@@ -1517,7 +1576,7 @@ Message::Ptr Api::editMessageText(const std::string& text,
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
- ptree p = sendRequest("editMessageText", args);
+ boost::property_tree::ptree p = sendRequest("editMessageText", args);
if (p.get_child_optional("message_id")) {
return _tgTypeParser.parseJsonAndGetMessage(p);
} else {
@@ -1525,17 +1584,17 @@ Message::Ptr Api::editMessageText(const std::string& text,
}
}
-Message::Ptr Api::editMessageCaption(std::int64_t chatId,
+Message::Ptr Api::editMessageCaption(boost::variant<std::int64_t, std::string> chatId,
std::int32_t messageId,
const std::string& caption,
const std::string& inlineMessageId,
GenericReply::Ptr replyMarkup,
const std::string& parseMode,
const std::vector<MessageEntity::Ptr>& captionEntities) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(7);
- if (chatId) {
+ if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) {
args.emplace_back("chat_id", chatId);
}
if (messageId) {
@@ -1557,7 +1616,7 @@ Message::Ptr Api::editMessageCaption(std::int64_t chatId,
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
- ptree p = sendRequest("editMessageCaption", args);
+ boost::property_tree::ptree p = sendRequest("editMessageCaption", args);
if (p.get_child_optional("message_id")) {
return _tgTypeParser.parseJsonAndGetMessage(p);
} else {
@@ -1565,13 +1624,17 @@ Message::Ptr Api::editMessageCaption(std::int64_t chatId,
}
}
-Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId,
+Message::Ptr Api::editMessageMedia(InputMedia::Ptr media,
+ boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId,
+ const std::string& inlineMessageId,
GenericReply::Ptr replyMarkup) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(5);
+
args.emplace_back("media", _tgTypeParser.parseInputMedia(media));
- if (chatId) {
+ if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) {
args.emplace_back("chat_id", chatId);
}
if (messageId) {
@@ -1583,7 +1646,8 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, s
if (replyMarkup) {
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
- ptree p = sendRequest("editMessageMedia", args);
+
+ boost::property_tree::ptree p = sendRequest("editMessageMedia", args);
if (p.get_child_optional("message_id")) {
return _tgTypeParser.parseJsonAndGetMessage(p);
} else {
@@ -1591,12 +1655,15 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, s
}
}
-Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messageId, const string& inlineMessageId,
+Message::Ptr Api::editMessageReplyMarkup(boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId,
+ const std::string& inlineMessageId,
const GenericReply::Ptr replyMarkup) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(4);
- if (chatId) {
+
+ if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) {
args.emplace_back("chat_id", chatId);
}
if (messageId) {
@@ -1608,7 +1675,8 @@ Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messa
if (replyMarkup) {
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
- ptree p = sendRequest("editMessageReplyMarkup", args);
+
+ boost::property_tree::ptree p = sendRequest("editMessageReplyMarkup", args);
if (p.get_child_optional("message_id")) {
return _tgTypeParser.parseJsonAndGetMessage(p);
} else {
@@ -1616,37 +1684,48 @@ Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messa
}
}
-Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
- vector<HttpReqArg> args;
+Poll::Ptr Api::stopPoll(boost::variant<std::int64_t, std::string> chatId,
+ std::int64_t messageId,
+ const InlineKeyboardMarkup::Ptr replyMarkup) const {
+ std::vector<HttpReqArg> args;
args.reserve(3);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("message_id", messageId);
if (replyMarkup) {
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
+
return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args));
}
-void Api::deleteMessage(std::int64_t chatId, std::int32_t messageId) const {
- sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) });
+bool Api::deleteMessage(boost::variant<std::int64_t, std::string> chatId,
+ std::int32_t messageId) const {
+ std::vector<HttpReqArg> args;
+ args.reserve(2);
+
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("message_id", messageId);
+
+ return sendRequest("deleteMessage", args).get<bool>("", false);
}
-Message::Ptr Api::sendSticker(boost::variant<std::int64_t, const std::string&> chatId,
- boost::variant<InputFile::Ptr, const std::string&> sticker,
+Message::Ptr Api::sendSticker(boost::variant<std::int64_t, std::string> chatId,
+ boost::variant<InputFile::Ptr, std::string> sticker,
std::int32_t replyToMessageId,
GenericReply::Ptr replyMarkup,
bool disableNotification,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(7);
args.emplace_back("chat_id", chatId);
if (sticker.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(sticker);
args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName);
- } else { // const std::string&
- args.emplace_back("sticker", boost::get<const std::string&>(sticker));
+ } else { // std::string
+ args.emplace_back("sticker", boost::get<std::string>(sticker));
}
if (disableNotification) {
args.emplace_back("disable_notification", disableNotification);
@@ -1667,8 +1746,8 @@ Message::Ptr Api::sendSticker(boost::variant<std::int64_t, const std::string&> c
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendSticker", args));
}
-StickerSet::Ptr Api::getStickerSet(const string& name) const {
- vector<HttpReqArg> args;
+StickerSet::Ptr Api::getStickerSet(const std::string& name) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
args.emplace_back("name", name);
@@ -1677,21 +1756,24 @@ StickerSet::Ptr Api::getStickerSet(const string& name) const {
}
std::vector<Sticker::Ptr> Api::getCustomEmojiStickers(const std::vector<std::string>& customEmojiIds) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(1);
args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray<std::string>([] (const std::string& customEmojiId) -> std::string {
- return "\"" + StringTools::urlEncode(customEmojiId) + "\"";
+ return "\"" + StringTools::escapeJsonString(customEmojiId) + "\"";
}, customEmojiIds));
return _tgTypeParser.parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args));
}
-File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSticker) const {
- vector<HttpReqArg> args;
+File::Ptr Api::uploadStickerFile(std::int64_t userId,
+ const InputFile::Ptr pngSticker) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("user_id", userId);
args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName);
+
return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args));
}
@@ -1700,11 +1782,11 @@ bool Api::createNewStickerSet(std::int64_t userId,
const std::string& title,
const std::string& emojis,
MaskPosition::Ptr maskPosition,
- boost::variant<InputFile::Ptr, const std::string&> pngSticker,
+ boost::variant<InputFile::Ptr, std::string> pngSticker,
InputFile::Ptr tgsSticker,
InputFile::Ptr webmSticker,
const std::string& stickerType) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(10);
args.emplace_back("user_id", userId);
@@ -1713,8 +1795,8 @@ bool Api::createNewStickerSet(std::int64_t userId,
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 { // const std::string&
- args.emplace_back("png_sticker", boost::get<const std::string&>(pngSticker));
+ } else { // std::string
+ args.emplace_back("png_sticker", boost::get<std::string>(pngSticker));
}
if (tgsSticker != nullptr) {
args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName);
@@ -1737,10 +1819,10 @@ bool Api::addStickerToSet(std::int64_t userId,
const std::string& name,
const std::string& emojis,
MaskPosition::Ptr maskPosition,
- boost::variant<InputFile::Ptr, const std::string&> pngSticker,
+ boost::variant<InputFile::Ptr, std::string> pngSticker,
InputFile::Ptr tgsSticker,
InputFile::Ptr webmSticker) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(7);
args.emplace_back("user_id", userId);
@@ -1749,8 +1831,8 @@ bool Api::addStickerToSet(std::int64_t userId,
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 { // const std::string&
- args.emplace_back("png_sticker", boost::get<const std::string&>(pngSticker));
+ } else { // std::string
+ args.emplace_back("png_sticker", boost::get<std::string>(pngSticker));
}
if (tgsSticker != nullptr) {
args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName);
@@ -1766,44 +1848,56 @@ bool Api::addStickerToSet(std::int64_t userId,
return sendRequest("addStickerToSet", args).get<bool>("", false);
}
-bool Api::setStickerPositionInSet(const string& sticker, std::uint32_t position) const {
- vector<HttpReqArg> args;
+bool Api::setStickerPositionInSet(const std::string& sticker,
+ std::int32_t position) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("sticker", sticker);
args.emplace_back("position", position);
+
return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
}
-bool Api::deleteStickerFromSet(const string& sticker) const {
- vector<HttpReqArg> args;
+bool Api::deleteStickerFromSet(const std::string& sticker) const {
+ std::vector<HttpReqArg> args;
args.reserve(1);
+
args.emplace_back("sticker", sticker);
+
return sendRequest("deleteStickerFromSet", args).get<bool>("", false);
}
-bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant<InputFile::Ptr, std::string> thumb) const {
- vector<HttpReqArg> args;
+bool Api::setStickerSetThumb(const std::string& name,
+ std::int64_t userId,
+ boost::variant<InputFile::Ptr, std::string> thumb) const {
+ std::vector<HttpReqArg> args;
args.reserve(3);
args.emplace_back("name", name);
args.emplace_back("user_id", userId);
- if (thumb.which() == 0 /* InputFile::Ptr */) {
+ if (thumb.which() == 0) { // InputFile::Ptr
auto file = boost::get<InputFile::Ptr>(thumb);
args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName);
- } else /* std::string */ {
+ } else { // std::string
args.emplace_back("thumb", boost::get<std::string>(thumb));
}
return sendRequest("setStickerSetThumb", args).get<bool>("", false);
}
-bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
- std::int32_t cacheTime, bool isPersonal, const string& nextOffset, const string& switchPmText, const string& switchPmParameter) const {
- vector<HttpReqArg> args;
+bool Api::answerInlineQuery(const std::string& inlineQueryId,
+ const std::vector<InlineQueryResult::Ptr>& results,
+ std::int32_t cacheTime,
+ bool isPersonal,
+ const std::string& nextOffset,
+ const std::string& switchPmText,
+ const std::string& switchPmParameter) const {
+ std::vector<HttpReqArg> args;
args.reserve(7);
+
args.emplace_back("inline_query_id", inlineQueryId);
- string resultsJson = _tgTypeParser.parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results);
- args.emplace_back("results", resultsJson);
+ args.emplace_back("results", _tgTypeParser.parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results));
if (cacheTime) {
args.emplace_back("cache_time", cacheTime);
}
@@ -1819,12 +1913,13 @@ bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector<Inlin
if (!switchPmParameter.empty()) {
args.emplace_back("switch_pm_parameter", switchPmParameter);
}
+
return sendRequest("answerInlineQuery", args).get<bool>("", false);
}
SentWebAppMessage::Ptr Api::answerWebAppQuery(const std::string& webAppQueryId,
InlineQueryResult::Ptr result) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("web_app_query_id", webAppQueryId);
@@ -1833,7 +1928,7 @@ SentWebAppMessage::Ptr Api::answerWebAppQuery(const std::string& webAppQueryId,
return _tgTypeParser.parseJsonAndGetSentWebAppMessage(sendRequest("answerWebAppQuery", args));
}
-Message::Ptr Api::sendInvoice(boost::variant<std::int64_t, const std::string&> chatId,
+Message::Ptr Api::sendInvoice(boost::variant<std::int64_t, std::string> chatId,
const std::string& title,
const std::string& description,
const std::string& payload,
@@ -1860,7 +1955,7 @@ Message::Ptr Api::sendInvoice(boost::variant<std::int64_t, const std::string&> c
const std::vector<std::int32_t>& suggestedTipAmounts,
const std::string& startParameter,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(27);
args.emplace_back("chat_id", chatId);
@@ -1954,7 +2049,7 @@ std::string Api::createInvoiceLink(const std::string& title,
bool sendPhoneNumberToProvider,
bool sendEmailToProvider,
bool isFlexible) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(20);
args.emplace_back("title", title);
@@ -2009,9 +2104,13 @@ std::string Api::createInvoiceLink(const std::string& title,
return sendRequest("createInvoiceLink", args).get<std::string>("", "");
}
-bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector<ShippingOption::Ptr>& shippingOptions, const std::string& errorMessage) const {
- vector<HttpReqArg> args;
+bool Api::answerShippingQuery(const std::string& shippingQueryId,
+ bool ok,
+ const std::vector<ShippingOption::Ptr>& shippingOptions,
+ const std::string& errorMessage) const {
+ std::vector<HttpReqArg> args;
args.reserve(4);
+
args.emplace_back("shipping_query_id", shippingQueryId);
args.emplace_back("ok", ok);
if (!shippingOptions.empty()) {
@@ -2020,22 +2119,28 @@ bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const
if (!errorMessage.empty()) {
args.emplace_back("error_message", errorMessage);
}
+
return sendRequest("answerShippingQuery", args).get<bool>("", false);
}
-bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage) const {
- vector<HttpReqArg> args;
+bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId,
+ bool ok,
+ const std::string& errorMessage) const {
+ std::vector<HttpReqArg> args;
args.reserve(3);
+
args.emplace_back("pre_checkout_query_id", preCheckoutQueryId);
args.emplace_back("ok", ok);
if (!errorMessage.empty()) {
args.emplace_back("error_message", errorMessage);
}
+
return sendRequest("answerPreCheckoutQuery", args).get<bool>("", false);
}
-bool Api::setPassportDataErrors(std::int64_t userId, const std::vector<PassportElementError::Ptr>& errors) const {
- vector<HttpReqArg> args;
+bool Api::setPassportDataErrors(std::int64_t userId,
+ const std::vector<PassportElementError::Ptr>& errors) const {
+ std::vector<HttpReqArg> args;
args.reserve(2);
args.emplace_back("user_id", userId);
@@ -2051,7 +2156,7 @@ Message::Ptr Api::sendGame(std::int64_t chatId,
bool disableNotification,
bool allowSendingWithoutReply,
bool protectContent) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(7);
args.emplace_back("chat_id", chatId);
@@ -2075,9 +2180,16 @@ Message::Ptr Api::sendGame(std::int64_t chatId,
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendGame", args));
}
-Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool force, bool disableEditMessage, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const {
- vector<HttpReqArg> args;
+Message::Ptr Api::setGameScore(std::int64_t userId,
+ std::int32_t score,
+ bool force,
+ bool disableEditMessage,
+ std::int64_t chatId,
+ std::int32_t messageId,
+ const std::string& inlineMessageId) const {
+ std::vector<HttpReqArg> args;
args.reserve(7);
+
args.emplace_back("user_id", userId);
args.emplace_back("score", score);
if (force) {
@@ -2095,14 +2207,15 @@ Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool for
if (!inlineMessageId.empty()) {
args.emplace_back("inline_message_id", inlineMessageId);
}
+
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("setGameScore", args));
}
-vector<GameHighScore::Ptr> Api::getGameHighScores(std::int64_t userId,
+std::vector<GameHighScore::Ptr> Api::getGameHighScores(std::int64_t userId,
std::int64_t chatId,
std::int32_t messageId,
const std::string& inlineMessageId) const {
- vector<HttpReqArg> args;
+ std::vector<HttpReqArg> args;
args.reserve(4);
args.emplace_back("user_id", userId);
@@ -2119,19 +2232,47 @@ vector<GameHighScore::Ptr> Api::getGameHighScores(std::int64_t userId,
return _tgTypeParser.parseJsonAndGetArray<GameHighScore>(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args));
}
-ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) const {
- string url(_url);
+std::string Api::downloadFile(const std::string& filePath,
+ const std::vector<HttpReqArg>& args) const {
+ std::string url(_url);
+ url += "/file/bot";
+ url += _token;
+ url += "/";
+ url += filePath;
+
+ return _httpClient.makeRequest(url, args);
+}
+
+bool Api::blockedByUser(std::int64_t chatId) const {
+ bool isBotBlocked = false;
+
+ try {
+ sendChatAction(chatId, "typing");
+
+ } catch (std::exception& e) {
+ std::string error = e.what();
+
+ if (error.compare("Forbidden: bot was blocked by the user") == 0) {
+ isBotBlocked = true;
+ }
+ }
+
+ return isBotBlocked;
+}
+
+boost::property_tree::ptree Api::sendRequest(const std::string& method, const std::vector<HttpReqArg>& args) const {
+ std::string url(_url);
url += "/bot";
url += _token;
url += "/";
url += method;
- string serverResponse = _httpClient.makeRequest(url, args);
+ std::string serverResponse = _httpClient.makeRequest(url, args);
if (!serverResponse.compare(0, 6, "<html>")) {
throw TgException("tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token.");
}
- ptree result = _tgTypeParser.parseJson(serverResponse);
+ boost::property_tree::ptree result = _tgTypeParser.parseJson(serverResponse);
try {
if (result.get<bool>("ok", false)) {
return result.get_child("result");
@@ -2139,7 +2280,7 @@ ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) con
throw TgException(result.get("description", ""));
}
} catch (boost::property_tree::ptree_error& e) {
- throw TgException("tgbot-cpp library can't parse json response. " + string(e.what()));
+ throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what()));
}
}
}
diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp
index edf4c13..1a6ed40 100644
--- a/src/EventHandler.cpp
+++ b/src/EventHandler.cpp
@@ -1,14 +1,20 @@
#include "tgbot/EventHandler.h"
-#include <algorithm>
-#include <cstddef>
-#include <string>
-
-using namespace std;
-
namespace TgBot {
void EventHandler::handleUpdate(const Update::Ptr& update) const {
+ if (update->message != nullptr) {
+ handleMessage(update->message);
+ }
+ if (update->editedMessage != nullptr) {
+ _broadcaster.broadcastEditedMessage(update->editedMessage);
+ }
+ if (update->channelPost != nullptr) {
+ handleMessage(update->channelPost);
+ }
+ if (update->editedChannelPost != nullptr) {
+ _broadcaster.broadcastEditedMessage(update->editedChannelPost);
+ }
if (update->inlineQuery != nullptr) {
_broadcaster.broadcastInlineQuery(update->inlineQuery);
}
@@ -18,11 +24,26 @@ void EventHandler::handleUpdate(const Update::Ptr& update) const {
if (update->callbackQuery != nullptr) {
_broadcaster.broadcastCallbackQuery(update->callbackQuery);
}
- if (update->message != nullptr) {
- handleMessage(update->message);
+ if (update->shippingQuery != nullptr) {
+ _broadcaster.broadcastShippingQuery(update->shippingQuery);
}
- if (update->channelPost != nullptr) {
- handleMessage(update->channelPost);
+ if (update->preCheckoutQuery != nullptr) {
+ _broadcaster.broadcastPreCheckoutQuery(update->preCheckoutQuery);
+ }
+ if (update->poll != nullptr) {
+ _broadcaster.broadcastPoll(update->poll);
+ }
+ if (update->pollAnswer != nullptr) {
+ _broadcaster.broadcastPollAnswer(update->pollAnswer);
+ }
+ if (update->myChatMember != nullptr) {
+ _broadcaster.broadcastMyChatMember(update->myChatMember);
+ }
+ if (update->chatMember != nullptr) {
+ _broadcaster.broadcastChatMember(update->chatMember);
+ }
+ if (update->chatJoinRequest != nullptr) {
+ _broadcaster.broadcastChatJoinRequest(update->chatJoinRequest);
}
}
@@ -33,13 +54,13 @@ void EventHandler::handleMessage(const Message::Ptr& message) const {
std::size_t splitPosition;
std::size_t spacePosition = message->text.find(' ');
std::size_t atSymbolPosition = message->text.find('@');
- if (spacePosition == string::npos) {
- if (atSymbolPosition == string::npos) {
+ if (spacePosition == std::string::npos) {
+ if (atSymbolPosition == std::string::npos) {
splitPosition = message->text.size();
} else {
splitPosition = atSymbolPosition;
}
- } else if (atSymbolPosition == string::npos) {
+ } else if (atSymbolPosition == std::string::npos) {
splitPosition = spacePosition;
} else {
splitPosition = std::min(spacePosition, atSymbolPosition);
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index d251da6..1f49489 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -1,10 +1,133 @@
#include "tgbot/TgTypeParser.h"
-#include <memory>
-#include <string>
-
namespace TgBot {
+Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Update>());
+ result->updateId = data.get<std::int32_t>("update_id", 0);
+ result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message");
+ result->editedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message");
+ result->channelPost = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "channel_post");
+ result->editedChannelPost = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_channel_post");
+ result->inlineQuery = tryParseJson<InlineQuery>(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query");
+ result->chosenInlineResult = tryParseJson<ChosenInlineResult>(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result");
+ result->callbackQuery = tryParseJson<CallbackQuery>(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query");
+ result->shippingQuery = tryParseJson<ShippingQuery>(&TgTypeParser::parseJsonAndGetShippingQuery, data, "shipping_query");
+ result->preCheckoutQuery = tryParseJson<PreCheckoutQuery>(&TgTypeParser::parseJsonAndGetPreCheckoutQuery, data, "pre_checkout_query");
+ result->poll = tryParseJson<Poll>(&TgTypeParser::parseJsonAndGetPoll, data, "poll");
+ result->pollAnswer = tryParseJson<PollAnswer>(&TgTypeParser::parseJsonAndGetPollAnswer, data, "poll_answer");
+ result->myChatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "my_chat_member");
+ result->chatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "chat_member");
+ result->chatJoinRequest = tryParseJson<ChatJoinRequest>(&TgTypeParser::parseJsonAndGetChatJoinRequest, data, "chat_join_request");
+ return result;
+}
+
+std::string TgTypeParser::parseUpdate(const Update::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "update_id", object->updateId);
+ appendToJson(result, "message", parseMessage(object->message));
+ appendToJson(result, "edited_message", parseMessage(object->editedMessage));
+ appendToJson(result, "channel_post", parseMessage(object->channelPost));
+ appendToJson(result, "edited_channel_post", parseMessage(object->editedChannelPost));
+ appendToJson(result, "inline_query", parseInlineQuery(object->inlineQuery));
+ appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult));
+ appendToJson(result, "callback_query", parseCallbackQuery(object->callbackQuery));
+ appendToJson(result, "shipping_query", parseShippingQuery(object->shippingQuery));
+ appendToJson(result, "pre_checkout_query", parsePreCheckoutQuery(object->preCheckoutQuery));
+ appendToJson(result, "poll", parsePoll(object->poll));
+ appendToJson(result, "poll_answer", parsePollAnswer(object->pollAnswer));
+ appendToJson(result, "my_chat_member", parseChatMemberUpdated(object->myChatMember));
+ appendToJson(result, "chat_member", parseChatMemberUpdated(object->chatMember));
+ appendToJson(result, "chat_join_request", parseChatJoinRequest(object->chatJoinRequest));
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<WebhookInfo>());
+ result->url = data.get<std::string>("url", "");
+ result->hasCustomCertificate = data.get<bool>("has_custom_certificate", false);
+ result->pendingUpdateCount = data.get<std::int32_t>("pending_update_count", 0);
+ result->ipAddress = data.get<std::string>("ip_address", "");
+ result->lastErrorDate = data.get<std::int32_t>("last_error_date", 0);
+ result->lastErrorMessage = data.get<std::string>("last_error_message", "");
+ result->lastSynchronizationErrorDate = data.get<std::int32_t>("last_synchronization_error_date", 0);
+ result->maxConnections = data.get<std::int32_t>("max_connections", 0);
+ result->allowedUpdates = parseJsonAndGetArray<std::string>(
+ [] (const boost::property_tree::ptree& innerData)->std::string {
+ return innerData.get<std::string>("");
+ }
+ , data, "allowed_updates");
+ return result;
+}
+
+std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "url", object->url);
+ appendToJson(result, "has_custom_certificate", object->hasCustomCertificate);
+ appendToJson(result, "pending_update_count", object->pendingUpdateCount);
+ appendToJson(result, "ip_address", object->ipAddress);
+ appendToJson(result, "last_error_date", object->lastErrorDate);
+ appendToJson(result, "last_error_message", object->lastErrorMessage);
+ appendToJson(result, "last_synchronization_error_date", object->lastSynchronizationErrorDate);
+ appendToJson(result, "max_connections", object->maxConnections);
+ appendToJson(result, "allowed_updates",
+ parseArray<std::string>([] (const std::string& s)->std::string {
+ return s;
+ }
+ , object->allowedUpdates));
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+User::Ptr TgTypeParser::parseJsonAndGetUser(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<User>());
+ result->id = data.get<std::int64_t>("id", 0);
+ result->isBot = data.get<bool>("is_bot", false);
+ result->firstName = data.get<std::string>("first_name", "");
+ result->lastName = data.get<std::string>("last_name", "");
+ result->username = data.get<std::string>("username", "");
+ result->languageCode = data.get<std::string>("language_code", "");
+ result->isPremium = data.get<bool>("is_premium", false);
+ result->addedToAttachmentMenu = data.get<bool>("added_to_attachment_menu", false);
+ result->canJoinGroups = data.get<bool>("can_join_groups", false);
+ result->canReadAllGroupMessages = data.get<bool>("can_read_all_group_messages", false);
+ result->supportsInlineQueries = data.get<bool>("supports_inline_queries", false);
+ return result;
+}
+
+std::string TgTypeParser::parseUser(const User::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "id", object->id);
+ appendToJson(result, "is_bot", object->isBot);
+ appendToJson(result, "first_name", object->firstName);
+ appendToJson(result, "last_name", object->lastName);
+ appendToJson(result, "username", object->username);
+ appendToJson(result, "language_code", object->languageCode);
+ appendToJson(result, "is_premium", object->isPremium);
+ appendToJson(result, "added_to_attachment_menu", object->addedToAttachmentMenu);
+ appendToJson(result, "can_join_groups", object->canJoinGroups);
+ appendToJson(result, "can_read_all_group_messages", object->canReadAllGroupMessages);
+ appendToJson(result, "supports_inline_queries", object->supportsInlineQueries);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<Chat>());
result->id = data.get<std::int64_t>("id", 0);
@@ -84,143 +207,6 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const {
return result;
}
-User::Ptr TgTypeParser::parseJsonAndGetUser(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<User>());
- result->id = data.get<std::int64_t>("id", 0);
- result->isBot = data.get<bool>("is_bot", false);
- result->firstName = data.get<std::string>("first_name", "");
- result->lastName = data.get<std::string>("last_name", "");
- result->username = data.get<std::string>("username", "");
- result->languageCode = data.get<std::string>("language_code", "");
- result->isPremium = data.get<bool>("is_premium", false);
- result->addedToAttachmentMenu = data.get<bool>("added_to_attachment_menu", false);
- result->canJoinGroups = data.get<bool>("can_join_groups", false);
- result->canReadAllGroupMessages = data.get<bool>("can_read_all_group_messages", false);
- result->supportsInlineQueries = data.get<bool>("supports_inline_queries", false);
- return result;
-}
-
-std::string TgTypeParser::parseUser(const User::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "id", object->id);
- appendToJson(result, "is_bot", object->isBot);
- appendToJson(result, "first_name", object->firstName);
- appendToJson(result, "last_name", object->lastName);
- appendToJson(result, "username", object->username);
- appendToJson(result, "language_code", object->languageCode);
- appendToJson(result, "is_premium", object->isPremium);
- appendToJson(result, "added_to_attachment_menu", object->addedToAttachmentMenu);
- appendToJson(result, "can_join_groups", object->canJoinGroups);
- appendToJson(result, "can_read_all_group_messages", object->canReadAllGroupMessages);
- appendToJson(result, "supports_inline_queries", object->supportsInlineQueries);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-MessageEntity::Ptr TgTypeParser::parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const{
- auto result(std::make_shared<MessageEntity>());
- std::string type = data.get<std::string>("type", "");
- if (type == "mention") {
- result->type = MessageEntity::Type::Mention;
- } else if (type == "hashtag") {
- result->type = MessageEntity::Type::Hashtag;
- } else if (type == "cashtag") {
- result->type = MessageEntity::Type::Cashtag;
- } else if (type == "bot_command") {
- result->type = MessageEntity::Type::BotCommand;
- } else if (type == "url") {
- result->type = MessageEntity::Type::Url;
- } else if (type == "email") {
- result->type = MessageEntity::Type::Email;
- } else if (type == "phone_number") {
- result->type = MessageEntity::Type::PhoneNumber;
- } else if (type == "bold") {
- result->type = MessageEntity::Type::Bold;
- } else if (type == "italic") {
- result->type = MessageEntity::Type::Italic;
- } else if (type == "underline") {
- result->type = MessageEntity::Type::Underline;
- } else if (type == "strikethrough") {
- result->type = MessageEntity::Type::Strikethrough;
- } else if (type == "spoiler") {
- result->type = MessageEntity::Type::Spoiler;
- } else if (type == "code") {
- result->type = MessageEntity::Type::Code;
- } else if (type == "pre") {
- result->type = MessageEntity::Type::Pre;
- } else if (type == "text_link") {
- result->type = MessageEntity::Type::TextLink;
- } else if (type == "text_mention") {
- result->type = MessageEntity::Type::TextMention;
- } else if (type == "custom_emoji") {
- result->type = MessageEntity::Type::CustomEmoji;
- }
- result->offset = data.get<std::int32_t>("offset", 0);
- result->length = data.get<std::int32_t>("length", 0);
- result->url = data.get<std::string>("url", "");
- result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user");
- result->language = data.get<std::string>("language", "");
- result->customEmojiId = data.get<std::string>("custom_emoji_id", "");
- return result;
-}
-
-std::string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- if (object->type == MessageEntity::Type::Mention) {
- appendToJson(result, "type", "mention");
- } else if (object->type == MessageEntity::Type::Hashtag) {
- appendToJson(result, "type", "hashtag");
- } else if (object->type == MessageEntity::Type::Cashtag) {
- appendToJson(result, "type", "cashtag");
- } else if (object->type == MessageEntity::Type::BotCommand) {
- appendToJson(result, "type", "bot_command");
- } else if (object->type == MessageEntity::Type::Url) {
- appendToJson(result, "type", "url");
- } else if (object->type == MessageEntity::Type::Email) {
- appendToJson(result, "type", "email");
- } else if (object->type == MessageEntity::Type::PhoneNumber) {
- appendToJson(result, "type", "phone_number");
- } else if (object->type == MessageEntity::Type::Bold) {
- appendToJson(result, "type", "bold");
- } else if (object->type == MessageEntity::Type::Italic) {
- appendToJson(result, "type", "italic");
- } else if (object->type == MessageEntity::Type::Underline) {
- appendToJson(result, "type", "underline");
- } else if (object->type == MessageEntity::Type::Strikethrough) {
- appendToJson(result, "type", "strikethrough");
- } else if (object->type == MessageEntity::Type::Spoiler) {
- appendToJson(result, "type", "spoiler");
- } else if (object->type == MessageEntity::Type::Code) {
- appendToJson(result, "type", "code");
- } else if (object->type == MessageEntity::Type::Pre) {
- appendToJson(result, "type", "pre");
- } else if (object->type == MessageEntity::Type::TextLink) {
- appendToJson(result, "type", "text_link");
- } else if (object->type == MessageEntity::Type::TextMention) {
- appendToJson(result, "type", "text_mention");
- } else if (object->type == MessageEntity::Type::CustomEmoji) {
- appendToJson(result, "type", "custom_emoji");
- }
- appendToJson(result, "offset", object->offset);
- appendToJson(result, "length", object->length);
- appendToJson(result, "url", object->url);
- appendToJson(result, "user", parseUser(object->user));
- appendToJson(result, "language", object->language);
- appendToJson(result, "custom_emoji_id", object->customEmojiId);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<Message>());
result->messageId = data.get<std::int32_t>("message_id", 0);
@@ -374,6 +360,105 @@ std::string TgTypeParser::parseMessageId(const MessageId::Ptr& object) const {
return result;
}
+MessageEntity::Ptr TgTypeParser::parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<MessageEntity>());
+ std::string type = data.get<std::string>("type", "");
+ if (type == "mention") {
+ result->type = MessageEntity::Type::Mention;
+ } else if (type == "hashtag") {
+ result->type = MessageEntity::Type::Hashtag;
+ } else if (type == "cashtag") {
+ result->type = MessageEntity::Type::Cashtag;
+ } else if (type == "bot_command") {
+ result->type = MessageEntity::Type::BotCommand;
+ } else if (type == "url") {
+ result->type = MessageEntity::Type::Url;
+ } else if (type == "email") {
+ result->type = MessageEntity::Type::Email;
+ } else if (type == "phone_number") {
+ result->type = MessageEntity::Type::PhoneNumber;
+ } else if (type == "bold") {
+ result->type = MessageEntity::Type::Bold;
+ } else if (type == "italic") {
+ result->type = MessageEntity::Type::Italic;
+ } else if (type == "underline") {
+ result->type = MessageEntity::Type::Underline;
+ } else if (type == "strikethrough") {
+ result->type = MessageEntity::Type::Strikethrough;
+ } else if (type == "spoiler") {
+ result->type = MessageEntity::Type::Spoiler;
+ } else if (type == "code") {
+ result->type = MessageEntity::Type::Code;
+ } else if (type == "pre") {
+ result->type = MessageEntity::Type::Pre;
+ } else if (type == "text_link") {
+ result->type = MessageEntity::Type::TextLink;
+ } else if (type == "text_mention") {
+ result->type = MessageEntity::Type::TextMention;
+ } else if (type == "custom_emoji") {
+ result->type = MessageEntity::Type::CustomEmoji;
+ }
+ result->offset = data.get<std::int32_t>("offset", 0);
+ result->length = data.get<std::int32_t>("length", 0);
+ result->url = data.get<std::string>("url", "");
+ result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user");
+ result->language = data.get<std::string>("language", "");
+ result->customEmojiId = data.get<std::string>("custom_emoji_id", "");
+ return result;
+}
+
+std::string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ if (object->type == MessageEntity::Type::Mention) {
+ appendToJson(result, "type", "mention");
+ } else if (object->type == MessageEntity::Type::Hashtag) {
+ appendToJson(result, "type", "hashtag");
+ } else if (object->type == MessageEntity::Type::Cashtag) {
+ appendToJson(result, "type", "cashtag");
+ } else if (object->type == MessageEntity::Type::BotCommand) {
+ appendToJson(result, "type", "bot_command");
+ } else if (object->type == MessageEntity::Type::Url) {
+ appendToJson(result, "type", "url");
+ } else if (object->type == MessageEntity::Type::Email) {
+ appendToJson(result, "type", "email");
+ } else if (object->type == MessageEntity::Type::PhoneNumber) {
+ appendToJson(result, "type", "phone_number");
+ } else if (object->type == MessageEntity::Type::Bold) {
+ appendToJson(result, "type", "bold");
+ } else if (object->type == MessageEntity::Type::Italic) {
+ appendToJson(result, "type", "italic");
+ } else if (object->type == MessageEntity::Type::Underline) {
+ appendToJson(result, "type", "underline");
+ } else if (object->type == MessageEntity::Type::Strikethrough) {
+ appendToJson(result, "type", "strikethrough");
+ } else if (object->type == MessageEntity::Type::Spoiler) {
+ appendToJson(result, "type", "spoiler");
+ } else if (object->type == MessageEntity::Type::Code) {
+ appendToJson(result, "type", "code");
+ } else if (object->type == MessageEntity::Type::Pre) {
+ appendToJson(result, "type", "pre");
+ } else if (object->type == MessageEntity::Type::TextLink) {
+ appendToJson(result, "type", "text_link");
+ } else if (object->type == MessageEntity::Type::TextMention) {
+ appendToJson(result, "type", "text_mention");
+ } else if (object->type == MessageEntity::Type::CustomEmoji) {
+ appendToJson(result, "type", "custom_emoji");
+ }
+ appendToJson(result, "offset", object->offset);
+ appendToJson(result, "length", object->length);
+ appendToJson(result, "url", object->url);
+ appendToJson(result, "user", parseUser(object->user));
+ appendToJson(result, "language", object->language);
+ appendToJson(result, "custom_emoji_id", object->customEmojiId);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
PhotoSize::Ptr TgTypeParser::parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<PhotoSize>());
result->fileId = data.get<std::string>("file_id", "");
@@ -400,21 +485,21 @@ std::string TgTypeParser::parsePhotoSize(const PhotoSize::Ptr& object) const {
return result;
}
-Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Audio>());
+Animation::Ptr TgTypeParser::parseJsonAndGetAnimation(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Animation>());
result->fileId = data.get<std::string>("file_id", "");
result->fileUniqueId = data.get<std::string>("file_unique_id", "");
+ result->width = data.get<std::int32_t>("width", 0);
+ result->height = data.get<std::int32_t>("height", 0);
result->duration = data.get<std::int32_t>("duration", 0);
- result->performer = data.get<std::string>("performer", "");
- result->title = data.get<std::string>("title", "");
+ result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
result->fileName = data.get<std::string>("file_name", "");
result->mimeType = data.get<std::string>("mime_type", "");
result->fileSize = data.get<std::int64_t>("file_size", 0);
- result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
return result;
}
-std::string TgTypeParser::parseAudio(const Audio::Ptr& object) const {
+std::string TgTypeParser::parseAnimation(const Animation::Ptr& object) const {
if (!object) {
return "";
}
@@ -422,30 +507,33 @@ std::string TgTypeParser::parseAudio(const Audio::Ptr& object) const {
result += '{';
appendToJson(result, "file_id", object->fileId);
appendToJson(result, "file_unique_id", object->fileUniqueId);
+ appendToJson(result, "width", object->width);
+ appendToJson(result, "height", object->height);
appendToJson(result, "duration", object->duration);
- appendToJson(result, "performer", object->performer);
- appendToJson(result, "title", object->title);
+ appendToJson(result, "thumb", parsePhotoSize(object->thumb));
appendToJson(result, "file_name", object->fileName);
appendToJson(result, "mime_type", object->mimeType);
appendToJson(result, "file_size", object->fileSize);
- appendToJson(result, "thumb", parsePhotoSize(object->thumb));
removeLastComma(result);
result += '}';
return result;
}
-Document::Ptr TgTypeParser::parseJsonAndGetDocument(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Document>());
+Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Audio>());
result->fileId = data.get<std::string>("file_id", "");
result->fileUniqueId = data.get<std::string>("file_unique_id", "");
- result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
+ result->duration = data.get<std::int32_t>("duration", 0);
+ result->performer = data.get<std::string>("performer", "");
+ result->title = data.get<std::string>("title", "");
result->fileName = data.get<std::string>("file_name", "");
result->mimeType = data.get<std::string>("mime_type", "");
result->fileSize = data.get<std::int64_t>("file_size", 0);
+ result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
return result;
}
-std::string TgTypeParser::parseDocument(const Document::Ptr& object) const {
+std::string TgTypeParser::parseAudio(const Audio::Ptr& object) const {
if (!object) {
return "";
}
@@ -453,42 +541,30 @@ std::string TgTypeParser::parseDocument(const Document::Ptr& object) const {
result += '{';
appendToJson(result, "file_id", object->fileId);
appendToJson(result, "file_unique_id", object->fileUniqueId);
- appendToJson(result, "thumb", parsePhotoSize(object->thumb));
+ appendToJson(result, "duration", object->duration);
+ appendToJson(result, "performer", object->performer);
+ appendToJson(result, "title", object->title);
appendToJson(result, "file_name", object->fileName);
appendToJson(result, "mime_type", object->mimeType);
appendToJson(result, "file_size", object->fileSize);
+ appendToJson(result, "thumb", parsePhotoSize(object->thumb));
removeLastComma(result);
result += '}';
return result;
}
-Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Sticker>());
+Document::Ptr TgTypeParser::parseJsonAndGetDocument(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Document>());
result->fileId = data.get<std::string>("file_id", "");
result->fileUniqueId = data.get<std::string>("file_unique_id", "");
- std::string type = data.get<std::string>("type", "");
- if (type == "regular") {
- result->type = Sticker::Type::Regular;
- } else if (type == "mask") {
- result->type = Sticker::Type::Mask;
- } else if (type == "custom_emoji") {
- result->type = Sticker::Type::CustomEmoji;
- }
- 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", "");
- result->premiumAnimation = tryParseJson<File>(&TgTypeParser::parseJsonAndGetFile, data, "premium_animation");
- result->maskPosition = tryParseJson<MaskPosition>(&TgTypeParser::parseJsonAndGetMaskPosition, data, "mask_position");
- result->customEmojiId = data.get<std::string>("custom_emoji_id", "");
- result->fileSize = data.get<std::int32_t>("file_size", 0);
+ result->fileName = data.get<std::string>("file_name", "");
+ result->mimeType = data.get<std::string>("mime_type", "");
+ result->fileSize = data.get<std::int64_t>("file_size", 0);
return result;
}
-std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const {
+std::string TgTypeParser::parseDocument(const Document::Ptr& object) const {
if (!object) {
return "";
}
@@ -496,256 +572,15 @@ std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const {
result += '{';
appendToJson(result, "file_id", object->fileId);
appendToJson(result, "file_unique_id", object->fileUniqueId);
- if (object->type == Sticker::Type::Regular) {
- appendToJson(result, "type", "regular");
- } else if (object->type == Sticker::Type::Mask) {
- appendToJson(result, "type", "mask");
- } else if (object->type == Sticker::Type::CustomEmoji) {
- appendToJson(result, "type", "custom_emoji");
- }
- 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);
- appendToJson(result, "premium_animation", parseFile(object->premiumAnimation));
- appendToJson(result, "mask_position", parseMaskPosition(object->maskPosition));
- appendToJson(result, "custom_emoji_id", object->customEmojiId);
+ appendToJson(result, "file_name", object->fileName);
+ appendToJson(result, "mime_type", object->mimeType);
appendToJson(result, "file_size", object->fileSize);
removeLastComma(result);
result += '}';
return result;
}
-StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<StickerSet>());
- result->name = data.get<std::string>("name", "");
- result->title = data.get<std::string>("title", "");
- std::string type = data.get<std::string>("type", "");
- if (type == "regular") {
- result->type = StickerSet::Type::Regular;
- } else if (type == "mask") {
- result->type = StickerSet::Type::Mask;
- } else if (type == "custom_emoji") {
- result->type = StickerSet::Type::CustomEmoji;
- }
- result->isAnimated = data.get<bool>("is_animated", false);
- result->isVideo = data.get<bool>("is_video", false);
- result->stickers = parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "stickers");
- result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
- return result;
-}
-
-std::string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "name", object->name);
- appendToJson(result, "title", object->title);
- if (object->type == StickerSet::Type::Regular) {
- appendToJson(result, "type", "regular");
- } else if (object->type == StickerSet::Type::Mask) {
- appendToJson(result, "type", "mask");
- } else if (object->type == StickerSet::Type::CustomEmoji) {
- appendToJson(result, "type", "custom_emoji");
- }
- appendToJson(result, "is_animated", object->isAnimated);
- appendToJson(result, "is_video", object->isVideo);
- appendToJson(result, "stickers", parseArray(&TgTypeParser::parseSticker, object->stickers));
- appendToJson(result, "thumb", parsePhotoSize(object->thumb));
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-MaskPosition::Ptr TgTypeParser::parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const {
- auto result(std::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;
-}
-
-std::string TgTypeParser::parseMaskPosition(const MaskPosition::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::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);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-Poll::Ptr TgTypeParser::parseJsonAndGetPoll(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Poll>());
- result->id = data.get<std::string>("id", "");
- result->question = data.get<std::string>("question", "");
- result->options = parseJsonAndGetArray<PollOption>(&TgTypeParser::parseJsonAndGetPollOption, data, "options");
- result->totalVoterCount = data.get<std::int32_t>("total_voter_count", 0);
- result->isClosed = data.get<bool>("is_closed", false);
- result->isAnonymous = data.get<bool>("is_anonymous", true);
- result->type = data.get<std::string>("type", "");
- result->allowsMultipleAnswers = data.get<bool>("allows_multiple_answers", false);
- result->correctOptionId = data.get<std::int32_t>("correct_option_id", 0);
- result->explanation = data.get<std::string>("explanation", "");
- result->explanationEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "explanation_entities");
- result->openPeriod = data.get<std::int32_t>("open_period", 0);
- result->closeDate = data.get<std::int64_t>("close_date", 0);
- return result;
-}
-
-std::string TgTypeParser::parsePoll(const Poll::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "id", object->id);
- appendToJson(result, "question", object->question);
- appendToJson(result, "options", parseArray(&TgTypeParser::parsePollOption, object->options));
- appendToJson(result, "total_voter_count", object->totalVoterCount);
- appendToJson(result, "is_closed", object->isClosed);
- appendToJson(result, "is_anonymous", object->isAnonymous);
- appendToJson(result, "type", object->type);
- appendToJson(result, "allows_multiple_answers", object->allowsMultipleAnswers);
- appendToJson(result, "correct_option_id", object->correctOptionId);
- appendToJson(result, "explanation", object->correctOptionId);
- appendToJson(result, "explanation_entities", parseArray(&TgTypeParser::parseMessageEntity, object->explanationEntities));
- appendToJson(result, "open_period", object->openPeriod);
- appendToJson(result, "close_date", object->closeDate);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-Dice::Ptr TgTypeParser::parseJsonAndGetDice(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Dice>());
- result->emoji = data.get<std::string>("emoji", "");
- result->value = data.get<std::int32_t>("value", 0);
- return result;
-}
-
-std::string TgTypeParser::parseDice(const Dice::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "emoji", object->emoji);
- appendToJson(result, "value", object->value);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-PollAnswer::Ptr TgTypeParser::parseJsonAndGetPollAnswer(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<PollAnswer>());
- result->pollId = data.get<std::string>("poll_id", "");
- result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user");
- result->optionIds = parseJsonAndGetArray<std::int32_t>([] (const boost::property_tree::ptree& innerData)->std::int32_t {
- return innerData.get<std::int32_t>(0);
- }, data, "option_ids");
- return result;
-}
-
-std::string TgTypeParser::parsePollAnswer(const PollAnswer::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "poll_id", object->pollId);
- appendToJson(result, "user", parseUser(object->user));
- appendToJson(result, "option_ids", parseArray<std::int32_t>([] (std::int32_t i)->std::int32_t {
- return i;
- }, object->optionIds));
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-PollOption::Ptr TgTypeParser::parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<PollOption>());
- result->text = data.get("text", "");
- result->voterCount = data.get("voter_count", 0);
- return result;
-}
-
-std::string TgTypeParser::parsePollOption(const PollOption::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "text", object->text);
- appendToJson(result, "voter_count", object->voterCount);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-ChatPermissions::Ptr TgTypeParser::parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<ChatPermissions>());
- result->canSendMessages = data.get<bool>("can_send_messages");
- result->canSendMediaMessages = data.get<bool>("can_send_media_messages");
- result->canSendPolls = data.get<bool>("can_send_polls");
- result->canSendOtherMessages = data.get<bool>("can_send_other_messages");
- result->canAddWebPagePreviews = data.get<bool>("can_add_web_page_previews");
- result->canChangeInfo = data.get<bool>("can_change_info");
- result->canInviteUsers = data.get<bool>("can_invite_users");
- result->canPinMessages = data.get<bool>("can_pin_messages");
- return result;
-}
-
-std::string TgTypeParser::parseChatPermissions(const ChatPermissions::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "can_send_messages", object->canSendMessages);
- appendToJson(result, "can_send_media_messages", object->canSendMediaMessages);
- appendToJson(result, "can_send_polls", object->canSendPolls);
- appendToJson(result, "can_send_other_messages", object->canSendOtherMessages);
- appendToJson(result, "can_add_web_page_previews", object->canAddWebPagePreviews);
- appendToJson(result, "can_change_info", object->canChangeInfo);
- appendToJson(result, "can_invite_users", object->canInviteUsers);
- appendToJson(result, "can_pin_messages", object->canPinMessages);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-ChatLocation::Ptr TgTypeParser::parseJsonAndGetChatLocation(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<ChatLocation>());
- result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
- result->address = data.get<std::string>("address", "");
- return result;
-}
-
-std::string TgTypeParser::parseChatLocation(const ChatLocation::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "location", parseLocation(object->location));
- appendToJson(result, "address", object->address);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
Video::Ptr TgTypeParser::parseJsonAndGetVideo(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<Video>());
result->fileId = data.get<std::string>("file_id", "");
@@ -780,17 +615,18 @@ std::string TgTypeParser::parseVideo(const Video::Ptr& object) const {
return result;
}
-Voice::Ptr TgTypeParser::parseJsonAndGetVoice(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Voice>());
+VideoNote::Ptr TgTypeParser::parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<VideoNote>());
result->fileId = data.get<std::string>("file_id", "");
result->fileUniqueId = data.get<std::string>("file_unique_id", "");
+ result->length = data.get<std::int32_t>("length", 0);
result->duration = data.get<std::int32_t>("duration", 0);
- result->mimeType = data.get<std::string>("mime_type", "");
- result->fileSize = data.get<std::int64_t>("file_size", 0);
+ result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
+ result->fileSize = data.get("file_size", 0);
return result;
}
-std::string TgTypeParser::parseVoice(const Voice::Ptr& object) const {
+std::string TgTypeParser::parseVideoNote(const VideoNote::Ptr& object) const {
if (!object) {
return "";
}
@@ -798,26 +634,26 @@ std::string TgTypeParser::parseVoice(const Voice::Ptr& object) const {
result += '{';
appendToJson(result, "file_id", object->fileId);
appendToJson(result, "file_unique_id", object->fileUniqueId);
+ appendToJson(result, "length", object->length);
appendToJson(result, "duration", object->duration);
- appendToJson(result, "mime_type", object->mimeType);
+ appendToJson(result, "thumb", parsePhotoSize(object->thumb));
appendToJson(result, "file_size", object->fileSize);
removeLastComma(result);
result += '}';
return result;
}
-VideoNote::Ptr TgTypeParser::parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<VideoNote>());
+Voice::Ptr TgTypeParser::parseJsonAndGetVoice(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Voice>());
result->fileId = data.get<std::string>("file_id", "");
result->fileUniqueId = data.get<std::string>("file_unique_id", "");
- result->length = data.get<std::int32_t>("length", 0);
result->duration = data.get<std::int32_t>("duration", 0);
- result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
- result->fileSize = data.get("file_size", 0);
+ result->mimeType = data.get<std::string>("mime_type", "");
+ result->fileSize = data.get<std::int64_t>("file_size", 0);
return result;
}
-std::string TgTypeParser::parseVideoNote(const VideoNote::Ptr& object) const {
+std::string TgTypeParser::parseVoice(const Voice::Ptr& object) const {
if (!object) {
return "";
}
@@ -825,135 +661,144 @@ std::string TgTypeParser::parseVideoNote(const VideoNote::Ptr& object) const {
result += '{';
appendToJson(result, "file_id", object->fileId);
appendToJson(result, "file_unique_id", object->fileUniqueId);
- appendToJson(result, "length", object->length);
appendToJson(result, "duration", object->duration);
- appendToJson(result, "thumb", parsePhotoSize(object->thumb));
+ appendToJson(result, "mime_type", object->mimeType);
appendToJson(result, "file_size", object->fileSize);
removeLastComma(result);
result += '}';
return result;
}
-Game::Ptr TgTypeParser::parseJsonAndGetGame(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Game>());
- result->title = data.get("title", "");
- result->description = data.get("description", "");
- result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo");
- result->text = data.get("text", "");
- result->textEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "text_entities");
- result->animation = tryParseJson<Animation>(&TgTypeParser::parseJsonAndGetAnimation, data, "animation");
+Contact::Ptr TgTypeParser::parseJsonAndGetContact(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Contact>());
+ result->phoneNumber = data.get<std::string>("phone_number");
+ result->firstName = data.get<std::string>("first_name");
+ result->lastName = data.get("last_name", "");
+ result->userId = data.get("user_id", 0);
+ result->vcard = data.get("vcard", "");
return result;
}
-std::string TgTypeParser::parseGame(const Game::Ptr& object) const {
+std::string TgTypeParser::parseContact(const Contact::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "title", object->title);
- appendToJson(result, "description", object->description);
- appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo));
- appendToJson(result, "text", object->text);
- appendToJson(result, "text_entities", parseArray(&TgTypeParser::parseMessageEntity, object->textEntities));
- appendToJson(result, "animation", parseAnimation(object->animation));
+ appendToJson(result, "phone_number", object->phoneNumber);
+ appendToJson(result, "first_name", object->firstName);
+ appendToJson(result, "last_name", object->lastName);
+ appendToJson(result, "user_id", object->userId);
+ appendToJson(result, "vcard", object->vcard);
removeLastComma(result);
result += '}';
return result;
}
-CallbackGame::Ptr TgTypeParser::parseJsonAndGetCallbackGame(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<CallbackGame>());
+Dice::Ptr TgTypeParser::parseJsonAndGetDice(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Dice>());
+ result->emoji = data.get<std::string>("emoji", "");
+ result->value = data.get<std::int32_t>("value", 0);
return result;
}
-std::string TgTypeParser::parseCallbackGame(const CallbackGame::Ptr& object) const {
+std::string TgTypeParser::parseDice(const Dice::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
+ appendToJson(result, "emoji", object->emoji);
+ appendToJson(result, "value", object->value);
+ removeLastComma(result);
result += '}';
return result;
}
-GameHighScore::Ptr TgTypeParser::parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<GameHighScore>());
- result->position = data.get("position", "");
- result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user");
- result->score = data.get<std::int32_t>("score", 0);
+PollOption::Ptr TgTypeParser::parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<PollOption>());
+ result->text = data.get("text", "");
+ result->voterCount = data.get("voter_count", 0);
return result;
}
-std::string TgTypeParser::parseGameHighScore(const GameHighScore::Ptr& object) const {
+std::string TgTypeParser::parsePollOption(const PollOption::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "position", object->position);
- appendToJson(result, "user", parseUser(object->user));
- appendToJson(result, "score", object->score);
+ appendToJson(result, "text", object->text);
+ appendToJson(result, "voter_count", object->voterCount);
removeLastComma(result);
result += '}';
return result;
}
-Animation::Ptr TgTypeParser::parseJsonAndGetAnimation(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Animation>());
- result->fileId = data.get<std::string>("file_id", "");
- result->fileUniqueId = data.get<std::string>("file_unique_id", "");
- result->width = data.get<std::int32_t>("width", 0);
- result->height = data.get<std::int32_t>("height", 0);
- result->duration = data.get<std::int32_t>("duration", 0);
- result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
- result->fileName = data.get<std::string>("file_name", "");
- result->mimeType = data.get<std::string>("mime_type", "");
- result->fileSize = data.get<std::int64_t>("file_size", 0);
+PollAnswer::Ptr TgTypeParser::parseJsonAndGetPollAnswer(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<PollAnswer>());
+ result->pollId = data.get<std::string>("poll_id", "");
+ result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user");
+ result->optionIds = parseJsonAndGetArray<std::int32_t>(
+ [] (const boost::property_tree::ptree& innerData)->std::int32_t {
+ return innerData.get<std::int32_t>("");
+ }, data, "option_ids");
return result;
}
-std::string TgTypeParser::parseAnimation(const Animation::Ptr& object) const {
+std::string TgTypeParser::parsePollAnswer(const PollAnswer::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "file_id", object->fileId);
- appendToJson(result, "file_unique_id", object->fileUniqueId);
- appendToJson(result, "width", object->width);
- appendToJson(result, "height", object->height);
- appendToJson(result, "duration", object->duration);
- appendToJson(result, "thumb", parsePhotoSize(object->thumb));
- appendToJson(result, "file_name", object->fileName);
- appendToJson(result, "mime_type", object->mimeType);
- appendToJson(result, "file_size", object->fileSize);
+ appendToJson(result, "poll_id", object->pollId);
+ appendToJson(result, "user", parseUser(object->user));
+ appendToJson(result, "option_ids", parseArray<std::int32_t>([] (std::int32_t i)->std::int32_t {
+ return i;
+ }, object->optionIds));
removeLastComma(result);
result += '}';
return result;
}
-Contact::Ptr TgTypeParser::parseJsonAndGetContact(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Contact>());
- result->phoneNumber = data.get<std::string>("phone_number");
- result->firstName = data.get<std::string>("first_name");
- result->lastName = data.get("last_name", "");
- result->userId = data.get("user_id", 0);
- result->vcard = data.get("vcard", "");
+Poll::Ptr TgTypeParser::parseJsonAndGetPoll(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Poll>());
+ result->id = data.get<std::string>("id", "");
+ result->question = data.get<std::string>("question", "");
+ result->options = parseJsonAndGetArray<PollOption>(&TgTypeParser::parseJsonAndGetPollOption, data, "options");
+ result->totalVoterCount = data.get<std::int32_t>("total_voter_count", 0);
+ result->isClosed = data.get<bool>("is_closed", false);
+ result->isAnonymous = data.get<bool>("is_anonymous", true);
+ result->type = data.get<std::string>("type", "");
+ result->allowsMultipleAnswers = data.get<bool>("allows_multiple_answers", false);
+ result->correctOptionId = data.get<std::int32_t>("correct_option_id", 0);
+ result->explanation = data.get<std::string>("explanation", "");
+ result->explanationEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "explanation_entities");
+ result->openPeriod = data.get<std::int32_t>("open_period", 0);
+ result->closeDate = data.get<std::int64_t>("close_date", 0);
return result;
}
-std::string TgTypeParser::parseContact(const Contact::Ptr& object) const {
+std::string TgTypeParser::parsePoll(const Poll::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "phone_number", object->phoneNumber);
- appendToJson(result, "first_name", object->firstName);
- appendToJson(result, "last_name", object->lastName);
- appendToJson(result, "user_id", object->userId);
- appendToJson(result, "vcard", object->vcard);
+ appendToJson(result, "id", object->id);
+ appendToJson(result, "question", object->question);
+ appendToJson(result, "options", parseArray(&TgTypeParser::parsePollOption, object->options));
+ appendToJson(result, "total_voter_count", object->totalVoterCount);
+ appendToJson(result, "is_closed", object->isClosed);
+ appendToJson(result, "is_anonymous", object->isAnonymous);
+ appendToJson(result, "type", object->type);
+ appendToJson(result, "allows_multiple_answers", object->allowsMultipleAnswers);
+ appendToJson(result, "correct_option_id", object->correctOptionId);
+ appendToJson(result, "explanation", object->correctOptionId);
+ appendToJson(result, "explanation_entities", parseArray(&TgTypeParser::parseMessageEntity, object->explanationEntities));
+ appendToJson(result, "open_period", object->openPeriod);
+ appendToJson(result, "close_date", object->closeDate);
removeLastComma(result);
result += '}';
return result;
@@ -1146,52 +991,6 @@ std::string TgTypeParser::parseVideoChatParticipantsInvited(const VideoChatParti
return result;
}
-Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Update>());
- result->updateId = data.get<std::int32_t>("update_id", 0);
- result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message");
- result->editedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message");
- result->channelPost = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "channel_post");
- result->editedChannelPost = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_channel_post");
- result->inlineQuery = tryParseJson<InlineQuery>(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query");
- result->chosenInlineResult = tryParseJson<ChosenInlineResult>(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result");
- result->callbackQuery = tryParseJson<CallbackQuery>(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query");
- result->shippingQuery = tryParseJson<ShippingQuery>(&TgTypeParser::parseJsonAndGetShippingQuery, data, "shipping_query");
- result->preCheckoutQuery = tryParseJson<PreCheckoutQuery>(&TgTypeParser::parseJsonAndGetPreCheckoutQuery, data, "pre_checkout_query");
- result->poll = tryParseJson<Poll>(&TgTypeParser::parseJsonAndGetPoll, data, "poll");
- result->pollAnswer = tryParseJson<PollAnswer>(&TgTypeParser::parseJsonAndGetPollAnswer, data, "poll_answer");
- result->myChatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "my_chat_member");
- result->chatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "chat_member");
- result->chatJoinRequest = tryParseJson<ChatJoinRequest>(&TgTypeParser::parseJsonAndGetChatJoinRequest, data, "chat_join_request");
- return result;
-}
-
-std::string TgTypeParser::parseUpdate(const Update::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "update_id", object->updateId);
- appendToJson(result, "message", parseMessage(object->message));
- appendToJson(result, "edited_message", parseMessage(object->editedMessage));
- appendToJson(result, "channel_post", parseMessage(object->channelPost));
- appendToJson(result, "edited_channel_post", parseMessage(object->editedChannelPost));
- appendToJson(result, "inline_query", parseInlineQuery(object->inlineQuery));
- appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult));
- appendToJson(result, "callback_query", parseCallbackQuery(object->callbackQuery));
- appendToJson(result, "shipping_query", parseShippingQuery(object->shippingQuery));
- appendToJson(result, "pre_checkout_query", parsePreCheckoutQuery(object->preCheckoutQuery));
- appendToJson(result, "poll", parsePoll(object->poll));
- appendToJson(result, "poll_answer", parsePollAnswer(object->pollAnswer));
- appendToJson(result, "my_chat_member", parseChatMemberUpdated(object->myChatMember));
- appendToJson(result, "chat_member", parseChatMemberUpdated(object->chatMember));
- appendToJson(result, "chat_join_request", parseChatJoinRequest(object->chatJoinRequest));
- removeLastComma(result);
- result += '}';
- return result;
-}
-
UserProfilePhotos::Ptr TgTypeParser::parseJsonAndGetUserProfilePhotos(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<UserProfilePhotos>());
result->totalCount = data.get<std::int32_t>("total_count");
@@ -1212,177 +1011,6 @@ std::string TgTypeParser::parseUserProfilePhotos(const UserProfilePhotos::Ptr& o
return result;
}
-InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const boost::property_tree::ptree& data) const {
- std::string type = data.get<std::string>("type", "");
- InputMedia::Ptr result;
-
- if (type == InputMediaPhoto::TYPE) {
- result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaPhoto(data));
- } else if (type == InputMediaVideo::TYPE) {
- result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaVideo(data));
- } else if (type == InputMediaAnimation::TYPE) {
- result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaAnimation(data));
- } else if (type == InputMediaAudio::TYPE) {
- result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaAudio(data));
- } else if (type == InputMediaDocument::TYPE) {
- result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaDocument(data));
- } else {
- result = std::make_shared<InputMedia>();
- }
-
- result->type = data.get<std::string>("type", "");
- result->media = data.get<std::string>("media", "");
- result->caption = data.get<std::string>("caption", "");
- result->parseMode = data.get<std::string>("parse_mode", "");
- result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
-
- return result;
-}
-
-std::string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "type", object->type);
- appendToJson(result, "media", object->media);
- appendToJson(result, "caption", object->caption);
- appendToJson(result, "parse_mode", object->parseMode);
- appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
-
- if (object->type == InputMediaPhoto::TYPE) {
- result += parseInputMediaPhoto(std::static_pointer_cast<InputMediaPhoto>(object));
- } else if (object->type == InputMediaVideo::TYPE) {
- result += parseInputMediaVideo(std::static_pointer_cast<InputMediaVideo>(object));
- } else if (object->type == InputMediaAnimation::TYPE) {
- result += parseInputMediaAnimation(std::static_pointer_cast<InputMediaAnimation>(object));
- } else if (object->type == InputMediaAudio::TYPE) {
- result += parseInputMediaAudio(std::static_pointer_cast<InputMediaAudio>(object));
- } else if (object->type == InputMediaDocument::TYPE) {
- result += parseInputMediaDocument(std::static_pointer_cast<InputMediaDocument>(object));
- }
-
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-InputMediaPhoto::Ptr TgTypeParser::parseJsonAndGetInputMediaPhoto(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetInputMedia().
- auto result(std::make_shared<InputMediaPhoto>());
- return result;
-}
-
-std::string TgTypeParser::parseInputMediaPhoto(const InputMediaPhoto::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseInputMedia(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- // The last comma will be erased by parseInputMedia().
- return result;
-}
-
-InputMediaVideo::Ptr TgTypeParser::parseJsonAndGetInputMediaVideo(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetInputMedia().
- auto result(std::make_shared<InputMediaVideo>());
- result->thumb = data.get<std::string>("thumb", "");
- result->width = data.get<std::int32_t>("width", 0);
- result->height = data.get<std::int32_t>("height", 0);
- result->duration = data.get<std::int32_t>("duration", 0);
- result->supportsStreaming = data.get<bool>("supports_streaming", false);
- return result;
-}
-
-std::string TgTypeParser::parseInputMediaVideo(const InputMediaVideo::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseInputMedia(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- appendToJson(result, "thumb", object->thumb);
- appendToJson(result, "width", object->width);
- appendToJson(result, "height", object->height);
- appendToJson(result, "duration", object->duration);
- appendToJson(result, "supports_streaming", object->supportsStreaming);
- // The last comma will be erased by parseInputMedia().
- return result;
-}
-
-InputMediaAnimation::Ptr TgTypeParser::parseJsonAndGetInputMediaAnimation(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetInputMedia().
- auto result(std::make_shared<InputMediaAnimation>());
- result->thumb = data.get<std::string>("thumb", "");
- result->width = data.get<std::int32_t>("width", 0);
- result->height = data.get<std::int32_t>("height", 0);
- result->duration = data.get<std::int32_t>("duration", 0);
- return result;
-}
-
-std::string TgTypeParser::parseInputMediaAnimation(const InputMediaAnimation::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseInputMedia(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- appendToJson(result, "thumb", object->thumb);
- appendToJson(result, "width", object->width);
- appendToJson(result, "height", object->height);
- appendToJson(result, "duration", object->duration);
- // The last comma will be erased by parseInputMedia().
- return result;
-}
-
-InputMediaAudio::Ptr TgTypeParser::parseJsonAndGetInputMediaAudio(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetInputMedia().
- auto result(std::make_shared<InputMediaAudio>());
- result->thumb = data.get<std::string>("thumb", "");
- result->duration = data.get<std::int32_t>("duration", 0);
- result->performer = data.get<std::string>("performer", "");
- result->title = data.get<std::string>("title", "");
- return result;
-}
-
-std::string TgTypeParser::parseInputMediaAudio(const InputMediaAudio::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseInputMedia(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- appendToJson(result, "thumb", object->thumb);
- appendToJson(result, "duration", object->duration);
- appendToJson(result, "performer", object->performer);
- appendToJson(result, "title", object->title);
- // The last comma will be erased by parseInputMedia().
- return result;
-}
-
-InputMediaDocument::Ptr TgTypeParser::parseJsonAndGetInputMediaDocument(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetInputMedia().
- auto result(std::make_shared<InputMediaDocument>());
- result->thumb = data.get<std::string>("thumb", "");
- result->disableContentTypeDetection = data.get<bool>("disable_content_type_detection", false);
- return result;
-}
-
-std::string TgTypeParser::parseInputMediaDocument(const InputMediaDocument::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseInputMedia(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- appendToJson(result, "thumb", object->thumb);
- appendToJson(result, "disable_content_type_detection", object->disableContentTypeDetection);
- // The last comma will be erased by parseInputMedia().
- return result;
-}
-
File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<File>());
result->fileId = data.get<std::string>("file_id", "");
@@ -1427,7 +1055,7 @@ std::string TgTypeParser::parseWebAppInfo(const WebAppInfo::Ptr& object) const {
ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<ReplyKeyboardMarkup>());
- for (const auto& item : data.find("keyboard")->second){
+ for (const auto& item : data.find("keyboard")->second) {
result->keyboard.push_back(parseJsonAndGetArray<KeyboardButton>(&TgTypeParser::parseJsonAndGetKeyboardButton, item.second));
}
result->resizeKeyboard = data.get<bool>("resize_keyboard", false);
@@ -1528,6 +1156,121 @@ std::string TgTypeParser::parseReplyKeyboardRemove(const ReplyKeyboardRemove::Pt
return result;
}
+InlineKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<InlineKeyboardMarkup>());
+ for (const auto& item : data.find("inline_keyboard")->second) {
+ result->inlineKeyboard.push_back(parseJsonAndGetArray<InlineKeyboardButton>(&TgTypeParser::parseJsonAndGetInlineKeyboardButton, item.second));
+ }
+ return result;
+}
+
+std::string TgTypeParser::parseInlineKeyboardMarkup(const InlineKeyboardMarkup::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ result += R"("inline_keyboard":[)";
+ for (const auto& item : object->inlineKeyboard) {
+ result += '[';
+ for (const auto& innerItem : item) {
+ result += parseInlineKeyboardButton(innerItem);
+ result += ',';
+ }
+ removeLastComma(result);
+ result += "],";
+ }
+ if (!object->inlineKeyboard.empty())
+ removeLastComma(result);
+ result += "]}";
+ return result;
+}
+
+InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<InlineKeyboardButton>());
+ result->text = data.get<std::string>("text", "");
+ result->url = data.get<std::string>("url", "");
+ result->callbackData = data.get<std::string>("callback_data", "");
+ result->webApp = tryParseJson<WebAppInfo>(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app");
+ result->loginUrl = tryParseJson<LoginUrl>(&TgTypeParser::parseJsonAndGetLoginUrl, data, "login_url");
+ result->switchInlineQuery = data.get<std::string>("switch_inline_query", "");
+ result->switchInlineQueryCurrentChat = data.get<std::string>("switch_inline_query_current_chat", "");
+ result->callbackGame = tryParseJson<CallbackGame>(&TgTypeParser::parseJsonAndGetCallbackGame, data, "callback_game");
+ result->pay = data.get<bool>("pay", false);
+ return result;
+}
+std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "pay", object->pay);
+ appendToJson(result, "text", object->text);
+ appendToJson(result, "url", object->url);
+ appendToJson(result, "callback_data", object->callbackData);
+ appendToJson(result, "switch_inline_query", object->switchInlineQuery);
+ appendToJson(result, "switch_inline_query_current_chat", object->switchInlineQueryCurrentChat);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+LoginUrl::Ptr TgTypeParser::parseJsonAndGetLoginUrl(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<LoginUrl>());
+ result->url = data.get<std::string>("url", "");
+ result->forwardText = data.get<std::string>("forward_text", "");
+ result->botUsername = data.get<std::string>("bot_username", "");
+ result->requestWriteAccess = data.get<bool>("request_write_access", false);
+ return result;
+}
+
+std::string TgTypeParser::parseLoginUrl(const LoginUrl::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "url", object->url);
+ appendToJson(result, "forward_text", object->forwardText);
+ appendToJson(result, "bot_username", object->botUsername);
+ appendToJson(result, "request_write_access", object->requestWriteAccess);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<CallbackQuery>());
+ result->id = data.get<std::string>("id");
+ result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
+ result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message");
+ result->inlineMessageId = data.get<std::string>("inline_message_id", "");
+ result->chatInstance = data.get<std::string>("chat_instance");
+ result->gameShortName = data.get<std::string>("game_short_name", "");
+ result->data = data.get<std::string>("data", "");
+ return result;
+}
+
+std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+
+ std::string result;
+ result += '{';
+ appendToJson(result, "id", object->id);
+ appendToJson(result, "from", parseUser(object->from));
+ appendToJson(result, "message", parseMessage(object->message));
+ appendToJson(result, "inline_message_id", object->inlineMessageId);
+ appendToJson(result, "chat_instance", object->chatInstance);
+ appendToJson(result, "game_short_name", object->gameShortName);
+ appendToJson(result, "data", object->data);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
ForceReply::Ptr TgTypeParser::parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<ForceReply>());
result->inputFieldPlaceholder = data.get<std::string>("input_field_placeholder", "");
@@ -1549,6 +1292,102 @@ std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const {
return result;
}
+ChatPhoto::Ptr TgTypeParser::parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ChatPhoto>());
+ result->smallFileId = data.get<std::string>("small_file_id", "");
+ result->smallFileUniqueId = data.get<std::string>("small_file_unique_id", "");
+ result->bigFileId = data.get<std::string>("big_file_id", "");
+ result->bigFileUniqueId = data.get<std::string>("big_file_unique_id", "");
+ return result;
+}
+
+std::string TgTypeParser::parseChatPhoto(const ChatPhoto::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "small_file_id", object->smallFileId);
+ appendToJson(result, "small_file_unique_id", object->smallFileUniqueId);
+ appendToJson(result, "big_file_id", object->bigFileId);
+ appendToJson(result, "big_file_unique_id", object->bigFileUniqueId);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+ChatInviteLink::Ptr TgTypeParser::parseJsonAndGetChatInviteLink(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ChatInviteLink>());
+ result->inviteLink = data.get<std::string>("invite_link", "");
+ result->creator = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "creator");
+ result->createsJoinRequest = data.get<bool>("creates_join_request", false);
+ result->isPrimary = data.get<bool>("is_primary", false);
+ result->isRevoked = data.get<bool>("is_revoked", false);
+ result->name = data.get<std::string>("name", "");
+ result->expireDate = data.get<std::uint32_t>("expire_date", 0);
+ result->memberLimit = data.get<std::uint32_t>("member_limit", 0);
+ result->pendingJoinRequestCount = data.get<std::uint32_t>("pending_join_request_count", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseChatInviteLink(const ChatInviteLink::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "invite_link", object->inviteLink);
+ appendToJson(result, "creator", parseUser(object->creator));
+ appendToJson(result, "creates_join_request", object->createsJoinRequest);
+ appendToJson(result, "is_primary", object->isPrimary);
+ appendToJson(result, "is_revoked", object->isRevoked);
+ appendToJson(result, "name", object->name);
+ appendToJson(result, "expire_date", object->expireDate);
+ appendToJson(result, "member_limit", object->memberLimit);
+ appendToJson(result, "pending_join_request_count", object->pendingJoinRequestCount);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+ChatAdministratorRights::Ptr TgTypeParser::parseJsonAndGetChatAdministratorRights(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ChatAdministratorRights>());
+ result->isAnonymous = data.get<bool>("is_anonymous", false);
+ result->canManageChat = data.get<bool>("can_manage_chat", false);
+ result->canDeleteMessages = data.get<bool>("can_delete_messages", false);
+ result->canManageVideoChats = data.get<bool>("can_manage_video_chats", false);
+ result->canRestrictMembers = data.get<bool>("can_restrict_members", false);
+ result->canPromoteMembers = data.get<bool>("can_promote_members", false);
+ result->canChangeInfo = data.get<bool>("can_change_info", false);
+ result->canInviteUsers = data.get<bool>("can_invite_users", false);
+ result->canPostMessages = data.get<bool>("can_post_messages", false);
+ result->canEditMessages = data.get<bool>("can_edit_messages", false);
+ result->canPinMessages = data.get<bool>("can_pin_messages", false);
+ return result;
+}
+
+std::string TgTypeParser::parseChatAdministratorRights(const ChatAdministratorRights::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "is_anonymous", object->isAnonymous);
+ appendToJson(result, "can_manage_chat", object->canManageChat);
+ appendToJson(result, "can_delete_messages", object->canDeleteMessages);
+ appendToJson(result, "can_manage_video_chats", object->canManageVideoChats);
+ appendToJson(result, "can_restrict_members", object->canRestrictMembers);
+ appendToJson(result, "can_promote_members", object->canPromoteMembers);
+ appendToJson(result, "can_change_info", object->canChangeInfo);
+ appendToJson(result, "can_invite_users", object->canInviteUsers);
+ appendToJson(result, "can_post_messages", object->canPostMessages);
+ appendToJson(result, "can_edit_messages", object->canEditMessages);
+ appendToJson(result, "can_pin_messages", object->canPinMessages);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const {
std::string status = data.get<std::string>("status", "");
ChatMember::Ptr result;
@@ -1811,102 +1650,353 @@ std::string TgTypeParser::parseChatJoinRequest(const ChatJoinRequest::Ptr& objec
return result;
}
-ChatPhoto::Ptr TgTypeParser::parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<ChatPhoto>());
- result->smallFileId = data.get<std::string>("small_file_id", "");
- result->smallFileUniqueId = data.get<std::string>("small_file_unique_id", "");
- result->bigFileId = data.get<std::string>("big_file_id", "");
- result->bigFileUniqueId = data.get<std::string>("big_file_unique_id", "");
+ChatPermissions::Ptr TgTypeParser::parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ChatPermissions>());
+ result->canSendMessages = data.get<bool>("can_send_messages");
+ result->canSendMediaMessages = data.get<bool>("can_send_media_messages");
+ result->canSendPolls = data.get<bool>("can_send_polls");
+ result->canSendOtherMessages = data.get<bool>("can_send_other_messages");
+ result->canAddWebPagePreviews = data.get<bool>("can_add_web_page_previews");
+ result->canChangeInfo = data.get<bool>("can_change_info");
+ result->canInviteUsers = data.get<bool>("can_invite_users");
+ result->canPinMessages = data.get<bool>("can_pin_messages");
return result;
}
-std::string TgTypeParser::parseChatPhoto(const ChatPhoto::Ptr& object) const {
+std::string TgTypeParser::parseChatPermissions(const ChatPermissions::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "small_file_id", object->smallFileId);
- appendToJson(result, "small_file_unique_id", object->smallFileUniqueId);
- appendToJson(result, "big_file_id", object->bigFileId);
- appendToJson(result, "big_file_unique_id", object->bigFileUniqueId);
+ appendToJson(result, "can_send_messages", object->canSendMessages);
+ appendToJson(result, "can_send_media_messages", object->canSendMediaMessages);
+ appendToJson(result, "can_send_polls", object->canSendPolls);
+ appendToJson(result, "can_send_other_messages", object->canSendOtherMessages);
+ appendToJson(result, "can_add_web_page_previews", object->canAddWebPagePreviews);
+ appendToJson(result, "can_change_info", object->canChangeInfo);
+ appendToJson(result, "can_invite_users", object->canInviteUsers);
+ appendToJson(result, "can_pin_messages", object->canPinMessages);
removeLastComma(result);
result += '}';
return result;
}
-ChatInviteLink::Ptr TgTypeParser::parseJsonAndGetChatInviteLink(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<ChatInviteLink>());
- result->inviteLink = data.get<std::string>("invite_link", "");
- result->creator = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "creator");
- result->createsJoinRequest = data.get<bool>("creates_join_request", false);
- result->isPrimary = data.get<bool>("is_primary", false);
- result->isRevoked = data.get<bool>("is_revoked", false);
- result->name = data.get<std::string>("name", "");
- result->expireDate = data.get<std::uint32_t>("expire_date", 0);
- result->memberLimit = data.get<std::uint32_t>("member_limit", 0);
- result->pendingJoinRequestCount = data.get<std::uint32_t>("pending_join_request_count", 0);
+ChatLocation::Ptr TgTypeParser::parseJsonAndGetChatLocation(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ChatLocation>());
+ result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
+ result->address = data.get<std::string>("address", "");
return result;
}
-std::string TgTypeParser::parseChatInviteLink(const ChatInviteLink::Ptr& object) const {
+std::string TgTypeParser::parseChatLocation(const ChatLocation::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "invite_link", object->inviteLink);
- appendToJson(result, "creator", parseUser(object->creator));
- appendToJson(result, "creates_join_request", object->createsJoinRequest);
- appendToJson(result, "is_primary", object->isPrimary);
- appendToJson(result, "is_revoked", object->isRevoked);
- appendToJson(result, "name", object->name);
- appendToJson(result, "expire_date", object->expireDate);
- appendToJson(result, "member_limit", object->memberLimit);
- appendToJson(result, "pending_join_request_count", object->pendingJoinRequestCount);
+ appendToJson(result, "location", parseLocation(object->location));
+ appendToJson(result, "address", object->address);
removeLastComma(result);
result += '}';
return result;
}
-ChatAdministratorRights::Ptr TgTypeParser::parseJsonAndGetChatAdministratorRights(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<ChatAdministratorRights>());
- result->isAnonymous = data.get<bool>("is_anonymous", false);
- result->canManageChat = data.get<bool>("can_manage_chat", false);
- result->canDeleteMessages = data.get<bool>("can_delete_messages", false);
- result->canManageVideoChats = data.get<bool>("can_manage_video_chats", false);
- result->canRestrictMembers = data.get<bool>("can_restrict_members", false);
- result->canPromoteMembers = data.get<bool>("can_promote_members", false);
- result->canChangeInfo = data.get<bool>("can_change_info", false);
- result->canInviteUsers = data.get<bool>("can_invite_users", false);
- result->canPostMessages = data.get<bool>("can_post_messages", false);
- result->canEditMessages = data.get<bool>("can_edit_messages", false);
- result->canPinMessages = data.get<bool>("can_pin_messages", false);
+BotCommand::Ptr TgTypeParser::parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<BotCommand>());
+ result->command = data.get("command", "");
+ result->description = data.get("description", "");
return result;
}
-std::string TgTypeParser::parseChatAdministratorRights(const ChatAdministratorRights::Ptr& object) const {
+std::string TgTypeParser::parseBotCommand(const BotCommand::Ptr& object) const {
+ std::string result;
+ result += '{';
+ appendToJson(result, "command", object->command);
+ appendToJson(result, "description", object->description);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+BotCommandScope::Ptr TgTypeParser::parseJsonAndGetBotCommandScope(const boost::property_tree::ptree& data) const {
+ std::string type = data.get<std::string>("type", "");
+ BotCommandScope::Ptr result;
+
+ if (type == BotCommandScopeDefault::TYPE) {
+ result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeDefault(data));
+ } else if (type == BotCommandScopeAllPrivateChats::TYPE) {
+ result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeAllPrivateChats(data));
+ } else if (type == BotCommandScopeAllGroupChats::TYPE) {
+ result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeAllGroupChats(data));
+ } else if (type == BotCommandScopeAllChatAdministrators::TYPE) {
+ result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeAllChatAdministrators(data));
+ } else if (type == BotCommandScopeChat::TYPE) {
+ result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeChat(data));
+ } else if (type == BotCommandScopeChatAdministrators::TYPE) {
+ result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeChatAdministrators(data));
+ } else if (type == BotCommandScopeChatMember::TYPE) {
+ result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeChatMember(data));
+ } else {
+ result = std::make_shared<BotCommandScope>();
+ }
+
+ result->type = type;
+
+ return result;
+}
+
+std::string TgTypeParser::parseBotCommandScope(const BotCommandScope::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "is_anonymous", object->isAnonymous);
- appendToJson(result, "can_manage_chat", object->canManageChat);
- appendToJson(result, "can_delete_messages", object->canDeleteMessages);
- appendToJson(result, "can_manage_video_chats", object->canManageVideoChats);
- appendToJson(result, "can_restrict_members", object->canRestrictMembers);
- appendToJson(result, "can_promote_members", object->canPromoteMembers);
- appendToJson(result, "can_change_info", object->canChangeInfo);
- appendToJson(result, "can_invite_users", object->canInviteUsers);
- appendToJson(result, "can_post_messages", object->canPostMessages);
- appendToJson(result, "can_edit_messages", object->canEditMessages);
- appendToJson(result, "can_pin_messages", object->canPinMessages);
+ appendToJson(result, "type", object->type);
+
+ if (object->type == BotCommandScopeDefault::TYPE) {
+ result += parseBotCommandScopeDefault(std::static_pointer_cast<BotCommandScopeDefault>(object));
+ } else if (object->type == BotCommandScopeAllPrivateChats::TYPE) {
+ result += parseBotCommandScopeAllPrivateChats(std::static_pointer_cast<BotCommandScopeAllPrivateChats>(object));
+ } else if (object->type == BotCommandScopeAllGroupChats::TYPE) {
+ result += parseBotCommandScopeAllGroupChats(std::static_pointer_cast<BotCommandScopeAllGroupChats>(object));
+ } else if (object->type == BotCommandScopeAllChatAdministrators::TYPE) {
+ result += parseBotCommandScopeAllChatAdministrators(std::static_pointer_cast<BotCommandScopeAllChatAdministrators>(object));
+ } else if (object->type == BotCommandScopeChat::TYPE) {
+ result += parseBotCommandScopeChat(std::static_pointer_cast<BotCommandScopeChat>(object));
+ } else if (object->type == BotCommandScopeChatAdministrators::TYPE) {
+ result += parseBotCommandScopeChatAdministrators(std::static_pointer_cast<BotCommandScopeChatAdministrators>(object));
+ } else if (object->type == BotCommandScopeChatMember::TYPE) {
+ result += parseBotCommandScopeChatMember(std::static_pointer_cast<BotCommandScopeChatMember>(object));
+ }
+
removeLastComma(result);
result += '}';
return result;
}
+BotCommandScopeDefault::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeDefault(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
+ auto result(std::make_shared<BotCommandScopeDefault>());
+ return result;
+}
+
+std::string TgTypeParser::parseBotCommandScopeDefault(const BotCommandScopeDefault::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseBotCommandScope(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ // The last comma will be erased by parseBotCommandScope().
+ return result;
+}
+
+BotCommandScopeAllPrivateChats::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllPrivateChats(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
+ auto result(std::make_shared<BotCommandScopeAllPrivateChats>());
+ return result;
+}
+
+std::string TgTypeParser::parseBotCommandScopeAllPrivateChats(const BotCommandScopeAllPrivateChats::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseBotCommandScope(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ // The last comma will be erased by parseBotCommandScope().
+ return result;
+}
+
+BotCommandScopeAllGroupChats::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllGroupChats(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
+ auto result(std::make_shared<BotCommandScopeAllGroupChats>());
+ return result;
+}
+
+std::string TgTypeParser::parseBotCommandScopeAllGroupChats(const BotCommandScopeAllGroupChats::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseBotCommandScope(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ // The last comma will be erased by parseBotCommandScope().
+ return result;
+}
+
+BotCommandScopeAllChatAdministrators::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllChatAdministrators(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
+ auto result(std::make_shared<BotCommandScopeAllChatAdministrators>());
+ return result;
+}
+
+std::string TgTypeParser::parseBotCommandScopeAllChatAdministrators(const BotCommandScopeAllChatAdministrators::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseBotCommandScope(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ // The last comma will be erased by parseBotCommandScope().
+ return result;
+}
+
+BotCommandScopeChat::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeChat(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
+ auto result(std::make_shared<BotCommandScopeChat>());
+ result->chatId = data.get<std::int64_t>("chat_id", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseBotCommandScopeChat(const BotCommandScopeChat::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseBotCommandScope(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ appendToJson(result, "chat_id", object->chatId);
+ // The last comma will be erased by parseBotCommandScope().
+ return result;
+}
+
+BotCommandScopeChatAdministrators::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeChatAdministrators(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
+ auto result(std::make_shared<BotCommandScopeChatAdministrators>());
+ result->chatId = data.get<std::int64_t>("chat_id", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseBotCommandScopeChatAdministrators(const BotCommandScopeChatAdministrators::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseBotCommandScope(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ appendToJson(result, "chat_id", object->chatId);
+ // The last comma will be erased by parseBotCommandScope().
+ return result;
+}
+
+BotCommandScopeChatMember::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeChatMember(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
+ auto result(std::make_shared<BotCommandScopeChatMember>());
+ result->chatId = data.get<std::int64_t>("chat_id", 0);
+ result->userId = data.get<std::int64_t>("user_id", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseBotCommandScopeChatMember(const BotCommandScopeChatMember::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseBotCommandScope(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ appendToJson(result, "chat_id", object->chatId);
+ appendToJson(result, "user_id", object->userId);
+ // The last comma will be erased by parseBotCommandScope().
+ return result;
+}
+
+MenuButton::Ptr TgTypeParser::parseJsonAndGetMenuButton(const boost::property_tree::ptree& data) const {
+ std::string type = data.get<std::string>("type", "");
+ MenuButton::Ptr result;
+
+ if (type == MenuButtonCommands::TYPE) {
+ result = std::static_pointer_cast<MenuButton>(parseJsonAndGetMenuButtonCommands(data));
+ } else if (type == MenuButtonWebApp::TYPE) {
+ result = std::static_pointer_cast<MenuButton>(parseJsonAndGetMenuButtonWebApp(data));
+ } else if (type == MenuButtonDefault::TYPE) {
+ result = std::static_pointer_cast<MenuButton>(parseJsonAndGetMenuButtonDefault(data));
+ } else {
+ result = std::make_shared<MenuButton>();
+ }
+
+ result->type = type;
+
+ return result;
+}
+
+std::string TgTypeParser::parseMenuButton(const MenuButton::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "type", object->type);
+
+ if (object->type == MenuButtonCommands::TYPE) {
+ result += parseMenuButtonCommands(std::static_pointer_cast<MenuButtonCommands>(object));
+ } else if (object->type == MenuButtonWebApp::TYPE) {
+ result += parseMenuButtonWebApp(std::static_pointer_cast<MenuButtonWebApp>(object));
+ } else if (object->type == MenuButtonDefault::TYPE) {
+ result += parseMenuButtonDefault(std::static_pointer_cast<MenuButtonDefault>(object));
+ }
+
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+MenuButtonCommands::Ptr TgTypeParser::parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetMenuButton().
+ auto result(std::make_shared<MenuButtonCommands>());
+ return result;
+}
+
+std::string TgTypeParser::parseMenuButtonCommands(const MenuButtonCommands::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseMenuButton(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ // The last comma will be erased by parseMenuButton().
+ return result;
+}
+
+MenuButtonWebApp::Ptr TgTypeParser::parseJsonAndGetMenuButtonWebApp(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetMenuButton().
+ auto result(std::make_shared<MenuButtonWebApp>());
+ result->text = data.get<std::string>("text", "");
+ result->webApp = tryParseJson<WebAppInfo>(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app");
+ return result;
+}
+
+std::string TgTypeParser::parseMenuButtonWebApp(const MenuButtonWebApp::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseMenuButton(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ appendToJson(result, "text", object->text);
+ appendToJson(result, "web_app", parseWebAppInfo(object->webApp));
+ // The last comma will be erased by parseMenuButton().
+ return result;
+}
+
+MenuButtonDefault::Ptr TgTypeParser::parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetMenuButton().
+ auto result(std::make_shared<MenuButtonDefault>());
+ return result;
+}
+
+std::string TgTypeParser::parseMenuButtonDefault(const MenuButtonDefault::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseMenuButton(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ // The last comma will be erased by parseMenuButton().
+ return result;
+}
+
ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<ResponseParameters>());
result->migrateToChatId = data.get<std::int64_t>("migrate_to_chat_id", 0);
@@ -1927,33 +2017,299 @@ std::string TgTypeParser::parseResponseParameters(const ResponseParameters::Ptr&
return result;
}
-GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const {
- if (data.find("force_reply") != data.not_found()) {
- return std::static_pointer_cast<GenericReply>(parseJsonAndGetForceReply(data));
- } else if (data.find("remove_keyboard") != data.not_found()) {
- return std::static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardRemove(data));
- } else if (data.find("keyboard") != data.not_found()) {
- return std::static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardMarkup(data));
- } else if (data.find("inline_keyboard") != data.not_found()) {
- return std::static_pointer_cast<GenericReply>(parseJsonAndGetInlineKeyboardMarkup(data));
+InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const boost::property_tree::ptree& data) const {
+ std::string type = data.get<std::string>("type", "");
+ InputMedia::Ptr result;
+
+ if (type == InputMediaPhoto::TYPE) {
+ result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaPhoto(data));
+ } else if (type == InputMediaVideo::TYPE) {
+ result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaVideo(data));
+ } else if (type == InputMediaAnimation::TYPE) {
+ result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaAnimation(data));
+ } else if (type == InputMediaAudio::TYPE) {
+ result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaAudio(data));
+ } else if (type == InputMediaDocument::TYPE) {
+ result = std::static_pointer_cast<InputMedia>(parseJsonAndGetInputMediaDocument(data));
+ } else {
+ result = std::make_shared<InputMedia>();
}
- return std::make_shared<GenericReply>();
+
+ result->type = data.get<std::string>("type", "");
+ result->media = data.get<std::string>("media", "");
+ result->caption = data.get<std::string>("caption", "");
+ result->parseMode = data.get<std::string>("parse_mode", "");
+ result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
+
+ return result;
}
-std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) const {
+std::string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const {
if (!object) {
return "";
}
- if (std::dynamic_pointer_cast<ForceReply>(object) != nullptr) {
- return parseForceReply(std::static_pointer_cast<ForceReply>(object));
- } else if (std::dynamic_pointer_cast<ReplyKeyboardRemove>(object) != nullptr) {
- return parseReplyKeyboardRemove(std::static_pointer_cast<ReplyKeyboardRemove>(object));
- } else if (std::dynamic_pointer_cast<ReplyKeyboardMarkup>(object) != nullptr){
- return parseReplyKeyboardMarkup(std::static_pointer_cast<ReplyKeyboardMarkup>(object));
- } else if (std::dynamic_pointer_cast<InlineKeyboardMarkup>(object) != nullptr){
- return parseInlineKeyboardMarkup(std::static_pointer_cast<InlineKeyboardMarkup>(object));
+ std::string result;
+ result += '{';
+ appendToJson(result, "type", object->type);
+ appendToJson(result, "media", object->media);
+ appendToJson(result, "caption", object->caption);
+ appendToJson(result, "parse_mode", object->parseMode);
+ appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
+
+ if (object->type == InputMediaPhoto::TYPE) {
+ result += parseInputMediaPhoto(std::static_pointer_cast<InputMediaPhoto>(object));
+ } else if (object->type == InputMediaVideo::TYPE) {
+ result += parseInputMediaVideo(std::static_pointer_cast<InputMediaVideo>(object));
+ } else if (object->type == InputMediaAnimation::TYPE) {
+ result += parseInputMediaAnimation(std::static_pointer_cast<InputMediaAnimation>(object));
+ } else if (object->type == InputMediaAudio::TYPE) {
+ result += parseInputMediaAudio(std::static_pointer_cast<InputMediaAudio>(object));
+ } else if (object->type == InputMediaDocument::TYPE) {
+ result += parseInputMediaDocument(std::static_pointer_cast<InputMediaDocument>(object));
}
- return "";
+
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+InputMediaPhoto::Ptr TgTypeParser::parseJsonAndGetInputMediaPhoto(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetInputMedia().
+ auto result(std::make_shared<InputMediaPhoto>());
+ return result;
+}
+
+std::string TgTypeParser::parseInputMediaPhoto(const InputMediaPhoto::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseInputMedia(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ // The last comma will be erased by parseInputMedia().
+ return result;
+}
+
+InputMediaVideo::Ptr TgTypeParser::parseJsonAndGetInputMediaVideo(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetInputMedia().
+ auto result(std::make_shared<InputMediaVideo>());
+ result->thumb = data.get<std::string>("thumb", "");
+ result->width = data.get<std::int32_t>("width", 0);
+ result->height = data.get<std::int32_t>("height", 0);
+ result->duration = data.get<std::int32_t>("duration", 0);
+ result->supportsStreaming = data.get<bool>("supports_streaming", false);
+ return result;
+}
+
+std::string TgTypeParser::parseInputMediaVideo(const InputMediaVideo::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseInputMedia(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ appendToJson(result, "thumb", object->thumb);
+ appendToJson(result, "width", object->width);
+ appendToJson(result, "height", object->height);
+ appendToJson(result, "duration", object->duration);
+ appendToJson(result, "supports_streaming", object->supportsStreaming);
+ // The last comma will be erased by parseInputMedia().
+ return result;
+}
+
+InputMediaAnimation::Ptr TgTypeParser::parseJsonAndGetInputMediaAnimation(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetInputMedia().
+ auto result(std::make_shared<InputMediaAnimation>());
+ result->thumb = data.get<std::string>("thumb", "");
+ result->width = data.get<std::int32_t>("width", 0);
+ result->height = data.get<std::int32_t>("height", 0);
+ result->duration = data.get<std::int32_t>("duration", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseInputMediaAnimation(const InputMediaAnimation::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseInputMedia(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ appendToJson(result, "thumb", object->thumb);
+ appendToJson(result, "width", object->width);
+ appendToJson(result, "height", object->height);
+ appendToJson(result, "duration", object->duration);
+ // The last comma will be erased by parseInputMedia().
+ return result;
+}
+
+InputMediaAudio::Ptr TgTypeParser::parseJsonAndGetInputMediaAudio(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetInputMedia().
+ auto result(std::make_shared<InputMediaAudio>());
+ result->thumb = data.get<std::string>("thumb", "");
+ result->duration = data.get<std::int32_t>("duration", 0);
+ result->performer = data.get<std::string>("performer", "");
+ result->title = data.get<std::string>("title", "");
+ return result;
+}
+
+std::string TgTypeParser::parseInputMediaAudio(const InputMediaAudio::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseInputMedia(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ appendToJson(result, "thumb", object->thumb);
+ appendToJson(result, "duration", object->duration);
+ appendToJson(result, "performer", object->performer);
+ appendToJson(result, "title", object->title);
+ // The last comma will be erased by parseInputMedia().
+ return result;
+}
+
+InputMediaDocument::Ptr TgTypeParser::parseJsonAndGetInputMediaDocument(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetInputMedia().
+ auto result(std::make_shared<InputMediaDocument>());
+ result->thumb = data.get<std::string>("thumb", "");
+ result->disableContentTypeDetection = data.get<bool>("disable_content_type_detection", false);
+ return result;
+}
+
+std::string TgTypeParser::parseInputMediaDocument(const InputMediaDocument::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseInputMedia(), so I don't add
+ // curly brackets to the result std::string.
+ std::string result;
+ appendToJson(result, "thumb", object->thumb);
+ appendToJson(result, "disable_content_type_detection", object->disableContentTypeDetection);
+ // The last comma will be erased by parseInputMedia().
+ return result;
+}
+
+Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Sticker>());
+ result->fileId = data.get<std::string>("file_id", "");
+ result->fileUniqueId = data.get<std::string>("file_unique_id", "");
+ std::string type = data.get<std::string>("type", "");
+ if (type == "regular") {
+ result->type = Sticker::Type::Regular;
+ } else if (type == "mask") {
+ result->type = Sticker::Type::Mask;
+ } else if (type == "custom_emoji") {
+ result->type = Sticker::Type::CustomEmoji;
+ }
+ 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", "");
+ result->premiumAnimation = tryParseJson<File>(&TgTypeParser::parseJsonAndGetFile, data, "premium_animation");
+ result->maskPosition = tryParseJson<MaskPosition>(&TgTypeParser::parseJsonAndGetMaskPosition, data, "mask_position");
+ result->customEmojiId = data.get<std::string>("custom_emoji_id", "");
+ result->fileSize = data.get<std::int32_t>("file_size", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "file_id", object->fileId);
+ appendToJson(result, "file_unique_id", object->fileUniqueId);
+ if (object->type == Sticker::Type::Regular) {
+ appendToJson(result, "type", "regular");
+ } else if (object->type == Sticker::Type::Mask) {
+ appendToJson(result, "type", "mask");
+ } else if (object->type == Sticker::Type::CustomEmoji) {
+ appendToJson(result, "type", "custom_emoji");
+ }
+ 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);
+ appendToJson(result, "premium_animation", parseFile(object->premiumAnimation));
+ appendToJson(result, "mask_position", parseMaskPosition(object->maskPosition));
+ appendToJson(result, "custom_emoji_id", object->customEmojiId);
+ appendToJson(result, "file_size", object->fileSize);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<StickerSet>());
+ result->name = data.get<std::string>("name", "");
+ result->title = data.get<std::string>("title", "");
+ std::string type = data.get<std::string>("type", "");
+ if (type == "regular") {
+ result->type = StickerSet::Type::Regular;
+ } else if (type == "mask") {
+ result->type = StickerSet::Type::Mask;
+ } else if (type == "custom_emoji") {
+ result->type = StickerSet::Type::CustomEmoji;
+ }
+ result->isAnimated = data.get<bool>("is_animated", false);
+ result->isVideo = data.get<bool>("is_video", false);
+ result->stickers = parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "stickers");
+ result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
+ return result;
+}
+
+std::string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "name", object->name);
+ appendToJson(result, "title", object->title);
+ if (object->type == StickerSet::Type::Regular) {
+ appendToJson(result, "type", "regular");
+ } else if (object->type == StickerSet::Type::Mask) {
+ appendToJson(result, "type", "mask");
+ } else if (object->type == StickerSet::Type::CustomEmoji) {
+ appendToJson(result, "type", "custom_emoji");
+ }
+ appendToJson(result, "is_animated", object->isAnimated);
+ appendToJson(result, "is_video", object->isVideo);
+ appendToJson(result, "stickers", parseArray(&TgTypeParser::parseSticker, object->stickers));
+ appendToJson(result, "thumb", parsePhotoSize(object->thumb));
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+MaskPosition::Ptr TgTypeParser::parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const {
+ auto result(std::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;
+}
+
+std::string TgTypeParser::parseMaskPosition(const MaskPosition::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::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);
+ removeLastComma(result);
+ result += '}';
+ return result;
}
InlineQuery::Ptr TgTypeParser::parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const {
@@ -1967,7 +2323,7 @@ InlineQuery::Ptr TgTypeParser::parseJsonAndGetInlineQuery(const boost::property_
return result;
}
-std::string TgTypeParser::parseInlineQuery(const InlineQuery::Ptr& object) const{
+std::string TgTypeParser::parseInlineQuery(const InlineQuery::Ptr& object) const {
if (!object) {
return "";
}
@@ -2040,7 +2396,7 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos
}
std::string TgTypeParser::parseInlineQueryResult(const InlineQueryResult::Ptr& object) const {
- if (!object){
+ if (!object) {
return "";
}
std::string result;
@@ -2051,62 +2407,43 @@ std::string TgTypeParser::parseInlineQueryResult(const InlineQueryResult::Ptr& o
if (object->type == InlineQueryResultCachedAudio::TYPE) {
result += parseInlineQueryResultCachedAudio(std::static_pointer_cast<InlineQueryResultCachedAudio>(object));
- }
- else if (object->type == InlineQueryResultCachedDocument::TYPE) {
+ } else if (object->type == InlineQueryResultCachedDocument::TYPE) {
result += parseInlineQueryResultCachedDocument(std::static_pointer_cast<InlineQueryResultCachedDocument>(object));
- }
- else if (object->type == InlineQueryResultCachedGif::TYPE) {
+ } else if (object->type == InlineQueryResultCachedGif::TYPE) {
result += parseInlineQueryResultCachedGif(std::static_pointer_cast<InlineQueryResultCachedGif>(object));
- }
- else if (object->type == InlineQueryResultCachedMpeg4Gif::TYPE) {
+ } else if (object->type == InlineQueryResultCachedMpeg4Gif::TYPE) {
result += parseInlineQueryResultCachedMpeg4Gif(std::static_pointer_cast<InlineQueryResultCachedMpeg4Gif>(object));
- }
- else if (object->type == InlineQueryResultCachedPhoto::TYPE) {
+ } else if (object->type == InlineQueryResultCachedPhoto::TYPE) {
result += parseInlineQueryResultCachedPhoto(std::static_pointer_cast<InlineQueryResultCachedPhoto>(object));
- }
- else if (object->type == InlineQueryResultCachedSticker::TYPE) {
+ } else if (object->type == InlineQueryResultCachedSticker::TYPE) {
result += parseInlineQueryResultCachedSticker(std::static_pointer_cast<InlineQueryResultCachedSticker>(object));
- }
- else if (object->type == InlineQueryResultCachedVideo::TYPE) {
+ } else if (object->type == InlineQueryResultCachedVideo::TYPE) {
result += parseInlineQueryResultCachedVideo(std::static_pointer_cast<InlineQueryResultCachedVideo>(object));
- }
- else if (object->type == InlineQueryResultCachedVoice::TYPE) {
+ } else if (object->type == InlineQueryResultCachedVoice::TYPE) {
result += parseInlineQueryResultCachedVoice(std::static_pointer_cast<InlineQueryResultCachedVoice>(object));
- }
- else if (object->type == InlineQueryResultArticle::TYPE) {
+ } else if (object->type == InlineQueryResultArticle::TYPE) {
result += parseInlineQueryResultArticle(std::static_pointer_cast<InlineQueryResultArticle>(object));
- }
- else if (object->type == InlineQueryResultAudio::TYPE) {
+ } else if (object->type == InlineQueryResultAudio::TYPE) {
result += parseInlineQueryResultAudio(std::static_pointer_cast<InlineQueryResultAudio>(object));
- }
- else if (object->type == InlineQueryResultContact::TYPE) {
+ } else if (object->type == InlineQueryResultContact::TYPE) {
result += parseInlineQueryResultContact(std::static_pointer_cast<InlineQueryResultContact>(object));
- }
- else if (object->type == InlineQueryResultGame::TYPE) {
+ } else if (object->type == InlineQueryResultGame::TYPE) {
result += parseInlineQueryResultGame(std::static_pointer_cast<InlineQueryResultGame>(object));
- }
- else if (object->type == InlineQueryResultDocument::TYPE) {
+ } else if (object->type == InlineQueryResultDocument::TYPE) {
result += parseInlineQueryResultDocument(std::static_pointer_cast<InlineQueryResultDocument>(object));
- }
- else if (object->type == InlineQueryResultLocation::TYPE) {
+ } else if (object->type == InlineQueryResultLocation::TYPE) {
result += parseInlineQueryResultLocation(std::static_pointer_cast<InlineQueryResultLocation>(object));
- }
- else if (object->type == InlineQueryResultVenue::TYPE) {
+ } else if (object->type == InlineQueryResultVenue::TYPE) {
result += parseInlineQueryResultVenue(std::static_pointer_cast<InlineQueryResultVenue>(object));
- }
- else if (object->type == InlineQueryResultVoice::TYPE) {
+ } else if (object->type == InlineQueryResultVoice::TYPE) {
result += parseInlineQueryResultVoice(std::static_pointer_cast<InlineQueryResultVoice>(object));
- }
- else if (object->type == InlineQueryResultPhoto::TYPE) {
+ } else if (object->type == InlineQueryResultPhoto::TYPE) {
result += parseInlineQueryResultPhoto(std::static_pointer_cast<InlineQueryResultPhoto>(object));
- }
- else if (object->type == InlineQueryResultGif::TYPE) {
+ } else if (object->type == InlineQueryResultGif::TYPE) {
result += parseInlineQueryResultGif(std::static_pointer_cast<InlineQueryResultGif>(object));
- }
- else if (object->type == InlineQueryResultMpeg4Gif::TYPE) {
+ } else if (object->type == InlineQueryResultMpeg4Gif::TYPE) {
result += parseInlineQueryResultMpeg4Gif(std::static_pointer_cast<InlineQueryResultMpeg4Gif>(object));
- }
- else if (object->type == InlineQueryResultVideo::TYPE) {
+ } else if (object->type == InlineQueryResultVideo::TYPE) {
result += parseInlineQueryResultVideo(std::static_pointer_cast<InlineQueryResultVideo>(object));
}
@@ -2115,38 +2452,47 @@ std::string TgTypeParser::parseInlineQueryResult(const InlineQueryResult::Ptr& o
return result;
}
-InlineQueryResultCachedAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const {
+InlineQueryResultArticle::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultCachedAudio>());
- result->audioFileId = data.get<std::string>("audio_file_id", "");
- result->caption = data.get<std::string>("caption", "");
- result->parseMode = data.get<std::string>("parse_mode", "");
- result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
+ auto result(std::make_shared<InlineQueryResultArticle>());
+ result->title = data.get<std::string>("title", "");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
+ result->url = data.get<std::string>("url", "");
+ result->hideUrl = data.get<bool>("hide_url", false);
+ result->description = data.get<std::string>("description", "");
+ result->thumbUrl = data.get<std::string>("thumb_url", "");
+ result->thumbWidth = data.get<std::int32_t>("thumb_width", 0);
+ result->thumbHeight = data.get<std::int32_t>("thumb_height", 0);
return result;
}
-std::string TgTypeParser::parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "audio_file_id", object->audioFileId);
- appendToJson(result, "caption", object->caption);
- appendToJson(result, "parse_mode", object->parseMode);
- appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
+ appendToJson(result, "title", object->title);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
+ appendToJson(result, "url", object->url);
+ appendToJson(result, "hide_url", object->hideUrl);
+ appendToJson(result, "description", object->description);
+ appendToJson(result, "thumb_url", object->thumbUrl);
+ appendToJson(result, "thumb_width", object->thumbWidth);
+ appendToJson(result, "thumb_height", object->thumbHeight);
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-InlineQueryResultCachedDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const {
+InlineQueryResultPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultCachedDocument>());
+ auto result(std::make_shared<InlineQueryResultPhoto>());
+ result->photoUrl = data.get<std::string>("photo_url", "");
+ result->thumbUrl = data.get<std::string>("thumb_url", "");
+ result->photoWidth = data.get<std::int32_t>("photo_width", 0);
+ result->photoHeight = data.get<std::int32_t>("photo_height", 0);
result->title = data.get<std::string>("title", "");
- result->documentFileId = data.get<std::string>("document_file_id", "");
result->description = data.get<std::string>("description", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
@@ -2155,15 +2501,18 @@ InlineQueryResultCachedDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryRes
return result;
}
-std::string TgTypeParser::parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
+ appendToJson(result, "photo_url", object->photoUrl);
+ appendToJson(result, "thumb_url", object->thumbUrl);
+ appendToJson(result, "photo_width", object->photoWidth);
+ appendToJson(result, "photo_height", object->photoHeight);
appendToJson(result, "title", object->title);
- appendToJson(result, "document_file_id", object->documentFileId);
appendToJson(result, "description", object->description);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
@@ -2173,10 +2522,15 @@ std::string TgTypeParser::parseInlineQueryResultCachedDocument(const InlineQuery
return result;
}
-InlineQueryResultCachedGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const {
+InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultCachedGif>());
- result->gifFileId = data.get<std::string>("gif_file_id", "");
+ auto result(std::make_shared<InlineQueryResultGif>());
+ result->gifUrl = data.get<std::string>("gif_url", "");
+ result->gifWidth = data.get<std::int32_t>("gif_width", 0);
+ result->gifHeight = data.get<std::int32_t>("gif_height", 0);
+ result->gifDuration = data.get<std::int32_t>("gif_duration", 0);
+ result->thumbUrl = data.get<std::string>("thumb_url", "");
+ result->thumbMimeType = data.get<std::string>("thumb_mime_type", "");
result->title = data.get<std::string>("title", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
@@ -2185,14 +2539,19 @@ InlineQueryResultCachedGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCa
return result;
}
-std::string TgTypeParser::parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "gif_file_id", object->gifFileId);
+ appendToJson(result, "gif_url", object->gifUrl);
+ appendToJson(result, "gif_width", object->gifWidth);
+ appendToJson(result, "gif_height", object->gifHeight);
+ appendToJson(result, "gif_duration", object->gifDuration);
+ appendToJson(result, "thumb_url", object->thumbUrl);
+ appendToJson(result, "thumb_mime_type", object->thumbMimeType);
appendToJson(result, "title", object->title);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
@@ -2202,10 +2561,15 @@ std::string TgTypeParser::parseInlineQueryResultCachedGif(const InlineQueryResul
return result;
}
-InlineQueryResultCachedMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const {
+InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpeg4Gif(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultCachedMpeg4Gif>());
- result->mpeg4FileId = data.get<std::string>("mpeg4_file_id", "");
+ auto result(std::make_shared<InlineQueryResultMpeg4Gif>());
+ result->mpeg4Url = data.get<std::string>("mpeg4_url", "");
+ result->mpeg4Width = data.get<std::int32_t>("mpeg4_width", 0);
+ result->mpeg4Height = data.get<std::int32_t>("mpeg4_height", 0);
+ result->mpeg4Duration = data.get<std::int32_t>("mpeg4_duration", 0);
+ result->thumbUrl = data.get<std::string>("thumb_url", "");
+ result->thumbMimeType = data.get<std::string>("thumb_mime_type", "");
result->title = data.get<std::string>("title", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
@@ -2214,14 +2578,19 @@ InlineQueryResultCachedMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryRes
return result;
}
-std::string TgTypeParser::parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResultMpeg4Gif::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "mpeg4_file_id", object->mpeg4FileId);
+ appendToJson(result, "mpeg4_url", object->mpeg4Url);
+ appendToJson(result, "mpeg4_width", object->mpeg4Width);
+ appendToJson(result, "mpeg4_height", object->mpeg4Height);
+ appendToJson(result, "mpeg4_duration", object->mpeg4Duration);
+ appendToJson(result, "thumb_url", object->thumbUrl);
+ appendToJson(result, "thumb_mime_type", object->thumbMimeType);
appendToJson(result, "title", object->title);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
@@ -2231,144 +2600,182 @@ std::string TgTypeParser::parseInlineQueryResultCachedMpeg4Gif(const InlineQuery
return result;
}
-InlineQueryResultCachedPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const {
+InlineQueryResultVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultCachedPhoto>());
- result->photoFileId = data.get<std::string>("photo_file_id", "");
+ auto result(std::make_shared<InlineQueryResultVideo>());
+ result->videoUrl = data.get<std::string>("video_url", "");
+ result->mimeType = data.get<std::string>("mime_type", "");
+ result->thumbUrl = data.get<std::string>("thumb_url", "");
result->title = data.get<std::string>("title", "");
- result->description = data.get<std::string>("description", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
+ result->videoWidth = data.get<std::int32_t>("video_width", 0);
+ result->videoHeight = data.get<std::int32_t>("video_height", 0);
+ result->videoDuration = data.get<std::int32_t>("video_duration", 0);
+ result->description = data.get<std::string>("description", "");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
return result;
}
-std::string TgTypeParser::parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "photo_file_id", object->photoFileId);
+ appendToJson(result, "video_url", object->videoUrl);
+ appendToJson(result, "mime_type", object->mimeType);
+ appendToJson(result, "thumb_url", object->thumbUrl);
appendToJson(result, "title", object->title);
- appendToJson(result, "description", object->description);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
+ appendToJson(result, "video_width", object->videoWidth);
+ appendToJson(result, "video_height", object->videoHeight);
+ appendToJson(result, "video_duration", object->videoDuration);
+ appendToJson(result, "description", object->description);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-InlineQueryResultCachedSticker::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const {
+InlineQueryResultAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultCachedSticker>());
- result->stickerFileId = data.get<std::string>("sticker_file_id", "");
+ auto result(std::make_shared<InlineQueryResultAudio>());
+ result->audioUrl = data.get<std::string>("audio_url", "");
+ result->title = data.get<std::string>("title", "");
+ result->caption = data.get<std::string>("caption", "");
+ result->parseMode = data.get<std::string>("parse_mode", "");
+ result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
+ result->performer = data.get<std::string>("performer", "");
+ result->audioDuration = data.get<std::int32_t>("audio_duration", 0);
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
return result;
}
-std::string TgTypeParser::parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "sticker_file_id", object->stickerFileId);
+ appendToJson(result, "audio_url", object->audioUrl);
+ appendToJson(result, "title", object->title);
+ appendToJson(result, "caption", object->caption);
+ appendToJson(result, "parse_mode", object->parseMode);
+ appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
+ appendToJson(result, "performer", object->performer);
+ appendToJson(result, "audio_duration", object->audioDuration);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-InlineQueryResultCachedVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const {
+InlineQueryResultVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultCachedVideo>());
- result->videoFileId = data.get<std::string>("video_file_id", "");
+ auto result(std::make_shared<InlineQueryResultVoice>());
+ result->voiceUrl = data.get<std::string>("voice_url", "");
result->title = data.get<std::string>("title", "");
- result->description = data.get<std::string>("description", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
+ result->voiceDuration = data.get<std::int32_t>("voice_duration", 0);
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
return result;
}
-std::string TgTypeParser::parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "video_file_id", object->videoFileId);
+ appendToJson(result, "voice_url", object->voiceUrl);
appendToJson(result, "title", object->title);
- appendToJson(result, "description", object->description);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
+ appendToJson(result, "voice_duration", object->voiceDuration);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-InlineQueryResultCachedVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const {
+InlineQueryResultDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultCachedVoice>());
- result->voiceFileId = data.get<std::string>("voice_file_id", "");
+ auto result(std::make_shared<InlineQueryResultDocument>());
result->title = data.get<std::string>("title", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
+ result->documentUrl = data.get<std::string>("document_url", "");
+ result->mimeType = data.get<std::string>("mime_type", "");
+ result->description = data.get<std::string>("description", "");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
+ result->thumbUrl = data.get<std::string>("thumb_url", "");
+ result->thumbWidth = data.get<std::int32_t>("thumb_width", 0);
+ result->thumbHeight = data.get<std::int32_t>("thumb_height", 0);
return result;
}
-std::string TgTypeParser::parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "voice_file_id", object->voiceFileId);
appendToJson(result, "title", object->title);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
+ appendToJson(result, "document_url", object->documentUrl);
+ appendToJson(result, "mime_type", object->mimeType);
+ appendToJson(result, "description", object->description);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
+ appendToJson(result, "thumb_url", object->thumbUrl);
+ appendToJson(result, "thumb_width", object->thumbWidth);
+ appendToJson(result, "thumb_height", object->thumbHeight);
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-InlineQueryResultArticle::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const {
+InlineQueryResultLocation::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultArticle>());
+ auto result(std::make_shared<InlineQueryResultLocation>());
+ result->latitude = data.get<float>("latitude", 0);
+ result->longitude = data.get<float>("longitude", 0);
result->title = data.get<std::string>("title", "");
+ result->horizontalAccuracy = data.get<float>("horizontal_accuracy", 0);
+ result->livePeriod = data.get<std::int32_t>("live_period", 0);
+ result->heading = data.get<std::int32_t>("heading", 0);
+ result->proximityAlertRadius = data.get<std::int32_t>("proximity_alert_radius", 0);
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
- result->url = data.get<std::string>("url", "");
- result->hideUrl = data.get<bool>("hide_url", false);
- result->description = data.get<std::string>("description", "");
result->thumbUrl = data.get<std::string>("thumb_url", "");
result->thumbWidth = data.get<std::int32_t>("thumb_width", 0);
result->thumbHeight = data.get<std::int32_t>("thumb_height", 0);
return result;
}
-std::string TgTypeParser::parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
+ appendToJson(result, "latitude", object->latitude);
+ appendToJson(result, "longitude", object->longitude);
appendToJson(result, "title", object->title);
+ appendToJson(result, "horizontal_accuracy", object->horizontalAccuracy);
+ appendToJson(result, "live_period", object->livePeriod);
+ appendToJson(result, "heading", object->heading);
+ appendToJson(result, "proximity_alert_radius", object->proximityAlertRadius);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
- appendToJson(result, "url", object->url);
- appendToJson(result, "hide_url", object->hideUrl);
- appendToJson(result, "description", object->description);
appendToJson(result, "thumb_url", object->thumbUrl);
appendToJson(result, "thumb_width", object->thumbWidth);
appendToJson(result, "thumb_height", object->thumbHeight);
@@ -2376,35 +2783,43 @@ std::string TgTypeParser::parseInlineQueryResultArticle(const InlineQueryResultA
return result;
}
-InlineQueryResultAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const {
+InlineQueryResultVenue::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultAudio>());
- result->audioUrl = data.get<std::string>("audio_url", "");
+ auto result(std::make_shared<InlineQueryResultVenue>());
+ result->latitude = data.get<float>("latitude", 0);
+ result->longitude = data.get<float>("longitude", 0);
result->title = data.get<std::string>("title", "");
- result->caption = data.get<std::string>("caption", "");
- result->parseMode = data.get<std::string>("parse_mode", "");
- result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
- result->performer = data.get<std::string>("performer", "");
- result->audioDuration = data.get<std::int32_t>("audio_duration", 0);
+ result->address = data.get<std::string>("address", "");
+ result->foursquareId = data.get<std::string>("foursquare_id", "");
+ result->foursquareType = data.get<std::string>("foursquare_type", "");
+ result->googlePlaceId = data.get<std::string>("google_place_id", "");
+ result->googlePlaceType = data.get<std::string>("google_place_type", "");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
+ result->thumbUrl = data.get<std::string>("thumb_url", "");
+ result->thumbWidth = data.get<std::int32_t>("thumb_width", 0);
+ result->thumbHeight = data.get<std::int32_t>("thumb_height", 0);
return result;
}
-std::string TgTypeParser::parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "audio_url", object->audioUrl);
+ appendToJson(result, "latitude", object->latitude);
+ appendToJson(result, "longitude", object->longitude);
appendToJson(result, "title", object->title);
- appendToJson(result, "caption", object->caption);
- appendToJson(result, "parse_mode", object->parseMode);
- appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
- appendToJson(result, "performer", object->performer);
- appendToJson(result, "audio_duration", object->audioDuration);
+ appendToJson(result, "address", object->address);
+ appendToJson(result, "foursquare_id", object->foursquareId);
+ appendToJson(result, "foursquare_type", object->foursquareType);
+ appendToJson(result, "google_place_id", object->googlePlaceId);
+ appendToJson(result, "google_place_type", object->googlePlaceType);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
+ appendToJson(result, "thumb_url", object->thumbUrl);
+ appendToJson(result, "thumb_width", object->thumbWidth);
+ appendToJson(result, "thumb_height", object->thumbHeight);
// The last comma will be erased by parseInlineQueryResult().
return result;
}
@@ -2424,7 +2839,7 @@ InlineQueryResultContact::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCont
}
std::string TgTypeParser::parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const {
- if (!object){
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
@@ -2442,7 +2857,6 @@ std::string TgTypeParser::parseInlineQueryResultContact(const InlineQueryResultC
return result;
}
-
InlineQueryResultGame::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
auto result(std::make_shared<InlineQueryResultGame>());
@@ -2451,7 +2865,7 @@ InlineQueryResultGame::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGame(co
}
std::string TgTypeParser::parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const {
- if (!object){
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
@@ -2462,165 +2876,121 @@ std::string TgTypeParser::parseInlineQueryResultGame(const InlineQueryResultGame
return result;
}
-InlineQueryResultDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const {
+InlineQueryResultCachedPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultDocument>());
+ auto result(std::make_shared<InlineQueryResultCachedPhoto>());
+ result->photoFileId = data.get<std::string>("photo_file_id", "");
result->title = data.get<std::string>("title", "");
+ result->description = data.get<std::string>("description", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
- result->documentUrl = data.get<std::string>("document_url", "");
- result->mimeType = data.get<std::string>("mime_type", "");
- result->description = data.get<std::string>("description", "");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
- result->thumbUrl = data.get<std::string>("thumb_url", "");
- result->thumbWidth = data.get<std::int32_t>("thumb_width", 0);
- result->thumbHeight = data.get<std::int32_t>("thumb_height", 0);
return result;
}
-std::string TgTypeParser::parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
+ appendToJson(result, "photo_file_id", object->photoFileId);
appendToJson(result, "title", object->title);
+ appendToJson(result, "description", object->description);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
- appendToJson(result, "document_url", object->documentUrl);
- appendToJson(result, "mime_type", object->mimeType);
- appendToJson(result, "description", object->description);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
- appendToJson(result, "thumb_url", object->thumbUrl);
- appendToJson(result, "thumb_width", object->thumbWidth);
- appendToJson(result, "thumb_height", object->thumbHeight);
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-InlineQueryResultLocation::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const {
+InlineQueryResultCachedGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultLocation>());
- result->latitude = data.get<float>("latitude", 0);
- result->longitude = data.get<float>("longitude", 0);
+ auto result(std::make_shared<InlineQueryResultCachedGif>());
+ result->gifFileId = data.get<std::string>("gif_file_id", "");
result->title = data.get<std::string>("title", "");
- result->horizontalAccuracy = data.get<float>("horizontal_accuracy", 0);
- result->livePeriod = data.get<std::int32_t>("live_period", 0);
- result->heading = data.get<std::int32_t>("heading", 0);
- result->proximityAlertRadius = data.get<std::int32_t>("proximity_alert_radius", 0);
+ result->caption = data.get<std::string>("caption", "");
+ result->parseMode = data.get<std::string>("parse_mode", "");
+ result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
- result->thumbUrl = data.get<std::string>("thumb_url", "");
- result->thumbWidth = data.get<std::int32_t>("thumb_width", 0);
- result->thumbHeight = data.get<std::int32_t>("thumb_height", 0);
return result;
}
-std::string TgTypeParser::parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "latitude", object->latitude);
- appendToJson(result, "longitude", object->longitude);
+ appendToJson(result, "gif_file_id", object->gifFileId);
appendToJson(result, "title", object->title);
- appendToJson(result, "horizontal_accuracy", object->horizontalAccuracy);
- appendToJson(result, "live_period", object->livePeriod);
- appendToJson(result, "heading", object->heading);
- appendToJson(result, "proximity_alert_radius", object->proximityAlertRadius);
+ appendToJson(result, "caption", object->caption);
+ appendToJson(result, "parse_mode", object->parseMode);
+ appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
- appendToJson(result, "thumb_url", object->thumbUrl);
- appendToJson(result, "thumb_width", object->thumbWidth);
- appendToJson(result, "thumb_height", object->thumbHeight);
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-
-InlineQueryResultVenue::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const {
+InlineQueryResultCachedMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultVenue>());
- result->latitude = data.get<float>("latitude", 0);
- result->longitude = data.get<float>("longitude", 0);
+ auto result(std::make_shared<InlineQueryResultCachedMpeg4Gif>());
+ result->mpeg4FileId = data.get<std::string>("mpeg4_file_id", "");
result->title = data.get<std::string>("title", "");
- result->address = data.get<std::string>("address", "");
- result->foursquareId = data.get<std::string>("foursquare_id", "");
- result->foursquareType = data.get<std::string>("foursquare_type", "");
- result->googlePlaceId = data.get<std::string>("google_place_id", "");
- result->googlePlaceType = data.get<std::string>("google_place_type", "");
+ result->caption = data.get<std::string>("caption", "");
+ result->parseMode = data.get<std::string>("parse_mode", "");
+ result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
- result->thumbUrl = data.get<std::string>("thumb_url", "");
- result->thumbWidth = data.get<std::int32_t>("thumb_width", 0);
- result->thumbHeight = data.get<std::int32_t>("thumb_height", 0);
return result;
}
-std::string TgTypeParser::parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "latitude", object->latitude);
- appendToJson(result, "longitude", object->longitude);
+ appendToJson(result, "mpeg4_file_id", object->mpeg4FileId);
appendToJson(result, "title", object->title);
- appendToJson(result, "address", object->address);
- appendToJson(result, "foursquare_id", object->foursquareId);
- appendToJson(result, "foursquare_type", object->foursquareType);
- appendToJson(result, "google_place_id", object->googlePlaceId);
- appendToJson(result, "google_place_type", object->googlePlaceType);
+ appendToJson(result, "caption", object->caption);
+ appendToJson(result, "parse_mode", object->parseMode);
+ appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
- appendToJson(result, "thumb_url", object->thumbUrl);
- appendToJson(result, "thumb_width", object->thumbWidth);
- appendToJson(result, "thumb_height", object->thumbHeight);
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-InlineQueryResultVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const {
+InlineQueryResultCachedSticker::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultVoice>());
- result->voiceUrl = data.get<std::string>("voice_url", "");
- result->title = data.get<std::string>("title", "");
- result->caption = data.get<std::string>("caption", "");
- result->parseMode = data.get<std::string>("parse_mode", "");
- result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
- result->voiceDuration = data.get<std::int32_t>("voice_duration", 0);
+ auto result(std::make_shared<InlineQueryResultCachedSticker>());
+ result->stickerFileId = data.get<std::string>("sticker_file_id", "");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
return result;
}
-std::string TgTypeParser::parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "voice_url", object->voiceUrl);
- appendToJson(result, "title", object->title);
- appendToJson(result, "caption", object->caption);
- appendToJson(result, "parse_mode", object->parseMode);
- appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
- appendToJson(result, "voice_duration", object->voiceDuration);
+ appendToJson(result, "sticker_file_id", object->stickerFileId);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-InlineQueryResultPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const {
+InlineQueryResultCachedDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultPhoto>());
- result->photoUrl = data.get<std::string>("photo_url", "");
- result->thumbUrl = data.get<std::string>("thumb_url", "");
- result->photoWidth = data.get<std::int32_t>("photo_width", 0);
- result->photoHeight = data.get<std::int32_t>("photo_height", 0);
+ auto result(std::make_shared<InlineQueryResultCachedDocument>());
result->title = data.get<std::string>("title", "");
+ result->documentFileId = data.get<std::string>("document_file_id", "");
result->description = data.get<std::string>("description", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
@@ -2629,18 +2999,15 @@ InlineQueryResultPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultPhoto(
return result;
}
-std::string TgTypeParser::parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const{
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "photo_url", object->photoUrl);
- appendToJson(result, "thumb_url", object->thumbUrl);
- appendToJson(result, "photo_width", object->photoWidth);
- appendToJson(result, "photo_height", object->photoHeight);
appendToJson(result, "title", object->title);
+ appendToJson(result, "document_file_id", object->documentFileId);
appendToJson(result, "description", object->description);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
@@ -2650,16 +3017,12 @@ std::string TgTypeParser::parseInlineQueryResultPhoto(const InlineQueryResultPho
return result;
}
-InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const {
+InlineQueryResultCachedVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultGif>());
- result->gifUrl = data.get<std::string>("gif_url", "");
- result->gifWidth = data.get<std::int32_t>("gif_width", 0);
- result->gifHeight = data.get<std::int32_t>("gif_height", 0);
- result->gifDuration = data.get<std::int32_t>("gif_duration", 0);
- result->thumbUrl = data.get<std::string>("thumb_url", "");
- result->thumbMimeType = data.get<std::string>("thumb_mime_type", "");
+ auto result(std::make_shared<InlineQueryResultCachedVideo>());
+ result->videoFileId = data.get<std::string>("video_file_id", "");
result->title = data.get<std::string>("title", "");
+ result->description = data.get<std::string>("description", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
@@ -2667,20 +3030,16 @@ InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(cons
return result;
}
-std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "gif_url", object->gifUrl);
- appendToJson(result, "gif_width", object->gifWidth);
- appendToJson(result, "gif_height", object->gifHeight);
- appendToJson(result, "gif_duration", object->gifDuration);
- appendToJson(result, "thumb_url", object->thumbUrl);
- appendToJson(result, "thumb_mime_type", object->thumbMimeType);
+ appendToJson(result, "video_file_id", object->videoFileId);
appendToJson(result, "title", object->title);
+ appendToJson(result, "description", object->description);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
@@ -2689,15 +3048,10 @@ std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif::
return result;
}
-InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpeg4Gif(const boost::property_tree::ptree& data) const {
+InlineQueryResultCachedVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultMpeg4Gif>());
- result->mpeg4Url = data.get<std::string>("mpeg4_url", "");
- result->mpeg4Width = data.get<std::int32_t>("mpeg4_width", 0);
- result->mpeg4Height = data.get<std::int32_t>("mpeg4_height", 0);
- result->mpeg4Duration = data.get<std::int32_t>("mpeg4_duration", 0);
- result->thumbUrl = data.get<std::string>("thumb_url", "");
- result->thumbMimeType = data.get<std::string>("thumb_mime_type", "");
+ auto result(std::make_shared<InlineQueryResultCachedVoice>());
+ result->voiceFileId = data.get<std::string>("voice_file_id", "");
result->title = data.get<std::string>("title", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
@@ -2706,19 +3060,14 @@ InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpe
return result;
}
-std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResultMpeg4Gif::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "mpeg4_url", object->mpeg4Url);
- appendToJson(result, "mpeg4_width", object->mpeg4Width);
- appendToJson(result, "mpeg4_height", object->mpeg4Height);
- appendToJson(result, "mpeg4_duration", object->mpeg4Duration);
- appendToJson(result, "thumb_url", object->thumbUrl);
- appendToJson(result, "thumb_mime_type", object->thumbMimeType);
+ appendToJson(result, "voice_file_id", object->voiceFileId);
appendToJson(result, "title", object->title);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
@@ -2728,246 +3077,33 @@ std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResult
return result;
}
-InlineQueryResultVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const {
+InlineQueryResultCachedAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInlineQueryResult().
- auto result(std::make_shared<InlineQueryResultVideo>());
- result->videoUrl = data.get<std::string>("video_url", "");
- result->mimeType = data.get<std::string>("mime_type", "");
- result->thumbUrl = data.get<std::string>("thumb_url", "");
- result->title = data.get<std::string>("title", "");
+ auto result(std::make_shared<InlineQueryResultCachedAudio>());
+ result->audioFileId = data.get<std::string>("audio_file_id", "");
result->caption = data.get<std::string>("caption", "");
result->parseMode = data.get<std::string>("parse_mode", "");
result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
- result->videoWidth = data.get<std::int32_t>("video_width", 0);
- result->videoHeight = data.get<std::int32_t>("video_height", 0);
- result->videoDuration = data.get<std::int32_t>("video_duration", 0);
- result->description = data.get<std::string>("description", "");
result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content");
return result;
}
-std::string TgTypeParser::parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const {
- if (!object){
+std::string TgTypeParser::parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const {
+ if (!object) {
return "";
}
// This function will be called by parseInlineQueryResult(), so I don't add
// curly brackets to the result std::string.
std::string result;
- appendToJson(result, "video_url", object->videoUrl);
- appendToJson(result, "mime_type", object->mimeType);
- appendToJson(result, "thumb_url", object->thumbUrl);
- appendToJson(result, "title", object->title);
+ appendToJson(result, "audio_file_id", object->audioFileId);
appendToJson(result, "caption", object->caption);
appendToJson(result, "parse_mode", object->parseMode);
appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
- appendToJson(result, "video_width", object->videoWidth);
- appendToJson(result, "video_height", object->videoHeight);
- appendToJson(result, "video_duration", object->videoDuration);
- appendToJson(result, "description", object->description);
appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent));
// The last comma will be erased by parseInlineQueryResult().
return result;
}
-ChosenInlineResult::Ptr TgTypeParser::parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<ChosenInlineResult>());
- result->resultId = data.get<std::string>("result_id", "");
- result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
- result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
- result->inlineMessageId = data.get<std::string>("inline_message_id", "");
- result->query = data.get<std::string>("query", "");
- return result;
-}
-
-std::string TgTypeParser::parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const {
- if (!object){
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "result_id", object->resultId);
- appendToJson(result, "from", parseUser(object->from));
- appendToJson(result, "query", object->query);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-SentWebAppMessage::Ptr TgTypeParser::parseJsonAndGetSentWebAppMessage(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<SentWebAppMessage>());
- result->inlineMessageId = data.get<std::string>("inline_message_id", "");
- return result;
-}
-
-std::string TgTypeParser::parseSentWebAppMessage(const SentWebAppMessage::Ptr& object) const {
- if (!object){
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "inline_message_id", object->inlineMessageId);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<CallbackQuery>());
- result->id = data.get<std::string>("id");
- result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
- result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message");
- result->inlineMessageId = data.get<std::string>("inline_message_id", "");
- result->chatInstance = data.get<std::string>("chat_instance");
- result->gameShortName = data.get<std::string>("game_short_name", "");
- result->data = data.get<std::string>("data", "");
- return result;
-}
-
-std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) const {
- if (!object){
- return "";
- }
-
- std::string result;
- result += '{';
- appendToJson(result, "id", object->id);
- appendToJson(result, "from", parseUser(object->from));
- appendToJson(result, "message", parseMessage(object->message));
- appendToJson(result, "inline_message_id", object->inlineMessageId);
- appendToJson(result, "chat_instance", object->chatInstance);
- appendToJson(result, "game_short_name", object->gameShortName);
- appendToJson(result, "data", object->data);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-InlineKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<InlineKeyboardMarkup>());
- for (const auto& item : data.find("inline_keyboard")->second){
- result->inlineKeyboard.push_back(parseJsonAndGetArray<InlineKeyboardButton>(&TgTypeParser::parseJsonAndGetInlineKeyboardButton, item.second));
- }
- return result;
-}
-
-std::string TgTypeParser::parseInlineKeyboardMarkup(const InlineKeyboardMarkup::Ptr& object) const {
- if (!object){
- return "";
- }
- std::string result;
- result += '{';
- result += R"("inline_keyboard":[)";
- for (const auto& item : object->inlineKeyboard){
- result += '[';
- for (const auto& innerItem : item){
- result += parseInlineKeyboardButton(innerItem);
- result += ',';
- }
- removeLastComma(result);
- result += "],";
- }
- if (!object->inlineKeyboard.empty())
- removeLastComma(result);
- result += "]}";
- return result;
-}
-
-InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<InlineKeyboardButton>());
- result->text = data.get<std::string>("text", "");
- result->url = data.get<std::string>("url", "");
- result->callbackData = data.get<std::string>("callback_data", "");
- result->webApp = tryParseJson<WebAppInfo>(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app");
- result->loginUrl = tryParseJson<LoginUrl>(&TgTypeParser::parseJsonAndGetLoginUrl, data, "login_url");
- result->switchInlineQuery = data.get<std::string>("switch_inline_query", "");
- result->switchInlineQueryCurrentChat = data.get<std::string>("switch_inline_query_current_chat", "");
- result->callbackGame = tryParseJson<CallbackGame>(&TgTypeParser::parseJsonAndGetCallbackGame, data, "callback_game");
- result->pay = data.get<bool>("pay", false);
- return result;
-}
-std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const {
- if (!object){
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "pay", object->pay);
- appendToJson(result, "text", object->text);
- appendToJson(result, "url", object->url);
- appendToJson(result, "callback_data", object->callbackData);
- appendToJson(result, "switch_inline_query", object->switchInlineQuery);
- appendToJson(result, "switch_inline_query_current_chat", object->switchInlineQueryCurrentChat);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-LoginUrl::Ptr TgTypeParser::parseJsonAndGetLoginUrl(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<LoginUrl>());
- result->url = data.get<std::string>("url", "");
- result->forwardText = data.get<std::string>("forward_text", "");
- result->botUsername = data.get<std::string>("bot_username", "");
- result->requestWriteAccess = data.get<bool>("request_write_access", false);
- return result;
-}
-
-std::string TgTypeParser::parseLoginUrl(const LoginUrl::Ptr& object) const {
- if (!object){
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "url", object->url);
- appendToJson(result, "forward_text", object->forwardText);
- appendToJson(result, "bot_username", object->botUsername);
- appendToJson(result, "request_write_access", object->requestWriteAccess);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<WebhookInfo>());
- result->url = data.get<std::string>("url", "");
- result->hasCustomCertificate = data.get<bool>("has_custom_certificate", false);
- result->pendingUpdateCount = data.get<std::int32_t>("pending_update_count", 0);
- result->ipAddress = data.get<std::string>("ip_address", "");
- result->lastErrorDate = data.get<std::int32_t>("last_error_date", 0);
- result->lastErrorMessage = data.get<std::string>("last_error_message", "");
- result->lastSynchronizationErrorDate = data.get<std::int32_t>("last_synchronization_error_date", 0);
- result->maxConnections = data.get<std::int32_t>("max_connections", 0);
- result->allowedUpdates = parseJsonAndGetArray<std::string>(
- [](const boost::property_tree::ptree& innerData)->std::string {
- return innerData.get<std::string>("");
- }
- , data, "allowed_updates");
- return result;
-}
-
-std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const {
- if (!object) {
- return "";
- }
- std::string result;
- result += '{';
- appendToJson(result, "url", object->url);
- appendToJson(result, "has_custom_certificate", object->hasCustomCertificate);
- appendToJson(result, "pending_update_count", object->pendingUpdateCount);
- appendToJson(result, "ip_address", object->ipAddress);
- appendToJson(result, "last_error_date", object->lastErrorDate);
- appendToJson(result, "last_error_message", object->lastErrorMessage);
- appendToJson(result, "last_synchronization_error_date", object->lastSynchronizationErrorDate);
- appendToJson(result, "max_connections", object->maxConnections);
- appendToJson(result, "allowed_updates",
- parseArray<std::string>([](const std::string &s)->std::string {
- return s;
- }
- , object->allowedUpdates));
- removeLastComma(result);
- result += '}';
- return result;
-}
-
InputMessageContent::Ptr TgTypeParser::parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const {
InputMessageContent::Ptr result;
@@ -2995,7 +3131,7 @@ InputMessageContent::Ptr TgTypeParser::parseJsonAndGetInputMessageContent(const
}
std::string TgTypeParser::parseInputMessageContent(const InputMessageContent::Ptr& object) const {
- if (!object){
+ if (!object) {
return "";
}
std::string result;
@@ -3029,7 +3165,7 @@ InputTextMessageContent::Ptr TgTypeParser::parseJsonAndGetInputTextMessageConten
}
std::string TgTypeParser::parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const {
- if (!object){
+ if (!object) {
return "";
}
// This function will be called by parseInputMessageContent()
@@ -3055,7 +3191,7 @@ InputLocationMessageContent::Ptr TgTypeParser::parseJsonAndGetInputLocationMessa
}
std::string TgTypeParser::parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const {
- if (!object){
+ if (!object) {
return "";
}
// This function will be called by parseInputMessageContent()
@@ -3085,7 +3221,7 @@ InputVenueMessageContent::Ptr TgTypeParser::parseJsonAndGetInputVenueMessageCont
}
std::string TgTypeParser::parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const {
- if (!object){
+ if (!object) {
return "";
}
// This function will be called by parseInputMessageContent()
@@ -3113,7 +3249,7 @@ InputContactMessageContent::Ptr TgTypeParser::parseJsonAndGetInputContactMessage
}
std::string TgTypeParser::parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const {
- if (!object){
+ if (!object) {
return "";
}
// This function will be called by parseInputMessageContent()
@@ -3136,8 +3272,9 @@ InputInvoiceMessageContent::Ptr TgTypeParser::parseJsonAndGetInputInvoiceMessage
result->currency = data.get<std::string>("currency", "");
result->prices = parseJsonAndGetArray<LabeledPrice>(&TgTypeParser::parseJsonAndGetLabeledPrice, data, "prices");
result->maxTipAmount = data.get<std::int32_t>("max_tip_amount", 0);
- result->suggestedTipAmounts = parseJsonAndGetArray<std::int32_t>([] (const boost::property_tree::ptree& innerData)->std::int32_t {
- return innerData.get<std::int32_t>(0);
+ result->suggestedTipAmounts = parseJsonAndGetArray<std::int32_t>(
+ [] (const boost::property_tree::ptree& innerData)->std::int32_t {
+ return innerData.get<std::int32_t>("");
}, data, "suggested_tip_amounts");
result->providerData = data.get<std::string>("provider_data", "");
result->photoUrl = data.get<std::string>("photo_url", "");
@@ -3186,344 +3323,118 @@ std::string TgTypeParser::parseInputInvoiceMessageContent(const InputInvoiceMess
return result;
}
-Invoice::Ptr TgTypeParser::parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<Invoice>());
- result->title = data.get<std::string>("title");
- result->description = data.get<std::string>("description");
- result->startParameter = data.get<std::string>("start_parameter");
- result->currency = data.get<std::string>("currency");
- result->totalAmount = data.get<std::int32_t>("total_amount");
+ChosenInlineResult::Ptr TgTypeParser::parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ChosenInlineResult>());
+ result->resultId = data.get<std::string>("result_id", "");
+ result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
+ result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
+ result->inlineMessageId = data.get<std::string>("inline_message_id", "");
+ result->query = data.get<std::string>("query", "");
return result;
}
-std::string TgTypeParser::parseInvoice(const Invoice::Ptr& object) const {
+std::string TgTypeParser::parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "title", object->title);
- appendToJson(result, "description", object->description);
- appendToJson(result, "start_parameter", object->startParameter);
- appendToJson(result, "currency", object->currency);
- appendToJson(result, "total_amount", object->totalAmount);
+ appendToJson(result, "result_id", object->resultId);
+ appendToJson(result, "from", parseUser(object->from));
+ appendToJson(result, "query", object->query);
removeLastComma(result);
result += '}';
return result;
}
-LabeledPrice::Ptr TgTypeParser::parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<LabeledPrice>());
- result->label = data.get<std::string>("label");
- result->amount = data.get<std::int32_t>("amount");
+SentWebAppMessage::Ptr TgTypeParser::parseJsonAndGetSentWebAppMessage(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<SentWebAppMessage>());
+ result->inlineMessageId = data.get<std::string>("inline_message_id", "");
return result;
}
-std::string TgTypeParser::parseLabeledPrice(const LabeledPrice::Ptr& object) const {
+std::string TgTypeParser::parseSentWebAppMessage(const SentWebAppMessage::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
std::string result;
result += '{';
- appendToJson(result, "label", object->label);
- appendToJson(result, "amount", object->amount);
+ appendToJson(result, "inline_message_id", object->inlineMessageId);
removeLastComma(result);
result += '}';
return result;
}
-BotCommand::Ptr TgTypeParser::parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<BotCommand>());
- result->command = data.get("command", "");
- result->description = data.get("description","");
+LabeledPrice::Ptr TgTypeParser::parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<LabeledPrice>());
+ result->label = data.get<std::string>("label");
+ result->amount = data.get<std::int32_t>("amount");
return result;
}
-std::string TgTypeParser::parseBotCommand(const BotCommand::Ptr& object) const {
+std::string TgTypeParser::parseLabeledPrice(const LabeledPrice::Ptr& object) const {
std::string result;
result += '{';
- appendToJson(result, "command", object->command);
- appendToJson(result, "description", object->description);
+ appendToJson(result, "label", object->label);
+ appendToJson(result, "amount", object->amount);
removeLastComma(result);
result += '}';
return result;
}
-BotCommandScope::Ptr TgTypeParser::parseJsonAndGetBotCommandScope(const boost::property_tree::ptree& data) const {
- std::string type = data.get<std::string>("type", "");
- BotCommandScope::Ptr result;
-
- if (type == BotCommandScopeDefault::TYPE) {
- result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeDefault(data));
- } else if (type == BotCommandScopeAllPrivateChats::TYPE) {
- result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeAllPrivateChats(data));
- } else if (type == BotCommandScopeAllGroupChats::TYPE) {
- result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeAllGroupChats(data));
- } else if (type == BotCommandScopeAllChatAdministrators::TYPE) {
- result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeAllChatAdministrators(data));
- } else if (type == BotCommandScopeChat::TYPE) {
- result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeChat(data));
- } else if (type == BotCommandScopeChatAdministrators::TYPE) {
- result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeChatAdministrators(data));
- } else if (type == BotCommandScopeChatMember::TYPE) {
- result = std::static_pointer_cast<BotCommandScope>(parseJsonAndGetBotCommandScopeChatMember(data));
- } else {
- result = std::make_shared<BotCommandScope>();
- }
-
- result->type = type;
-
+Invoice::Ptr TgTypeParser::parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Invoice>());
+ result->title = data.get<std::string>("title");
+ result->description = data.get<std::string>("description");
+ result->startParameter = data.get<std::string>("start_parameter");
+ result->currency = data.get<std::string>("currency");
+ result->totalAmount = data.get<std::int32_t>("total_amount");
return result;
}
-std::string TgTypeParser::parseBotCommandScope(const BotCommandScope::Ptr& object) const {
+std::string TgTypeParser::parseInvoice(const Invoice::Ptr& object) const {
if (!object) {
return "";
}
std::string result;
result += '{';
- appendToJson(result, "type", object->type);
-
- if (object->type == BotCommandScopeDefault::TYPE) {
- result += parseBotCommandScopeDefault(std::static_pointer_cast<BotCommandScopeDefault>(object));
- } else if (object->type == BotCommandScopeAllPrivateChats::TYPE) {
- result += parseBotCommandScopeAllPrivateChats(std::static_pointer_cast<BotCommandScopeAllPrivateChats>(object));
- } else if (object->type == BotCommandScopeAllGroupChats::TYPE) {
- result += parseBotCommandScopeAllGroupChats(std::static_pointer_cast<BotCommandScopeAllGroupChats>(object));
- } else if (object->type == BotCommandScopeAllChatAdministrators::TYPE) {
- result += parseBotCommandScopeAllChatAdministrators(std::static_pointer_cast<BotCommandScopeAllChatAdministrators>(object));
- } else if (object->type == BotCommandScopeChat::TYPE) {
- result += parseBotCommandScopeChat(std::static_pointer_cast<BotCommandScopeChat>(object));
- } else if (object->type == BotCommandScopeChatAdministrators::TYPE) {
- result += parseBotCommandScopeChatAdministrators(std::static_pointer_cast<BotCommandScopeChatAdministrators>(object));
- } else if (object->type == BotCommandScopeChatMember::TYPE) {
- result += parseBotCommandScopeChatMember(std::static_pointer_cast<BotCommandScopeChatMember>(object));
- }
-
+ appendToJson(result, "title", object->title);
+ appendToJson(result, "description", object->description);
+ appendToJson(result, "start_parameter", object->startParameter);
+ appendToJson(result, "currency", object->currency);
+ appendToJson(result, "total_amount", object->totalAmount);
removeLastComma(result);
result += '}';
return result;
}
-BotCommandScopeDefault::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeDefault(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
- auto result(std::make_shared<BotCommandScopeDefault>());
- return result;
-}
-
-std::string TgTypeParser::parseBotCommandScopeDefault(const BotCommandScopeDefault::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseBotCommandScope(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- // The last comma will be erased by parseBotCommandScope().
- return result;
-}
-
-BotCommandScopeAllPrivateChats::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllPrivateChats(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
- auto result(std::make_shared<BotCommandScopeAllPrivateChats>());
- return result;
-}
-
-std::string TgTypeParser::parseBotCommandScopeAllPrivateChats(const BotCommandScopeAllPrivateChats::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseBotCommandScope(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- // The last comma will be erased by parseBotCommandScope().
- return result;
-}
-
-BotCommandScopeAllGroupChats::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllGroupChats(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
- auto result(std::make_shared<BotCommandScopeAllGroupChats>());
- return result;
-}
-
-std::string TgTypeParser::parseBotCommandScopeAllGroupChats(const BotCommandScopeAllGroupChats::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseBotCommandScope(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- // The last comma will be erased by parseBotCommandScope().
- return result;
-}
-
-BotCommandScopeAllChatAdministrators::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllChatAdministrators(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
- auto result(std::make_shared<BotCommandScopeAllChatAdministrators>());
- return result;
-}
-
-std::string TgTypeParser::parseBotCommandScopeAllChatAdministrators(const BotCommandScopeAllChatAdministrators::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseBotCommandScope(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- // The last comma will be erased by parseBotCommandScope().
- return result;
-}
-
-BotCommandScopeChat::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeChat(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
- auto result(std::make_shared<BotCommandScopeChat>());
- result->chatId = data.get<std::int64_t>("chat_id", 0);
- return result;
-}
-
-std::string TgTypeParser::parseBotCommandScopeChat(const BotCommandScopeChat::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseBotCommandScope(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- appendToJson(result, "chat_id", object->chatId);
- // The last comma will be erased by parseBotCommandScope().
- return result;
-}
-
-BotCommandScopeChatAdministrators::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeChatAdministrators(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
- auto result(std::make_shared<BotCommandScopeChatAdministrators>());
- result->chatId = data.get<std::int64_t>("chat_id", 0);
- return result;
-}
-
-std::string TgTypeParser::parseBotCommandScopeChatAdministrators(const BotCommandScopeChatAdministrators::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseBotCommandScope(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- appendToJson(result, "chat_id", object->chatId);
- // The last comma will be erased by parseBotCommandScope().
- return result;
-}
-
-BotCommandScopeChatMember::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeChatMember(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetBotCommandScope().
- auto result(std::make_shared<BotCommandScopeChatMember>());
- result->chatId = data.get<std::int64_t>("chat_id", 0);
- result->userId = data.get<std::int64_t>("user_id", 0);
- return result;
-}
-
-std::string TgTypeParser::parseBotCommandScopeChatMember(const BotCommandScopeChatMember::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseBotCommandScope(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- appendToJson(result, "chat_id", object->chatId);
- appendToJson(result, "user_id", object->userId);
- // The last comma will be erased by parseBotCommandScope().
- return result;
-}
-
-MenuButton::Ptr TgTypeParser::parseJsonAndGetMenuButton(const boost::property_tree::ptree& data) const {
- std::string type = data.get<std::string>("type", "");
- MenuButton::Ptr result;
-
- if (type == MenuButtonCommands::TYPE) {
- result = std::static_pointer_cast<MenuButton>(parseJsonAndGetMenuButtonCommands(data));
- } else if (type == MenuButtonWebApp::TYPE) {
- result = std::static_pointer_cast<MenuButton>(parseJsonAndGetMenuButtonWebApp(data));
- } else if (type == MenuButtonDefault::TYPE) {
- result = std::static_pointer_cast<MenuButton>(parseJsonAndGetMenuButtonDefault(data));
- } else {
- result = std::make_shared<MenuButton>();
- }
-
- result->type = type;
-
+ShippingAddress::Ptr TgTypeParser::parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const {
+ ShippingAddress::Ptr result;
+ result->countryCode = data.get<std::string>("country_code");
+ result->state = data.get<std::string>("state", "");
+ result->city = data.get<std::string>("city");
+ result->streetLine1 = data.get<std::string>("street_line1");
+ result->streetLine2 = data.get<std::string>("street_line2");
+ result->postCode = data.get<std::string>("post_code");
return result;
}
-std::string TgTypeParser::parseMenuButton(const MenuButton::Ptr& object) const {
- if (!object) {
- return "";
- }
+std::string TgTypeParser::parseShippingAddress(const ShippingAddress::Ptr& object) const {
std::string result;
result += '{';
- appendToJson(result, "type", object->type);
-
- if (object->type == MenuButtonCommands::TYPE) {
- result += parseMenuButtonCommands(std::static_pointer_cast<MenuButtonCommands>(object));
- } else if (object->type == MenuButtonWebApp::TYPE) {
- result += parseMenuButtonWebApp(std::static_pointer_cast<MenuButtonWebApp>(object));
- } else if (object->type == MenuButtonDefault::TYPE) {
- result += parseMenuButtonDefault(std::static_pointer_cast<MenuButtonDefault>(object));
+ appendToJson(result, "country_code", object->countryCode);
+ if (!object->state.empty()) {
+ appendToJson(result, "state", object->state);
}
-
+ appendToJson(result, "city", object->city);
+ appendToJson(result, "street_line1", object->streetLine1);
+ appendToJson(result, "street_line2", object->streetLine2);
+ appendToJson(result, "post_code", object->postCode);
removeLastComma(result);
result += '}';
return result;
}
-MenuButtonCommands::Ptr TgTypeParser::parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetMenuButton().
- auto result(std::make_shared<MenuButtonCommands>());
- return result;
-}
-
-std::string TgTypeParser::parseMenuButtonCommands(const MenuButtonCommands::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseMenuButton(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- // The last comma will be erased by parseMenuButton().
- return result;
-}
-
-MenuButtonWebApp::Ptr TgTypeParser::parseJsonAndGetMenuButtonWebApp(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetMenuButton().
- auto result(std::make_shared<MenuButtonWebApp>());
- result->text = data.get<std::string>("text", "");
- result->webApp = tryParseJson<WebAppInfo>(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app");
- return result;
-}
-
-std::string TgTypeParser::parseMenuButtonWebApp(const MenuButtonWebApp::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseMenuButton(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- appendToJson(result, "text", object->text);
- appendToJson(result, "web_app", parseWebAppInfo(object->webApp));
- // The last comma will be erased by parseMenuButton().
- return result;
-}
-
-MenuButtonDefault::Ptr TgTypeParser::parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& data) const {
- // NOTE: This function will be called by parseJsonAndGetMenuButton().
- auto result(std::make_shared<MenuButtonDefault>());
- return result;
-}
-
-std::string TgTypeParser::parseMenuButtonDefault(const MenuButtonDefault::Ptr& object) const {
- if (!object) {
- return "";
- }
- // This function will be called by parseMenuButton(), so I don't add
- // curly brackets to the result std::string.
- std::string result;
- // The last comma will be erased by parseMenuButton().
- return result;
-}
-
OrderInfo::Ptr TgTypeParser::parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<OrderInfo>());
result->name = data.get<std::string>("name", "");
@@ -3558,72 +3469,47 @@ std::string TgTypeParser::parseOrderInfo(const OrderInfo::Ptr& object) const {
return result;
}
-PreCheckoutQuery::Ptr TgTypeParser::parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<PreCheckoutQuery>());
+ShippingOption::Ptr TgTypeParser::parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ShippingOption>());
result->id = data.get<std::string>("id");
- result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user");
- result->currency = data.get<std::string>("currency");
- result->totalAmount = data.get<std::int32_t>("total_amount");
+ result->title = data.get<std::string>("title");
+ result->prices = parseJsonAndGetArray<LabeledPrice>(&TgTypeParser::parseJsonAndGetLabeledPrice, data, "prices");
return result;
}
-std::string TgTypeParser::parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const {
+std::string TgTypeParser::parseShippingOption(const ShippingOption::Ptr& object) const {
std::string result;
result += '{';
appendToJson(result, "id", object->id);
- result += R"("user":)";
- result += parseUser(object->from);
- result += ",";
- appendToJson(result, "currency", object->currency);
- appendToJson(result, "total_amount", object->totalAmount);
- removeLastComma(result);
- result += '}';
- return result;
-}
-
-ShippingAddress::Ptr TgTypeParser::parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const {
- ShippingAddress::Ptr result;
- result->countryCode = data.get<std::string>("country_code");
- result->state = data.get<std::string>("state", "");
- result->city = data.get<std::string>("city");
- result->streetLine1 = data.get<std::string>("street_line1");
- result->streetLine2 = data.get<std::string>("street_line2");
- result->postCode = data.get<std::string>("post_code");
- return result;
-}
-
-std::string TgTypeParser::parseShippingAddress(const ShippingAddress::Ptr& object) const {
- std::string result;
- result += '{';
- appendToJson(result, "country_code", object->countryCode);
- if (!object->state.empty()) {
- appendToJson(result, "state", object->state);
- }
- appendToJson(result, "city", object->city);
- appendToJson(result, "street_line1", object->streetLine1);
- appendToJson(result, "street_line2", object->streetLine2);
- appendToJson(result, "post_code", object->postCode);
+ appendToJson(result, "title", object->title);
removeLastComma(result);
+ result += R"("prices":)";
+ result += parseArray(&TgTypeParser::parseLabeledPrice, object->prices);
result += '}';
return result;
}
-ShippingOption::Ptr TgTypeParser::parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<ShippingOption>());
- result->id = data.get<std::string>("id");
- result->title = data.get<std::string>("title");
- result->prices = parseJsonAndGetArray<LabeledPrice>(&TgTypeParser::parseJsonAndGetLabeledPrice, data, "prices");
+SuccessfulPayment::Ptr TgTypeParser::parseJsonAndGetSuccessfulPayment(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<SuccessfulPayment>());
+ result->currency = data.get<std::string>("currency");
+ result->totalAmount = data.get<std::int32_t>("total_amount");
+ result->invoicePayload = data.get<std::string>("invoice_payload");
+ result->shippingOptionId = data.get<std::string>("shipping_option_id");
+ result->orderInfo = tryParseJson(&TgTypeParser::parseJsonAndGetOrderInfo, data, "order_info");
return result;
}
-std::string TgTypeParser::parseShippingOption(const ShippingOption::Ptr& object) const {
+std::string TgTypeParser::parseSuccessfulPayment(const SuccessfulPayment::Ptr& object) const {
std::string result;
result += '{';
- appendToJson(result, "id", object->id);
- appendToJson(result, "title", object->title);
+ appendToJson(result, "currency", object->currency);
+ appendToJson(result, "total_amount", object->totalAmount);
+ appendToJson(result, "invoice_payload", object->invoicePayload);
+ appendToJson(result, "shipping_option_id", object->shippingOptionId);
+ result += R"("order_info":)";
+ result += parseOrderInfo(object->orderInfo);
+ result += ",";
removeLastComma(result);
- result += R"("prices":)";
- result += parseArray(&TgTypeParser::parseLabeledPrice, object->prices);
result += '}';
return result;
}
@@ -3653,26 +3539,24 @@ std::string TgTypeParser::parseShippingQuery(const ShippingQuery::Ptr& object) c
return result;
}
-SuccessfulPayment::Ptr TgTypeParser::parseJsonAndGetSuccessfulPayment(const boost::property_tree::ptree& data) const {
- auto result(std::make_shared<SuccessfulPayment>());
+PreCheckoutQuery::Ptr TgTypeParser::parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<PreCheckoutQuery>());
+ result->id = data.get<std::string>("id");
+ result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user");
result->currency = data.get<std::string>("currency");
result->totalAmount = data.get<std::int32_t>("total_amount");
- result->invoicePayload = data.get<std::string>("invoice_payload");
- result->shippingOptionId = data.get<std::string>("shipping_option_id");
- result->orderInfo = tryParseJson(&TgTypeParser::parseJsonAndGetOrderInfo, data, "order_info");
return result;
}
-std::string TgTypeParser::parseSuccessfulPayment(const SuccessfulPayment::Ptr& object) const {
+std::string TgTypeParser::parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const {
std::string result;
result += '{';
+ appendToJson(result, "id", object->id);
+ result += R"("user":)";
+ result += parseUser(object->from);
+ result += ",";
appendToJson(result, "currency", object->currency);
appendToJson(result, "total_amount", object->totalAmount);
- appendToJson(result, "invoice_payload", object->invoicePayload);
- appendToJson(result, "shipping_option_id", object->shippingOptionId);
- result += R"("order_info":)";
- result += parseOrderInfo(object->orderInfo);
- result += ",";
removeLastComma(result);
result += '}';
return result;
@@ -4033,6 +3917,99 @@ std::string TgTypeParser::parsePassportElementErrorUnspecified(const PassportEle
return result;
}
+Game::Ptr TgTypeParser::parseJsonAndGetGame(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<Game>());
+ result->title = data.get("title", "");
+ result->description = data.get("description", "");
+ result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo");
+ result->text = data.get("text", "");
+ result->textEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "text_entities");
+ result->animation = tryParseJson<Animation>(&TgTypeParser::parseJsonAndGetAnimation, data, "animation");
+ return result;
+}
+
+std::string TgTypeParser::parseGame(const Game::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "title", object->title);
+ appendToJson(result, "description", object->description);
+ appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo));
+ appendToJson(result, "text", object->text);
+ appendToJson(result, "text_entities", parseArray(&TgTypeParser::parseMessageEntity, object->textEntities));
+ appendToJson(result, "animation", parseAnimation(object->animation));
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+CallbackGame::Ptr TgTypeParser::parseJsonAndGetCallbackGame(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<CallbackGame>());
+ return result;
+}
+
+std::string TgTypeParser::parseCallbackGame(const CallbackGame::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ result += '}';
+ return result;
+}
+
+GameHighScore::Ptr TgTypeParser::parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<GameHighScore>());
+ result->position = data.get("position", "");
+ result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user");
+ result->score = data.get<std::int32_t>("score", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseGameHighScore(const GameHighScore::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "position", object->position);
+ appendToJson(result, "user", parseUser(object->user));
+ appendToJson(result, "score", object->score);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const {
+ if (data.find("force_reply") != data.not_found()) {
+ return std::static_pointer_cast<GenericReply>(parseJsonAndGetForceReply(data));
+ } else if (data.find("remove_keyboard") != data.not_found()) {
+ return std::static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardRemove(data));
+ } else if (data.find("keyboard") != data.not_found()) {
+ return std::static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardMarkup(data));
+ } else if (data.find("inline_keyboard") != data.not_found()) {
+ return std::static_pointer_cast<GenericReply>(parseJsonAndGetInlineKeyboardMarkup(data));
+ }
+ return std::make_shared<GenericReply>();
+}
+
+std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ if (std::dynamic_pointer_cast<ForceReply>(object) != nullptr) {
+ return parseForceReply(std::static_pointer_cast<ForceReply>(object));
+ } else if (std::dynamic_pointer_cast<ReplyKeyboardRemove>(object) != nullptr) {
+ return parseReplyKeyboardRemove(std::static_pointer_cast<ReplyKeyboardRemove>(object));
+ } else if (std::dynamic_pointer_cast<ReplyKeyboardMarkup>(object) != nullptr) {
+ return parseReplyKeyboardMarkup(std::static_pointer_cast<ReplyKeyboardMarkup>(object));
+ } else if (std::dynamic_pointer_cast<InlineKeyboardMarkup>(object) != nullptr) {
+ return parseInlineKeyboardMarkup(std::static_pointer_cast<InlineKeyboardMarkup>(object));
+ }
+ return "";
+}
void TgTypeParser::appendToJson(std::string& json, const std::string& varName, const std::string& value) const {
if (value.empty()) {
diff --git a/src/net/TgLongPoll.cpp b/src/net/TgLongPoll.cpp
index a7b4fcb..6a224cb 100644
--- a/src/net/TgLongPoll.cpp
+++ b/src/net/TgLongPoll.cpp
@@ -21,13 +21,19 @@ TgLongPoll::TgLongPoll(const Bot& bot, std::int32_t limit, std::int32_t timeout,
}
void TgLongPoll::start() {
- std::vector<Update::Ptr> updates = _api->getUpdates(_lastUpdateId, _limit, _timeout, _allowUpdates);
+ // get all unconfirmed updates
+ std::vector<Update::Ptr> updates = _api->getUpdates(0, _limit, _timeout, _allowUpdates);
+
+ // handle updates
for (Update::Ptr& item : updates) {
if (item->updateId >= _lastUpdateId) {
_lastUpdateId = item->updateId + 1;
}
_eventHandler->handleUpdate(item);
}
+
+ // confirm handled updates
+ _api->getUpdates(_lastUpdateId, _limit, _timeout, _allowUpdates);
}
}
diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp
index 653047c..3e5e6c4 100644
--- a/src/tools/StringTools.cpp
+++ b/src/tools/StringTools.cpp
@@ -101,4 +101,22 @@ string urlDecode(const string& value) {
return result;
}
+std::string escapeJsonString(const std::string& value) {
+ string result;
+
+ for (const char& c : value) {
+ switch (c) {
+ case '"':
+ case '\\':
+ case '/':
+ result += '\\';
+ break;
+ }
+
+ result += c;
+ }
+
+ return result;
+}
+
}
diff --git a/tools/docker-run-sample b/tools/docker-run-sample
index e7ac6ba..e7ac6ba 100755..100644
--- a/tools/docker-run-sample
+++ b/tools/docker-run-sample
diff --git a/tools/docker-run-sample-webhook b/tools/docker-run-sample-webhook
index 386b0c6..386b0c6 100755..100644
--- a/tools/docker-run-sample-webhook
+++ b/tools/docker-run-sample-webhook
diff --git a/tools/docker-test b/tools/docker-test
index 5451ff1..5451ff1 100755..100644
--- a/tools/docker-test
+++ b/tools/docker-test
diff --git a/tools/docs-generate b/tools/docs-generate
index 1453346..1453346 100755..100644
--- a/tools/docs-generate
+++ b/tools/docs-generate
diff --git a/tools/docs-push-gh-pages b/tools/docs-push-gh-pages
index 4d07dbd..4d07dbd 100755..100644
--- a/tools/docs-push-gh-pages
+++ b/tools/docs-push-gh-pages
diff --git a/tools/list-includes b/tools/list-includes
index 5e04c1a..5e04c1a 100755..100644
--- a/tools/list-includes
+++ b/tools/list-includes
diff --git a/tools/list-srcs b/tools/list-srcs
index ed2a199..ed2a199 100755..100644
--- a/tools/list-srcs
+++ b/tools/list-srcs