diff options
author | Oleg Morozenkov <m@oleg.rocks> | 2019-12-05 01:06:02 +0300 |
---|---|---|
committer | Oleg Morozenkov <m@oleg.rocks> | 2019-12-05 01:06:02 +0300 |
commit | 2b5baa24597778d8e9f5d93c30a6f6440ef90971 (patch) | |
tree | 589202ffbaecb0ff2176575688e30cf18b317a61 | |
parent | e1031f20f9139a554c3e4cf70585ae0dcea1bcda (diff) | |
parent | 76f36598570a13862471175cbfdbfb9dec4139d2 (diff) |
Merge branch 'master' into nitanmarcel/api_update_pr
-rw-r--r-- | .travis.yml | 88 | ||||
-rwxr-xr-x | .travis/install.sh | 24 | ||||
-rwxr-xr-x | .travis/run.sh | 13 | ||||
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | README.md | 20 | ||||
-rw-r--r-- | appveyor.yml | 80 | ||||
-rw-r--r-- | build.py | 17 | ||||
-rw-r--r-- | conanfile.py | 61 | ||||
-rw-r--r-- | include/tgbot/Api.h | 5 | ||||
-rw-r--r-- | include/tgbot/TgTypeParser.h | 613 | ||||
-rw-r--r-- | samples/echobot-conan/CMakeLists.txt | 9 | ||||
-rw-r--r-- | samples/echobot-conan/conanfile.py | 24 | ||||
-rw-r--r-- | samples/echobot-conan/example.cpp | 20 | ||||
-rw-r--r-- | src/Api.cpp | 7 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 3 | ||||
-rw-r--r-- | src/net/CurlHttpClient.cpp | 32 |
16 files changed, 338 insertions, 685 deletions
diff --git a/.travis.yml b/.travis.yml index f4e6c94..37629fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,84 +1,10 @@ -linux: &linux - os: linux - dist: xenial - language: python - python: "3.7" - services: - - docker -osx: &osx - os: osx - language: generic +sudo: required -stages: - - unittest - - conan-linux - - conan-osx - -jobs: - include: - - <<: *linux - stage: unittest - name: unittest - sudo: required - script: - - docker build -t reo7sp/tgbot-cpp -f Dockerfile . - - docker build -t reo7sp/tgbot-cpp-test -f Dockerfile_test . - - docker run --rm reo7sp/tgbot-cpp-test - - - <<: *linux - stage: conan-linux - env: CONAN_GCC_VERSIONS=4.9 CONAN_DOCKER_IMAGE=conanio/gcc49 - - <<: *linux - stage: conan-linux - env: CONAN_GCC_VERSIONS=5 CONAN_DOCKER_IMAGE=conanio/gcc5 - - <<: *linux - stage: conan-linux - env: CONAN_GCC_VERSIONS=6 CONAN_DOCKER_IMAGE=conanio/gcc6 - - <<: *linux - stage: conan-linux - env: CONAN_GCC_VERSIONS=7 CONAN_DOCKER_IMAGE=conanio/gcc7 - - <<: *linux - stage: conan-linux - env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8 - - - <<: *linux - stage: conan-linux - env: CONAN_CLANG_VERSIONS=4.0 CONAN_DOCKER_IMAGE=conanio/clang40 - - <<: *linux - stage: conan-linux - env: CONAN_CLANG_VERSIONS=5.0 CONAN_DOCKER_IMAGE=conanio/clang50 - - <<: *linux - stage: conan-linux - env: CONAN_CLANG_VERSIONS=6.0 CONAN_DOCKER_IMAGE=conanio/clang60 - - <<: *linux - stage: conan-linux - env: CONAN_CLANG_VERSIONS=7.0 CONAN_DOCKER_IMAGE=conanio/clang7 CONAN_BUILD_POLICY=missing - - - <<: *osx - stage: conan-osx - osx_image: xcode7.3 - env: CONAN_APPLE_CLANG_VERSIONS=7.3 CONAN_BUILD_POLICY=missing - - <<: *osx - stage: conan-osx - osx_image: xcode8.3 - env: CONAN_APPLE_CLANG_VERSIONS=8.1 CONAN_BUILD_POLICY=missing - - <<: *osx - stage: conan-osx - osx_image: xcode9 - env: CONAN_APPLE_CLANG_VERSIONS=9.0 - - <<: *osx - stage: conan-osx - osx_image: xcode9.4 - env: CONAN_APPLE_CLANG_VERSIONS=9.1 - - <<: *osx - stage: conan-osx - osx_image: xcode10 - env: CONAN_APPLE_CLANG_VERSIONS=10.0 - -install: - - chmod +x .travis/install.sh - - ./.travis/install.sh +services: + - docker script: - - chmod +x .travis/run.sh - - ./.travis/run.sh + - docker build -t reo7sp/tgbot-cpp -f Dockerfile . + - docker build -t reo7sp/tgbot-cpp-test -f Dockerfile_test . + - docker run --rm reo7sp/tgbot-cpp-test + diff --git a/.travis/install.sh b/.travis/install.sh deleted file mode 100755 index 657ecc1..0000000 --- a/.travis/install.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -e -set -x - -if [[ "$(uname -s)" == 'Darwin' ]]; then - brew update || brew update - brew outdated pyenv || brew upgrade pyenv - brew install pyenv-virtualenv - brew install cmake || true - - if which pyenv > /dev/null; then - eval "$(pyenv init -)" - fi - - pyenv install 3.7.1 - pyenv virtualenv 3.7.1 conan - pyenv rehash - pyenv activate conan -fi - -pip install conan_package_tools -pip install conan -conan user diff --git a/.travis/run.sh b/.travis/run.sh deleted file mode 100755 index 0a3488e..0000000 --- a/.travis/run.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -e -set -x - -if [[ "$(uname -s)" == 'Darwin' ]]; then - if which pyenv > /dev/null; then - eval "$(pyenv init -)" - fi - pyenv activate conan -fi - -python build.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 908cf69..8f8bbcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,6 @@ cmake_minimum_required(VERSION 2.8.4) project(TgBot) -if (${CONAN_EXPORTED}) - include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - conan_basic_setup() -endif() - set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # options @@ -47,7 +42,7 @@ find_package(OpenSSL REQUIRED) include_directories(${OPENSSL_INCLUDE_DIR}) ## curl -find_package(CURL) +find_package(CURL 7.56.0) if (CURL_FOUND) include_directories(${CURL_INCLUDE_DIRS}) add_definitions(-DHAVE_CURL) @@ -1,16 +1,8 @@ # tgbot-cpp [![Travis build Status](https://travis-ci.org/reo7sp/tgbot-cpp.svg?branch=master)](https://travis-ci.org/reo7sp/tgbot-cpp) -[![Appveyor build status](https://ci.appveyor.com/api/projects/status/tncys4p1flm8817m?svg=true)](https://ci.appveyor.com/project/reo7sp/tgbot-cpp) -[![Docker Hub pulls](https://img.shields.io/docker/pulls/reo7sp/tgbot-cpp.svg)](https://hub.docker.com/r/reo7sp/tgbot-cpp/) +[![GitHub contributors](https://img.shields.io/github/contributors/reo7sp/tgbot-cpp.svg)](https://github.com/reo7sp/tgbot-cpp/graphs/contributors) [![Open documentation](https://img.shields.io/badge/open-documentation-orange.svg)](http://reo7sp.github.io/tgbot-cpp) -[![Donate using PayPal](https://img.shields.io/badge/donate-PayPal-orange.svg)](https://paypal.me/reo7sp) - ---- - -[![GitHub contributors](https://img.shields.io/github/contributors/reo7sp/tgbot-cpp.svg)](https://github.com/reo7sp/tgbot-cpp/graphs/contributors) 🚀🚀🚀 thanks for the contributing! - ---- C++ library for Telegram bot API. @@ -85,12 +77,6 @@ Or you can treat this repository as a submodule of your project, for example, se ### Docker 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/). -### Conan -You can use Conan C/C++ Package Manager. Follow [Conan instructions](https://docs.conan.io/en/latest/getting_started.html) and use [the template](https://github.com/reo7sp/tgbot-cpp/tree/master/samples/echobot-conan). - -### Arch Linux -A PKGBUILD compiles shared library with header files is hosted on [Arch Linux User Repository](https://aur.archlinux.org/packages/libtgbot-cpp-git/). - ## Bot compilation @@ -119,9 +105,5 @@ add_definitions(-DTGBOT_CHANGE_READ_BUFFER_SIZE) # Read Buffer Size Expansion ``` -## Feedback -Feel free to [create new issues on GitHub](https://github.com/reo7sp/tgbot-cpp/issues) or [contact me on Telegram](https://t.me/reo7sp). - - ## Licence [The MIT License](http://opensource.org/licenses/MIT). diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 4d16413..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,80 +0,0 @@ -build: false - - -environment: - PYTHON: "C:\\Python37" - VS150COMNTOOLS: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\Tools\\" - - matrix: - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - CONAN_VISUAL_VERSIONS: 12 - CONAN_ARCHS: x86 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MT - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - CONAN_VISUAL_VERSIONS: 12 - CONAN_ARCHS: x86_64 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MT - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - CONAN_VISUAL_VERSIONS: 12 - CONAN_ARCHS: x86 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MD - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - CONAN_VISUAL_VERSIONS: 12 - CONAN_ARCHS: x86_64 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MD - - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - CONAN_VISUAL_VERSIONS: 14 - CONAN_ARCHS: x86 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MT - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - CONAN_VISUAL_VERSIONS: 14 - CONAN_ARCHS: x86_64 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MT - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - CONAN_VISUAL_VERSIONS: 14 - CONAN_ARCHS: x86 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MD - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - CONAN_VISUAL_VERSIONS: 14 - CONAN_ARCHS: x86_64 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MD - - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CONAN_VISUAL_VERSIONS: 15 - CONAN_ARCHS: x86 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MT - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CONAN_VISUAL_VERSIONS: 15 - CONAN_ARCHS: x86_64 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MT - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CONAN_VISUAL_VERSIONS: 15 - CONAN_ARCHS: x86 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MD - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CONAN_VISUAL_VERSIONS: 15 - CONAN_ARCHS: x86_64 - CONAN_BUILD_TYPES: Release - CONAN_VISUAL_RUNTIMES: MD - -install: - - set PATH=%PATH%;%PYTHON%/Scripts/ - - pip.exe install conan --upgrade - - pip.exe install conan_package_tools - - conan user # It creates the conan data directory - -test_script: - - python build.py - diff --git a/build.py b/build.py deleted file mode 100644 index 18a873a..0000000 --- a/build.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -from cpt.packager import ConanMultiPackager - - -if __name__ == "__main__": - builder = ConanMultiPackager( - username="reo7sp", - login_username="reo7sp", - upload="https://api.bintray.com/conan/reo7sp/tgbot-cpp", - channel="ci", - stable_branch_pattern="release/*", - upload_only_when_stable=True, # Will only upload when the branch matches "release/*" - docker_32_images=True - ) - builder.add_common_builds() - builder.run() diff --git a/conanfile.py b/conanfile.py deleted file mode 100644 index 96c3d22..0000000 --- a/conanfile.py +++ /dev/null @@ -1,61 +0,0 @@ - -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import os - -from conans import ConanFile, CMake, tools - - -class TgbotConan(ConanFile): - name = "tgbot_cpp" - version = "b35438d" - description = "C++ library for Telegram bot API" - url = "https://github.com/reo7sp/tgbot-cpp" - homepage = "http://reo7sp.github.io/tgbot-cpp" - license = "MIT" - - exports_sources = ["LICENSE", ] - scm = {"type": "git", - "url": "auto", - "revision": "auto"} - - generators = "cmake" - settings = "os", "arch", "compiler", "build_type" - options = {"fPIC": [True, False], - "shared": [True, False]} - default_options = {"fPIC": True, "shared": True} - - requires = ( - "boost/1.68.0@conan/stable", - "OpenSSL/1.0.2q@conan/stable", - "libcurl/7.61.1@bincrafters/stable" - ) - - def source(self): - boost_version = self.deps_cpp_info['boost'].version - tools.replace_in_file(os.path.join(self.source_folder, "CMakeLists.txt"), - "find_package(Boost 1.59.0 COMPONENTS system REQUIRED)", - "find_package(Boost {} COMPONENTS system REQUIRED)".format(boost_version)) - - def config_options(self): - if self.settings.os == "Windows": - del self.options.fPIC - - def _configure_cmake(self): - cmake = CMake(self) - cmake.definitions["ENABLE_TESTS"] = False - cmake.configure() - return cmake - - def build(self): - cmake = self._configure_cmake() - cmake.build() - - def package(self): - self.copy(pattern="LICENSE", dst="licenses") - cmake = self._configure_cmake() - cmake.install() - - def package_info(self): - self.cpp_info.libs = ['TgBot'] diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 4ce8dd7..02e68a5 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -251,13 +251,12 @@ public: * @brief Use this method to add a new sticker to a set created by the bot. * @param userId User identifier of created sticker set owner. * @param name Sticker set name. - * @param title Sticker set title, 1-64 characters. * @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. * @param emojis One or more emoji corresponding to the sticker. * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces. * @return Returns True on success. */ - bool addStickerToSet(int32_t userId, const std::string& name, const std::string& title, + bool addStickerToSet(int32_t userId, const std::string& name, boost::variant<InputFile::Ptr, std::string> pngSticker, const std::string& emojis, MaskPosition::Ptr maskPosition = nullptr) const; /** @@ -273,7 +272,7 @@ public: * @param stickers File identifier of the sticker. * @return Returns True on success. */ - bool deleteStickerPositionInSet(const std::string& sticker) const; + bool deleteStickerFromSet(const std::string& sticker) const; /** * @brief Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index aa0cd10..6cda5a7 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -109,405 +109,406 @@ namespace TgBot { - class TgTypeParser { +class TgTypeParser { - public: - template<typename T> - using JsonToTgTypeFunc = std::shared_ptr<T> (TgTypeParser::*)(const boost::property_tree::ptree&) const; +public: + template<typename T> + using JsonToTgTypeFunc = std::shared_ptr<T> (TgTypeParser::*)(const boost::property_tree::ptree&) const; - template<typename T> - using TgTypeToJsonFunc = std::string (TgTypeParser::*)(const std::shared_ptr<T>&) const; + 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; + Chat::Ptr parseJsonAndGetChat(const boost::property_tree::ptree& data) const; + std::string parseChat(const Chat::Ptr& object) const; - User::Ptr parseJsonAndGetUser(const boost::property_tree::ptree& data) const; - std::string parseUser(const User::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; + MessageEntity::Ptr parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const; + std::string parseMessageEntity(const MessageEntity::Ptr& object) const; - Message::Ptr parseJsonAndGetMessage(const boost::property_tree::ptree& data) const; - std::string parseMessage(const Message::Ptr& object) const; + Message::Ptr parseJsonAndGetMessage(const boost::property_tree::ptree& data) const; + std::string parseMessage(const Message::Ptr& object) const; - PhotoSize::Ptr parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const; - std::string parsePhotoSize(const PhotoSize::Ptr& object) const; + PhotoSize::Ptr parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const; + std::string parsePhotoSize(const PhotoSize::Ptr& object) const; - Audio::Ptr parseJsonAndGetAudio(const boost::property_tree::ptree& data) const; - std::string parseAudio(const Audio::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; + 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; + Sticker::Ptr parseJsonAndGetSticker(const boost::property_tree::ptree& data) const; + std::string parseSticker(const Sticker::Ptr& object) const; - StickerSet::Ptr parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const; - std::string parseStickerSet(const StickerSet::Ptr& object) const; + StickerSet::Ptr parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const; + std::string parseStickerSet(const StickerSet::Ptr& object) const; - MaskPosition::Ptr parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const; - std::string parseMaskPosition(const MaskPosition::Ptr& object) const; + MaskPosition::Ptr parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const; + std::string parseMaskPosition(const MaskPosition::Ptr& object) const; - Poll::Ptr parseJsonAndGetPoll(const boost::property_tree::ptree& data) const; - std::string parsePoll(const Poll::Ptr& object) const; + Poll::Ptr parseJsonAndGetPoll(const boost::property_tree::ptree& data) const; + std::string parsePoll(const Poll::Ptr& object) const; - PollOption::Ptr parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const; - std::string parsePollOption(const PollOption::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; + ChatPermissions::Ptr parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const; + std::string parseChatPermissions(const ChatPermissions::Ptr& object) const; - Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const; - std::string parseVideo(const Video::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; + 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; + 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; + Game::Ptr parseJsonAndGetGame(const boost::property_tree::ptree& data) const; + std::string parseGame(const Game::Ptr& object) const; - GameHighScore::Ptr parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const; - std::string parseGameHighScore(const GameHighScore::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; + Animation::Ptr parseJsonAndGetAnimation(const boost::property_tree::ptree& data) const; + std::string parseAnimation(const Animation::Ptr& object) const; - Contact::Ptr parseJsonAndGetContact(const boost::property_tree::ptree& data) const; - std::string parseContact(const Contact::Ptr& object) const; + Contact::Ptr parseJsonAndGetContact(const boost::property_tree::ptree& data) const; + std::string parseContact(const Contact::Ptr& object) const; - Location::Ptr parseJsonAndGetLocation(const boost::property_tree::ptree& data) const; - std::string parseLocation(const Location::Ptr& object) const; + Location::Ptr parseJsonAndGetLocation(const boost::property_tree::ptree& data) const; + std::string parseLocation(const Location::Ptr& object) const; - Update::Ptr parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const; - std::string parseUpdate(const Update::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; + 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; + InputMedia::Ptr parseJsonAndGetInputMedia(const boost::property_tree::ptree& data) const; + std::string parseInputMedia(const InputMedia::Ptr& object) const; - File::Ptr parseJsonAndGetFile(const boost::property_tree::ptree& data) const; - std::string parseFile(const File::Ptr& object) const; + File::Ptr parseJsonAndGetFile(const boost::property_tree::ptree& data) const; + std::string parseFile(const File::Ptr& object) const; - ReplyKeyboardMarkup::Ptr parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Ptr& object) const; + ReplyKeyboardMarkup::Ptr parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const; + std::string parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Ptr& object) const; - KeyboardButton::Ptr parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButton(const KeyboardButton::Ptr& object) const; + KeyboardButton::Ptr parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const; + std::string parseKeyboardButton(const KeyboardButton::Ptr& object) const; - ReplyKeyboardRemove::Ptr parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const; + ReplyKeyboardRemove::Ptr parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const; + std::string parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const; - ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const; - std::string parseForceReply(const ForceReply::Ptr& object) const; + ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const; + std::string parseForceReply(const ForceReply::Ptr& object) const; - ChatMember::Ptr parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const; - std::string parseChatMember(const ChatMember::Ptr& object) const; + ChatMember::Ptr parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const; + std::string parseChatMember(const ChatMember::Ptr& object) const; - ChatPhoto::Ptr parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const; - std::string parseChatPhoto(const ChatPhoto::Ptr& object) const; + ChatPhoto::Ptr parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const; + std::string parseChatPhoto(const ChatPhoto::Ptr& object) const; - ResponseParameters::Ptr parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const; - std::string parseResponseParameters(const ResponseParameters::Ptr& object) const; + 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; + GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const; + std::string parseGenericReply(const GenericReply::Ptr& object) const; - InlineQuery::Ptr parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const; - std::string parseInlineQuery(const InlineQuery::Ptr& object) const; + InlineQuery::Ptr parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const; + std::string parseInlineQuery(const InlineQuery::Ptr& object) const; - InlineQueryResult::Ptr parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResult(const InlineQueryResult::Ptr& object) const; + InlineQueryResult::Ptr parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResult(const InlineQueryResult::Ptr& object) const; - InlineQueryResultCachedAudio::Ptr parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const; + InlineQueryResultCachedAudio::Ptr parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const; - InlineQueryResultCachedDocument::Ptr parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const; + InlineQueryResultCachedDocument::Ptr parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const; - InlineQueryResultCachedGif::Ptr parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const; + InlineQueryResultCachedGif::Ptr parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const; - InlineQueryResultCachedMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const; + InlineQueryResultCachedMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const; - InlineQueryResultCachedPhoto::Ptr parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const; + InlineQueryResultCachedPhoto::Ptr parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const; - InlineQueryResultCachedSticker::Ptr parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const; + InlineQueryResultCachedSticker::Ptr parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const; - InlineQueryResultCachedVideo::Ptr parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const; + InlineQueryResultCachedVideo::Ptr parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const; - InlineQueryResultCachedVoice::Ptr parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const; + InlineQueryResultCachedVoice::Ptr parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const; - InlineQueryResultArticle::Ptr parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const; + InlineQueryResultArticle::Ptr parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const; - InlineQueryResultAudio::Ptr parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultAudio(const InlineQueryResultAudio::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; + 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; + InlineQueryResultGame::Ptr parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const; - InlineQueryResultDocument::Ptr parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const; + InlineQueryResultDocument::Ptr parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const; - InlineQueryResultLocation::Ptr parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const; + InlineQueryResultLocation::Ptr parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const; - InlineQueryResultVenue::Ptr parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const; + 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; + 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; + 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; + 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; + 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; + InlineQueryResultVideo::Ptr parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const; - ChosenInlineResult::Ptr parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const; - std::string parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const; + ChosenInlineResult::Ptr parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const; + std::string parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const; - CallbackQuery::Ptr parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const; - std::string parseCallbackQuery(const CallbackQuery::Ptr& object) const; + CallbackQuery::Ptr parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const; + std::string parseCallbackQuery(const CallbackQuery::Ptr& object) const; - InlineKeyboardMarkup::Ptr parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const; - std::string parseInlineKeyboardMarkup(const InlineKeyboardMarkup::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; + InlineKeyboardButton::Ptr parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const; + std::string parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const; - WebhookInfo::Ptr parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const; - std::string parseWebhookInfo(const WebhookInfo::Ptr& object) const; + WebhookInfo::Ptr parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const; + std::string parseWebhookInfo(const WebhookInfo::Ptr& object) const; - InputMessageContent::Ptr parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputMessageContent(const InputMessageContent::Ptr& object) const; + InputMessageContent::Ptr parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputMessageContent(const InputMessageContent::Ptr& object) const; - InputTextMessageContent::Ptr parseJsonAndGetInputTextMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const; + InputTextMessageContent::Ptr parseJsonAndGetInputTextMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const; - InputLocationMessageContent::Ptr parseJsonAndGetInputLocationMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const; + InputLocationMessageContent::Ptr parseJsonAndGetInputLocationMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const; - InputVenueMessageContent::Ptr parseJsonAndGetInputVenueMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const; + InputVenueMessageContent::Ptr parseJsonAndGetInputVenueMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const; - InputContactMessageContent::Ptr parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const; + InputContactMessageContent::Ptr parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const; - Invoice::Ptr parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const; - std::string parseInvoice(const Invoice::Ptr& object) const; + Invoice::Ptr parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const; + std::string parseInvoice(const Invoice::Ptr& object) const; - LabeledPrice::Ptr parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const; - std::string parseLabeledPrice(const LabeledPrice::Ptr& object) const; + LabeledPrice::Ptr parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const; + std::string parseLabeledPrice(const LabeledPrice::Ptr& object) const; - OrderInfo::Ptr parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const; - std::string parseOrderInfo(const OrderInfo::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; + 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; + 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; + ShippingOption::Ptr parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const; + std::string parseShippingOption(const ShippingOption::Ptr& object) const; - ShippingQuery::Ptr parseJsonAndGetShippingQuery(const boost::property_tree::ptree& data) const; - std::string parseShippingQuery(const ShippingQuery::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; + SuccessfulPayment::Ptr parseJsonAndGetSuccessfulPayment(const boost::property_tree::ptree& data) const; + std::string parseSuccessfulPayment(const SuccessfulPayment::Ptr& object) const; - inline boost::property_tree::ptree parseJson(const std::string& json) const { - boost::property_tree::ptree tree; - std::istringstream input(json); - boost::property_tree::read_json(input, tree); - return tree; - } + inline boost::property_tree::ptree parseJson(const std::string& json) const { + boost::property_tree::ptree tree; + std::istringstream input(json); + boost::property_tree::read_json(input, tree); + return tree; + } - template<typename T> - std::shared_ptr<T> tryParseJson(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return std::shared_ptr<T>(); - } - return (this->*parseFunc)(treeItem->second); + template<typename T> + std::shared_ptr<T> tryParseJson(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { + return std::shared_ptr<T>(); } - - template<typename T> - std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data) const { - std::vector<std::shared_ptr<T>> result; - result.reserve(data.size()); - for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : data) { - result.push_back((this->*parseFunc)(innerTreeItem.second)); - } - return result; + return (this->*parseFunc)(treeItem->second); + } + + template<typename T> + std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data) const { + std::vector<std::shared_ptr<T>> result; + result.reserve(data.size()); + for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : data) { + result.push_back((this->*parseFunc)(innerTreeItem.second)); } - - template<typename T> - std::vector<T> parseJsonAndGetArray(std::function<T(const boost::property_tree::ptree&)> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector<T> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { - result.push_back(parseFunc(innerTreeItem.second)); - } + return result; + } + + template<typename T> + std::vector<T> parseJsonAndGetArray(std::function<T(const boost::property_tree::ptree&)> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { + std::vector<T> result; + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { return result; } - - template<typename T> - std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector<std::shared_ptr<T>> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { - result.push_back((this->*parseFunc)(innerTreeItem.second)); - } - return result; + result.reserve(treeItem->second.size()); + for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { + result.push_back(parseFunc(innerTreeItem.second)); } - - template<typename T> - std::vector<std::vector<std::shared_ptr<T>>> parseJsonAndGet2DArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector<std::vector<std::shared_ptr<T>>> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { - std::vector<std::shared_ptr<T>> innerResult; - for (const std::pair<const std::string, boost::property_tree::ptree>& innerInnerTreeItem : innerTreeItem.second) { - innerResult.push_back((this->*parseFunc)(innerInnerTreeItem.second)); - } - result.push_back(innerResult); - } + return result; + } + + template<typename T> + std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { + std::vector<std::shared_ptr<T>> result; + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { return result; } - - template<typename T> - std::string parseArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::shared_ptr<T>>& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const std::shared_ptr<T>& item : objects) { - result += (this->*parseFunc)(item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; + result.reserve(treeItem->second.size()); + for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { + result.push_back((this->*parseFunc)(innerTreeItem.second)); } - - template<typename T> - std::string parseArray(std::function<T(const T&)> parseFunc, const std::vector<T>& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const T& item : objects) { - result += parseFunc(item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; + return result; + } + + template<typename T> + std::vector<std::vector<std::shared_ptr<T>>> parseJsonAndGet2DArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { + std::vector<std::vector<std::shared_ptr<T>>> result; + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { return result; } - - template<typename T> - std::string parse2DArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::vector<std::shared_ptr<T>>>& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const std::vector<std::shared_ptr<T>>& item : objects) { - result += parseArray(parseFunc, item); - result += ','; + result.reserve(treeItem->second.size()); + for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { + std::vector<std::shared_ptr<T>> innerResult; + for (const std::pair<const std::string, boost::property_tree::ptree>& innerInnerTreeItem : innerTreeItem.second) { + innerResult.push_back((this->*parseFunc)(innerInnerTreeItem.second)); } - result.erase(result.length() - 1); - result += ']'; - return result; + result.push_back(innerResult); } - - private: - inline void removeLastComma(std::string& input) const { - input.erase(input.length() - 1); + return result; + } + + template<typename T> + std::string parseArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::shared_ptr<T>>& objects) const { + if (objects.empty()) + return ""; + std::string result; + result += '['; + for (const std::shared_ptr<T>& item : objects) { + result += (this->*parseFunc)(item); + result += ','; } - - template<typename T> - inline void appendToJson(std::string& json, const std::string& varName, const std::shared_ptr<T>& value) const { - if (value == nullptr) { - return; - } - json += '"'; - json += varName; - json += R"(":)"; - json += value; - json += ','; + result.erase(result.length() - 1); + result += ']'; + return result; + } + + template<typename T> + std::string parseArray(std::function<T(const T&)> parseFunc, const std::vector<T>& objects) const { + if (objects.empty()) + return ""; + std::string result; + result += '['; + for (const T& item : objects) { + result += parseFunc(item); + result += ','; } - - template<typename T> - inline void appendToJson(std::string& json, const std::string& varName, const T& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += value; - json += ','; + result.erase(result.length() - 1); + result += ']'; + return result; + } + + template<typename T> + std::string parse2DArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::vector<std::shared_ptr<T>>>& objects) const { + if (objects.empty()) + return ""; + std::string result; + result += '['; + for (const std::vector<std::shared_ptr<T>>& item : objects) { + result += parseArray(parseFunc, item); + result += ','; } - - template<typename T> - inline void appendToJsonNumber(std::string& json, const std::string& varName, const T& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += std::to_string(value); - json += ','; - } - inline void appendToJson(std::string &json, const std::string &varName, const int &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned long long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const float &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const double &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long double &value) const { appendToJsonNumber(json, varName, value); } - - inline void appendToJson(std::string& json, const std::string& varName, const bool& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += (value ? "true" : "false"); - json += ','; + result.erase(result.length() - 1); + result += ']'; + return result; + } + +private: + inline void removeLastComma(std::string& input) const { + input.erase(input.length() - 1); + } + + template<typename T> + inline void appendToJson(std::string& json, const std::string& varName, const std::shared_ptr<T>& value) const { + if (value == nullptr) { + return; } - - void appendToJson(std::string& json, const std::string& varName, const std::string& value) const; - }; + json += '"'; + json += varName; + json += R"(":)"; + json += value; + json += ','; + } + + template<typename T> + inline void appendToJson(std::string& json, const std::string& varName, const T& value) const { + json += '"'; + json += varName; + json += R"(":)"; + json += value; + json += ','; + } + + template<typename T> + inline void appendToJsonNumber(std::string& json, const std::string& varName, const T& value) const { + json += '"'; + json += varName; + json += R"(":)"; + json += std::to_string(value); + json += ','; + } + + inline void appendToJson(std::string &json, const std::string &varName, const int &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const long &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const long long &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const unsigned &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const unsigned long &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const unsigned long long &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const float &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const double &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const long double &value) const { appendToJsonNumber(json, varName, value); } + + inline void appendToJson(std::string& json, const std::string& varName, const bool& value) const { + json += '"'; + json += varName; + json += R"(":)"; + json += (value ? "true" : "false"); + json += ','; + } + + void appendToJson(std::string& json, const std::string& varName, const std::string& value) const; +}; } diff --git a/samples/echobot-conan/CMakeLists.txt b/samples/echobot-conan/CMakeLists.txt deleted file mode 100644 index 24d5422..0000000 --- a/samples/echobot-conan/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -project(PackageTest CXX) -cmake_minimum_required(VERSION 2.8.4) -set(CMAKE_CXX_STANDARD 11) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -add_executable(example example.cpp) -target_link_libraries(example ${CONAN_LIBS}) diff --git a/samples/echobot-conan/conanfile.py b/samples/echobot-conan/conanfile.py deleted file mode 100644 index 732b9b8..0000000 --- a/samples/echobot-conan/conanfile.py +++ /dev/null @@ -1,24 +0,0 @@ - -import os -from conans import ConanFile, CMake, tools - - -class TestConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" - - def build(self): - cmake = CMake(self) - # Current dir is "echobot-conan/build/<build_id>" and CMakeLists.txt is in "echobot-conan" - cmake.configure() - cmake.build() - - def imports(self): - self.copy("*.dll", dst="bin", src="bin") - self.copy("*.dylib*", dst="bin", src="lib") - self.copy('*.so*', dst='bin', src='lib') - - def test(self): - if not tools.cross_building(self.settings): - os.chdir("bin") - self.run(".%sexample" % os.sep) diff --git a/samples/echobot-conan/example.cpp b/samples/echobot-conan/example.cpp deleted file mode 100644 index f1c2863..0000000 --- a/samples/echobot-conan/example.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include <tgbot/tgbot.h> - -using namespace std; -using namespace TgBot; - -bool sigintGot = false; - -int main() { - Bot bot("PLACE YOUR TOKEN HERE"); - bot.getEvents().onCommand("start", [&bot](Message::Ptr message) { - bot.getApi().sendMessage(message->chat->id, "Hi!"); - }); - bot.getEvents().onAnyMessage([&bot](Message::Ptr message) { - printf("User wrote %s\n", message->text.c_str()); - if (StringTools::startsWith(message->text, "/start")) { - return; - } - bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text); - }); -} diff --git a/src/Api.cpp b/src/Api.cpp index ee8f36f..19681f7 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -336,12 +336,11 @@ bool Api::createNewStickerSet(int32_t userId, const string& name, const string& return sendRequest("createNewStickerSet", args).get<bool>("", false); } -bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { +bool Api::addStickerToSet(int32_t userId, const string& name, const boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { vector<HttpReqArg> args; args.reserve(6); args.emplace_back("user_id", userId); args.emplace_back("name", name); - args.emplace_back("title", title); 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); @@ -363,11 +362,11 @@ bool Api::setStickerPositionInSet(const string& sticker, uint32_t position) cons return sendRequest("setStickerPositionInSet", args).get<bool>("", false); } -bool Api::deleteStickerPositionInSet(const string& sticker) const { +bool Api::deleteStickerFromSet(const string& sticker) const { vector<HttpReqArg> args; args.reserve(1); args.emplace_back("sticker", sticker); - return sendRequest("setStickerPositionInSet", args).get<bool>("", false); + return sendRequest("deleteStickerFromSet", args).get<bool>("", false); } Message::Ptr Api::sendVideo(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const boost::variant<InputFile::Ptr, std::string> thumb, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 0a098f0..999dbc1 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1811,12 +1811,13 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton:: } string result; result += '{'; + if(object->pay) + 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); - appendToJson(result, "pay", object->pay); removeLastComma(result); result += '}'; return result; diff --git a/src/net/CurlHttpClient.cpp b/src/net/CurlHttpClient.cpp index 932fd68..8b1aec4 100644 --- a/src/net/CurlHttpClient.cpp +++ b/src/net/CurlHttpClient.cpp @@ -37,10 +37,8 @@ CurlHttpClient::~CurlHttpClient() { } static size_t curlWriteString(char* ptr, size_t size, size_t nmemb, void* userdata) { - std::string &s = *(std::string *)userdata; - auto read = size * nmemb; - s.append(ptr, ptr + read); - return read; + static_cast<std::string *>(userdata)->append(ptr, size * nmemb); + return size * nmemb; }; std::string CurlHttpClient::makeRequest(const Url& url, const std::vector<HttpReqArg>& args) const { @@ -56,18 +54,21 @@ std::string CurlHttpClient::makeRequest(const Url& url, const std::vector<HttpRe headers = curl_slist_append(headers, "Connection: close"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - std::string data; - std::vector<char*> escaped; + curl_mime *mime; + curl_mimepart *part; + mime = curl_mime_init(curl); if (!args.empty()) { for (const HttpReqArg& a : args) { - escaped.push_back(curl_easy_escape(curl, a.name.c_str(), a.name.size())); - data += escaped.back() + std::string("="); - escaped.push_back(curl_easy_escape(curl, a.value.c_str(), a.value.size())); - data += escaped.back() + std::string("&"); + part = curl_mime_addpart(mime); + + curl_mime_data(part, a.value.c_str(), a.value.size()); + curl_mime_type(part, a.mimeType.c_str()); + curl_mime_name(part, a.name.c_str()); + if (a.isFile) { + curl_mime_filename(part, a.fileName.c_str()); + } } - data.resize(data.size() - 1); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)data.size()); + curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime); } std::string response; @@ -77,10 +78,7 @@ std::string CurlHttpClient::makeRequest(const Url& url, const std::vector<HttpRe auto res = curl_easy_perform(curl); curl_slist_free_all(headers); curl_easy_cleanup(curl); - - for (auto& e : escaped) { - curl_free(e); - } + curl_mime_free(mime); if (res != CURLE_OK) { throw std::runtime_error(std::string("curl error: ") + curl_easy_strerror(res)); |