summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornitanmarcel <nitan.marcel@protonmail.com>2019-11-19 21:31:44 +0200
committernitanmarcel <nitan.marcel@protonmail.com>2019-11-19 21:34:53 +0200
commit23553bc251ca673137b684082a6f84062f053bd2 (patch)
tree6ba5dccf2cb58e64a595399ee7da626ae7a285dd
parent70fdce95df4998ae4e54df4006859a3770a59478 (diff)
API 4.2
-rw-r--r--CMakeLists.txt2
-rw-r--r--Doxyfile86
-rw-r--r--README.md2
-rw-r--r--include/tgbot/Api.h39
-rw-r--r--include/tgbot/TgTypeParser.h8
-rw-r--r--include/tgbot/types/ChatMember.h5
-rw-r--r--include/tgbot/types/Message.h11
-rw-r--r--include/tgbot/types/Poll.h63
-rw-r--r--include/tgbot/types/PollOption.h46
-rw-r--r--src/Api.cpp38
-rw-r--r--src/TgTypeParser.cpp50
11 files changed, 298 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 275c505..411535d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,7 +34,7 @@ set(SRC_LIST
src/tools/StringTools.cpp
src/types/InlineQueryResult.cpp
src/types/InputFile.cpp
-)
+ include/tgbot/types/Poll.h include/tgbot/types/PollOption.h)
# libs
## threads
diff --git a/Doxyfile b/Doxyfile
index ae557e7..2b036f8 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -63,7 +63,7 @@ OUTPUT_DIRECTORY = doc
# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
# directories (in 2 levels) under the output directory of each output format and
# will distribute the generated files over these directories. Enabling this
-# option can be useful when feeding doxygen a huge amount of source files, where
+# options can be useful when feeding doxygen a huge amount of source files, where
# putting all generated files in the same directory would otherwise causes
# performance problems for the file system.
# The default value is: NO.
@@ -330,7 +330,7 @@ AUTOLINK_SUPPORT = YES
BUILTIN_STL_SUPPORT = NO
-# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# If you use Microsoft's C++/CLI language, you should set this options to YES to
# enable parsing support.
# The default value is: NO.
@@ -345,11 +345,11 @@ CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
# For Microsoft's IDL there are propget and propput attributes to indicate
-# getter and setter methods for a property. Setting this option to YES will make
+# getter and setter methods for a property. Setting this options to YES will make
# doxygen to replace the get and set methods by a property in the documentation.
# This will only work if the methods are indeed getting or setting a simple
# type. If this is not the case, or you want to show the methods anyway, you
-# should set this option to NO.
+# should set this options to NO.
# The default value is: YES.
IDL_PROPERTY_SUPPORT = YES
@@ -362,8 +362,8 @@ IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
-# If one adds a struct or class to a group and this option is enabled, then also
-# any nested class or struct is added to the same group. By default this option
+# If one adds a struct or class to a group and this options is enabled, then also
+# any nested class or struct is added to the same group. By default this options
# is disabled and one has to add nested compounds explicitly via \ingroup.
# The default value is: NO.
@@ -483,14 +483,14 @@ EXTRACT_ANON_NSPACES = NO
# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
# undocumented members inside documented classes or files. If set to NO these
# members will be included in the various overviews, but no documentation
-# section is generated. This option has no effect if EXTRACT_ALL is enabled.
+# section is generated. This options has no effect if EXTRACT_ALL is enabled.
# The default value is: NO.
HIDE_UNDOC_MEMBERS = NO
# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
# undocumented classes that are normally visible in the class hierarchy. If set
-# to NO, these classes will be included in the various overviews. This option
+# to NO, these classes will be included in the various overviews. This options
# has no effect if EXTRACT_ALL is enabled.
# The default value is: NO.
@@ -521,7 +521,7 @@ INTERNAL_DOCS = NO
# names in lower-case letters. If set to YES, upper-case letters are also
# allowed. This is useful if you have classes or files whose names only differ
# in case and if your file system supports case sensitive file names. Windows
-# and Mac users are advised to set this option to NO.
+# and Mac users are advised to set this options to NO.
# The default value is: system dependent.
CASE_SENSE_NAMES = NO
@@ -584,9 +584,9 @@ SORT_BRIEF_DOCS = NO
# (brief and detailed) documentation of class members so that constructors and
# destructors are listed first. If set to NO the constructors will appear in the
# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
-# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
+# Note: If SORT_BRIEF_DOCS is set to NO this options is ignored for sorting brief
# member documentation.
-# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
+# Note: If SORT_MEMBER_DOCS is set to NO this options is ignored for sorting
# detailed member documentation.
# The default value is: NO.
@@ -602,14 +602,14 @@ SORT_GROUP_NAMES = NO
# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
# fully-qualified names, including namespaces. If set to NO, the class list will
# be sorted only by class name, not including the namespace part.
-# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
-# Note: This option applies only to the class list, not to the alphabetical
+# Note: This options is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This options applies only to the class list, not to the alphabetical
# list.
# The default value is: NO.
SORT_BY_SCOPE_NAME = NO
-# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
+# If the STRICT_PROTO_MATCHING options is enabled and doxygen fails to do proper
# type resolution of all parameters of a function it will reject a match between
# the prototype and the implementation of a member function even if there is
# only one candidate or it is obvious which candidate to choose by doing a
@@ -695,8 +695,8 @@ FILE_VERSION_FILTER =
# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
# by doxygen. The layout file controls the global structure of the generated
# output files in an output format independent way. To create the layout file
-# that represents doxygen's defaults, run doxygen with the -l option. You can
-# optionally specify a file name after the option, if omitted DoxygenLayout.xml
+# that represents doxygen's defaults, run doxygen with the -l options. You can
+# optionally specify a file name after the options, if omitted DoxygenLayout.xml
# will be used as the name of the layout file.
#
# Note that if you run doxygen from a directory containing a file called
@@ -750,7 +750,7 @@ WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
-# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
+# This WARN_NO_PARAMDOC options can be enabled to get warnings for functions that
# are documented, but have no documentation for their parameters or return
# value. If set to NO, doxygen will only warn about wrong or incomplete
# parameter documentation, but not about the absence of documentation.
@@ -1036,8 +1036,8 @@ VERBATIM_HEADERS = YES
# cost of reduced performance. This can be particularly helpful with template
# rich C++ code for which doxygen's built-in parser lacks the necessary type
# information.
-# Note: The availability of this option depends on whether or not doxygen was
-# generated with the -Duse-libclang=ON option for CMake.
+# Note: The availability of this options depends on whether or not doxygen was
+# generated with the -Duse-libclang=ON options for CMake.
# The default value is: NO.
CLANG_ASSISTED_PARSING = NO
@@ -1144,7 +1144,7 @@ HTML_STYLESHEET =
# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
# cascading style sheets that are included after the standard style sheets
-# created by doxygen. Using this option one can overrule certain style aspects.
+# created by doxygen. Using this options one can overrule certain style aspects.
# This is preferred over using HTML_STYLESHEET since it does not replace the
# standard style sheet and is therefore more robust against future updates.
# Doxygen will copy the style sheet files to the output directory.
@@ -1418,7 +1418,7 @@ ECLIPSE_DOC_ID = org.doxygen.Project
# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
# of each HTML page. A value of NO enables the index and the value YES disables
# it. Since the tabs in the index contain the same information as the navigation
-# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
+# tree, you can set this options to YES if you also set GENERATE_TREEVIEW to YES.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
@@ -1435,7 +1435,7 @@ DISABLE_INDEX = NO
# sheet generated by doxygen has an example that shows how to put an image at
# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
# the same information as the tab index, you could consider setting
-# DISABLE_INDEX to YES when enabling this option.
+# DISABLE_INDEX to YES when enabling this options.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
@@ -1458,7 +1458,7 @@ ENUM_VALUES_PER_LINE = 4
TREEVIEW_WIDTH = 250
-# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
+# If the EXT_LINKS_IN_WINDOW options is set to YES, doxygen will open links to
# external symbols imported via tag files in a separate window.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
@@ -1478,19 +1478,19 @@ FORMULA_FONTSIZE = 10
# generated for formulas are transparent PNGs. Transparent PNGs are not
# supported properly for IE 6.0, but are supported on all modern browsers.
#
-# Note that when changing this option you need to delete any form_*.png files in
+# Note that when changing this options you need to delete any form_*.png files in
# the HTML output directory before the changes have effect.
# The default value is: YES.
# This tag requires that the tag GENERATE_HTML is set to YES.
FORMULA_TRANSPARENT = YES
-# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
+# Enable the USE_MATHJAX options to render LaTeX formulas using MathJax (see
# http://www.mathjax.org) which uses client side Javascript for the rendering
# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
# installed or if you want to formulas look prettier in the HTML output. When
# enabled you may also need to install MathJax separately and configure the path
-# to it using the MATHJAX_RELPATH option.
+# to it using the MATHJAX_RELPATH options.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
@@ -1507,7 +1507,7 @@ USE_MATHJAX = NO
MATHJAX_FORMAT = HTML-CSS
# When MathJax is enabled you need to specify the location relative to the HTML
-# output directory using the MATHJAX_RELPATH option. The destination directory
+# output directory using the MATHJAX_RELPATH options. The destination directory
# should contain the MathJax.js script. For instance, if the mathjax directory
# is located at the same level as the HTML output directory, then
# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
@@ -1543,13 +1543,13 @@ MATHJAX_CODEFILE =
# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
# search using the keyboard; to jump to the search box use <access key> + S
# (what the <access key> is depends on the OS and browser, but it is typically
-# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down
+# <CTRL>, <ALT>/<options>, or both). Inside the search box use the <cursor down
# key> to jump into the search results window, the results can be navigated
# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel
# the search. The filter options can be selected when the cursor is inside the
# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>
# to select a filter and <Enter> or <escape> to activate or cancel the filter
-# option.
+# options.
# The default value is: YES.
# This tag requires that the tag GENERATE_HTML is set to YES.
@@ -1570,7 +1570,7 @@ SERVER_BASED_SEARCH = NO
# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
# script for searching. Instead the search results are written to an XML file
# which needs to be processed by an external indexer. Doxygen will invoke an
-# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
+# external search engine pointed to by the SEARCHENGINE_URL options to obtain the
# search results.
#
# Doxygen ships with an example indexer (doxyindexer) and search engine
@@ -1640,7 +1640,7 @@ LATEX_OUTPUT = latex
# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
# invoked.
#
-# Note that when enabling USE_PDFLATEX this option is only used for generating
+# Note that when enabling USE_PDFLATEX this options is only used for generating
# bitmaps for formulas in the HTML output, but not in the Makefile that is
# written to the output directory.
# The default file is: latex.
@@ -1677,7 +1677,7 @@ PAPER_TYPE = a4
# by its name or with the correct syntax as to be used with the LaTeX
# \usepackage command. To get the times font for instance you can specify :
# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
-# To use the option intlimits with the amsmath package you can specify:
+# To use the options intlimits with the amsmath package you can specify:
# EXTRA_PACKAGES=[intlimits]{amsmath}
# If left blank no extra packages will be included.
# This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -1713,7 +1713,7 @@ LATEX_FOOTER =
# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
# LaTeX style sheets that are included after the standard style sheets created
-# by doxygen. Using this option one can overrule certain style aspects. Doxygen
+# by doxygen. Using this options one can overrule certain style aspects. Doxygen
# will copy the style sheet files to the output directory.
# Note: The order of the extra style sheet files is of importance (e.g. the last
# style sheet in the list overrules the setting of the previous ones in the
@@ -1740,7 +1740,7 @@ LATEX_EXTRA_FILES =
PDF_HYPERLINKS = YES
# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
-# the PDF file directly from the LaTeX files. Set this option to YES, to get a
+# the PDF file directly from the LaTeX files. Set this options to YES, to get a
# higher quality PDF documentation.
# The default value is: YES.
# This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -1749,7 +1749,7 @@ USE_PDFLATEX = YES
# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
# command to the generated LaTeX files. This will instruct LaTeX to keep running
-# if errors occur, instead of asking the user for help. This option is also used
+# if errors occur, instead of asking the user for help. This options is also used
# when generating formulas in HTML.
# The default value is: NO.
# This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -2053,7 +2053,7 @@ INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
# The PREDEFINED tag can be used to specify one or more macro names that are
-# defined before the preprocessor is started (similar to the -D option of e.g.
+# defined before the preprocessor is started (similar to the -D options of e.g.
# gcc). The argument of the tag is a list of macros of the form: name or
# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
# is assumed. To prevent a macro definition from being undefined via #undef or
@@ -2139,7 +2139,7 @@ PERL_PATH = /usr/bin/perl
# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram
# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
-# NO turns the diagrams off. Note that this option also works with HAVE_DOT
+# NO turns the diagrams off. Note that this options also works with HAVE_DOT
# disabled, but it is recommended to install and use dot, since it yields more
# powerful graphs.
# The default value is: YES.
@@ -2171,7 +2171,7 @@ HIDE_UNDOC_RELATIONS = YES
# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
# available from the path. This tool is part of Graphviz (see:
# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
-# Bell Labs. The other options in this section have no effect if this option is
+# Bell Labs. The other options in this section have no effect if this options is
# set to NO
# The default value is: NO.
@@ -2285,7 +2285,7 @@ INCLUDED_BY_GRAPH = YES
# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
# dependency graph for every global function or class method.
#
-# Note that enabling this option will significantly increase the time of a run.
+# Note that enabling this options will significantly increase the time of a run.
# So in most cases it will be better to enable call graphs for selected
# functions only using the \callgraph command. Disabling a call graph can be
# accomplished by means of the command \hidecallgraph.
@@ -2297,7 +2297,7 @@ CALL_GRAPH = NO
# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
# dependency graph for every global function or class method.
#
-# Note that enabling this option will significantly increase the time of a run.
+# Note that enabling this options will significantly increase the time of a run.
# So in most cases it will be better to enable caller graphs for selected
# functions only using the \callergraph command. Disabling a caller graph can be
# accomplished by means of the command \hidecallergraph.
@@ -2337,7 +2337,7 @@ DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
-# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
+# If DOT_IMAGE_FORMAT is set to svg, then this options can be set to YES to
# enable generation of interactive SVG images that allow zooming and panning.
#
# Note that this requires a modern browser other than Internet Explorer. Tested
@@ -2407,7 +2407,7 @@ DOT_GRAPH_MAX_NODES = 50
# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
# generated by dot. A depth value of 3 means that only nodes reachable from the
# root by following a path via at most 3 edges will be shown. Nodes that lay
-# further from the root node will be omitted. Note that setting this option to 1
+# further from the root node will be omitted. Note that setting this options to 1
# or 2 may greatly reduce the computation time needed for large code bases. Also
# note that the size of a graph can be further restricted by
# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
@@ -2420,7 +2420,7 @@ MAX_DOT_GRAPH_DEPTH = 0
# background. This is disabled by default, because dot on Windows does not seem
# to support this out of the box.
#
-# Warning: Depending on the platform used, enabling this option may lead to
+# Warning: Depending on the platform used, enabling this options may lead to
# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
# read).
# The default value is: NO.
diff --git a/README.md b/README.md
index bd045d5..780923a 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp).
## State
- [x] Bot API 3.0 ~ 3.6
-- [x] Bot API 4.0 (Implemented all APIs except 'Telegram Passport')
+- [x] Bot API 4.0 ~ 4.2 (Implemented all APIs except 'Telegram Passport')
## Sample
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 84a6c9b..184f3a1 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -291,6 +291,7 @@ public:
* @param disableNotification Optional. Sends the message silenty.
* @return On success, the sent message is returned.
*/
+
Message::Ptr sendVideo(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming = false, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string& caption = "",
int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const;
@@ -585,7 +586,7 @@ public:
/**
* @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.
+ * @param chatId Unique identifier for the target chat or username of the target channel.
* @param messageId Unique identifier for the target message.
*/
void deleteMessage(int64_t chatId, int32_t messageId) const;
@@ -746,8 +747,8 @@ public:
bool setChatDescription(int64_t chatId, const std::string& description) const;
/**
- * @brief Use this method to pin a message in a supergroup or a channel.
- * @param chatId Unique identifier for the target chat.
+ * @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
@@ -755,8 +756,8 @@ public:
bool pinChatMessage(int64_t chatId, int32_t messageId, bool disableNotification = false) const;
/**
- * @brief Use this method to unpin a message in a supergroup or a channel.
- * @param chatId Unique identifier for the target chat.
+ * @brief Use this method to unpin a message in a group, a supergroup, or a channel.
+ * @param chatId Unique identifier for the target chat or username of the target channel.
* @return True on success
*/
bool unpinChatMessage(int64_t chatId) const;
@@ -792,7 +793,6 @@ public:
std::vector<GameHighScore::Ptr> getGameHighScores(int32_t userId, int32_t score, bool force = false,
bool disableEditMessage = false, int64_t chatId = 0, int32_t messageId = 0, const std::string& inlineMessageId = "") const;
-
/**
* @brief Downloads file from Telegram and saves it in memory.
* @param filePath Telegram file path.
@@ -801,6 +801,33 @@ public:
*/
std::string downloadFile(const std::string& filePath, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
+ /**
+ * @brief Use this method to send a poll.
+ * @param chatId Unique identifier for the target chat or username of the target channel.
+ * @param question Poll question, 1-255 characters.
+ * @param options List of answer options, 2-10 strings 1-100 characters each.
+ * @param disable_notification Optional. Sends the message silenty.
+ * @param reply_to_message_id Optional. If the message is a reply, ID of the original message.
+ * @param reply_markup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
+ *
+ * @return On success, the sent message is returned.
+ */
+ Message::Ptr sendPoll(int64_t chatId, std::string question, std::vector<std::string> options, bool disable_notification=false, int32_t reply_to_message_id=0,GenericReply::Ptr reply_markup = std::make_shared<GenericReply>()) const;
+
+ /**
+ * @brief Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned..
+ * @param chatId Unique identifier for the target chat or username of the target channel.
+ * @param question Poll question, 1-255 characters.
+ * @param options List of answer options, 2-10 strings 1-100 characters each.
+ * @param disable_notification Optional. Sends the message silenty.
+ * @param reply_to_message_id Optional. If the message is a reply, ID of the original message.
+ * @param reply_markup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
+ *
+ * @return On success, the sent message is returned.
+ */
+
+ Poll::Ptr stopPoll(int64_t chatId, int64_t messageId, InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared<InlineKeyboardMarkup>()) 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/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index eeda4cd..a2cb660 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -36,6 +36,8 @@
#include "tgbot/types/Document.h"
#include "tgbot/types/Sticker.h"
#include "tgbot/types/StickerSet.h"
+#include "tgbot/types/Poll.h"
+#include "tgbot/types/PollOption.h"
#include "tgbot/types/MaskPosition.h"
#include "tgbot/types/Video.h"
#include "tgbot/types/Voice.h"
@@ -145,6 +147,12 @@ namespace TgBot {
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;
+
+ PollOption::Ptr parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const;
+ std::string parsePollOption(const PollOption::Ptr& object) const;
+
Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const;
std::string parseVideo(const Video::Ptr& object) const;
diff --git a/include/tgbot/types/ChatMember.h b/include/tgbot/types/ChatMember.h
index facfec2..79fff0e 100644
--- a/include/tgbot/types/ChatMember.h
+++ b/include/tgbot/types/ChatMember.h
@@ -77,6 +77,11 @@ public:
bool canPinMessages = false;
/**
+ * @brief Optional. Restricted only. True, if the user is a member of the chat at the moment of the request.
+ */
+ bool isMember = false;
+
+ /**
* @brief Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user).
*/
bool canPromoteMembers = false;
diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h
index f92eeaf..4b7ce59 100644
--- a/include/tgbot/types/Message.h
+++ b/include/tgbot/types/Message.h
@@ -34,6 +34,7 @@
#include "tgbot/types/Document.h"
#include "tgbot/types/Animation.h"
#include "tgbot/types/Sticker.h"
+#include "tgbot/types/Poll.h"
#include "tgbot/types/Video.h"
#include "tgbot/types/Contact.h"
#include "tgbot/types/Location.h"
@@ -97,6 +98,11 @@ public:
std::string forwardSignature;
/**
+ * @brief Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages.
+ */
+ std::string forwardSenderName;
+
+ /**
* @brief Optional. For forwarded messages, date the original message was sent in Unix time.
*/
int32_t forwardDate;
@@ -194,6 +200,11 @@ public:
Venue::Ptr venue;
/**
+ * @brief Optional. Message is a poll, information about the poll.
+ */
+ Poll::Ptr poll;
+
+ /**
* @brief Optional. A new member was added to the group, information about them (this member may be bot itself).
*/
User::Ptr newChatMember;
diff --git a/include/tgbot/types/Poll.h b/include/tgbot/types/Poll.h
new file mode 100644
index 0000000..11c3c07
--- /dev/null
+++ b/include/tgbot/types/Poll.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2019 Nitan Alexandru Marcel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_POLL_H
+#define TGBOT_POLL_H
+
+#include <memory>
+#include <string>
+#include <vector>
+#include "tgbot/types/PollOption.h"
+
+namespace TgBot{
+ /**
+ * @brief This object represents a Poll.
+ *
+ * @ingroup types
+ */
+ class Poll{
+ public:
+ typedef std::shared_ptr<Poll> Ptr;
+
+ /**
+ * @brief Unique poll identifier.
+ */
+ int64_t id;
+
+ /**
+ * @brief Poll question, 1-255 characters.
+ */
+ std::string question;
+
+ /**
+ * @brief List of poll options.
+ */
+ PollOption::Ptr options;
+
+ /**
+ * @brief True, if the poll is closed.
+ */
+ bool is_closed;
+ };
+}
+
+#endif //TGBOT_POLL_H
diff --git a/include/tgbot/types/PollOption.h b/include/tgbot/types/PollOption.h
new file mode 100644
index 0000000..52099f9
--- /dev/null
+++ b/include/tgbot/types/PollOption.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2019 Nitan Alexandru Marcel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#ifndef TGBOT_POLLOPTION_H
+#define TGBOT_POLLOPTION_H
+
+class PollOption {
+
+public:
+ typedef std::shared_ptr<PollOption> Ptr;
+
+ /**
+ * @brief Option text, 1-100 characters.
+ */
+ std::string text;
+
+ /**
+ * @brief Number of users that voted for this option.
+ */
+ int64_t voter_count;
+};
+
+#endif //TGBOT_POLLOPTION_H
diff --git a/src/Api.cpp b/src/Api.cpp
index 6b41947..ae6ecee 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -276,6 +276,7 @@ bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok,
return sendRequest("answerPreCheckoutQuery", args).get<bool>("", false);
}
+
Message::Ptr Api::sendSticker(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.reserve(5);
@@ -1143,6 +1144,43 @@ void Api::deleteMessage(int64_t chatId, int32_t messageId) const {
sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) });
}
+Message::Ptr Api::sendPoll(int64_t chat_id, std::string question, std::vector<std::string> options, bool disable_notification, int32_t reply_to_message_id,GenericReply::Ptr reply_markup) const {
+ vector<HttpReqArg> args;
+ args.reserve(6);
+ args.emplace_back("chat_id", chat_id);
+ args.emplace_back("question", question);
+ std::string json_array;
+ json_array = "[";
+ for(const auto &arr : options){
+ json_array += "\"" + arr + "\"" + ",";
+ }
+ json_array.pop_back();
+ json_array += "]";
+ args.emplace_back("options", json_array);
+
+ if (disable_notification){
+ args.emplace_back("disable_notification", disable_notification);
+ }
+ if (reply_to_message_id!=0){
+ args.emplace_back("reply_to_message_id", reply_to_message_id);
+ }
+ if (reply_markup){
+ args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(reply_markup));
+ }
+ return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args));
+}
+
+Poll::Ptr Api::stopPoll(int64_t chatId, int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
+ 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));
+}
+
ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) const {
string url = "https://api.telegram.org/bot";
url += _token;
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 4e31c94..528993b 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -144,6 +144,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const {
result->forwardFromChat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "forward_from_chat");
result->forwardFromMessageId = data.get<int32_t>("forward_from_message_id", 0);
result->forwardSignature = data.get("forward_signature", "");
+ result->forwardSenderName = data.get("forward_sender_name", "");
result->forwardDate = data.get("forward_date", 0);
result->replyToMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message");
result->editDate = data.get<int32_t>("edit_date", 0);
@@ -161,6 +162,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const {
result->voice = tryParseJson<Voice>(&TgTypeParser::parseJsonAndGetVoice, data, "voice");
result->contact = tryParseJson<Contact>(&TgTypeParser::parseJsonAndGetContact, data, "contact");
result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
+ result->poll = tryParseJson<Poll>(&TgTypeParser::parseJsonAndGetPoll, data, "poll");
result->newChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_participant");
result->newChatMembers = parseJsonAndGetArray<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_members");
result->leftChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "left_chat_participant");
@@ -194,6 +196,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "forward_from_chat", parseChat(object->forwardFromChat));
appendToJson(result, "forward_from_message_id", object->forwardFromMessageId);
appendToJson(result, "forward_signature", object->forwardSignature);
+ appendToJson(result, "forward_sender_name", object->forwardSenderName);
appendToJson(result, "forward_date", object->forwardDate);
appendToJson(result, "reply_to_message", parseMessage(object->replyToMessage));
appendToJson(result, "edit_date", object->editDate);
@@ -208,6 +211,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "voice", parseVoice(object->voice));
appendToJson(result, "contact", parseContact(object->contact));
appendToJson(result, "location", parseLocation(object->location));
+ appendToJson(result, "poll", parsePoll(object->poll));
appendToJson(result, "new_chat_member", parseUser(object->newChatMember));
appendToJson(result, "new_chat_members", parseArray(&TgTypeParser::parseUser, object->newChatMembers));
appendToJson(result, "left_chat_member", parseUser(object->leftChatMember));
@@ -385,6 +389,50 @@ string TgTypeParser::parseMaskPosition(const MaskPosition::Ptr& object) const {
return result;
}
+Poll::Ptr TgTypeParser::parseJsonAndGetPoll(const ptree& data) const {
+ auto result(make_shared<Poll>());
+ result->id = data.get("id", 0);
+ result->question = data.get("question", "");
+ result->options = tryParseJson<PollOption>(&TgTypeParser::parseJsonAndGetPollOption, data, "options");
+ result->is_closed = data.get<bool>("is_closed");
+ return result;
+}
+
+string TgTypeParser::parsePoll(const Poll::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "id", object->id);
+ appendToJson(result, "question", object->question);
+ appendToJson(result, "options", parsePollOption(object->options));
+ appendToJson(result, "is_closed", object->is_closed);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+ PollOption::Ptr TgTypeParser::parseJsonAndGetPollOption(const ptree& data) const {
+ auto result(make_shared<PollOption>());
+ result->text = data.get("text", "");
+ result->voter_count = data.get("voter_count", 0);
+ return result;
+}
+
+string TgTypeParser::parsePollOption(const PollOption::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "text", object->text);
+ appendToJson(result, "voter_count", object->voter_count);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
Video::Ptr TgTypeParser::parseJsonAndGetVideo(const ptree& data) const {
auto result(make_shared<Video>());
result->fileId = data.get<string>("file_id");
@@ -877,6 +925,7 @@ ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tr
result->canInviteUsers = data.get<bool>("can_invite_users", false);
result->canRestrictMembers = data.get<bool>("can_restrict_members", false);
result->canPinMessages = data.get<bool>("can_pin_messages", false);
+ result->isMember = data.get<bool>("is_member", false);
result->canPromoteMembers = data.get<bool>("can_promote_messages", false);
result->canSendMessages = data.get<bool>("can_send_messages", false);
result->canSendMediaMessages = data.get<bool>("can_send_media_messages", false);
@@ -2127,5 +2176,4 @@ void TgTypeParser::appendToJson(string& json, const string& varName, const strin
}
json += ',';
}
-
}