summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--[-rwxr-xr-x]CMakeLists.txt2
-rw-r--r--[-rwxr-xr-x]README.md55
-rw-r--r--doxygen.conf332
-rw-r--r--include/tgbot/Api.h242
-rw-r--r--include/tgbot/Bot.h (renamed from src/tgbot/Bot.h)16
-rw-r--r--include/tgbot/EventBroadcaster.h (renamed from src/tgbot/EventBroadcaster.h)21
-rw-r--r--include/tgbot/EventHandler.h (renamed from src/tgbot/EventHandler.h)0
-rw-r--r--include/tgbot/TgException.h (renamed from src/tgbot/TgException.h)4
-rw-r--r--include/tgbot/TgTypeParser.h (renamed from src/tgbot/TgTypeParser.h)0
-rw-r--r--include/tgbot/doxygenMain.h89
-rw-r--r--include/tgbot/net/HttpClient.h (renamed from src/tgbot/net/HttpClient.h)12
-rw-r--r--include/tgbot/net/HttpParser.h (renamed from src/tgbot/net/HttpParser.h)0
-rw-r--r--include/tgbot/net/HttpReqArg.h (renamed from src/tgbot/net/HttpReqArg.h)21
-rw-r--r--include/tgbot/net/HttpServer.h (renamed from src/tgbot/net/HttpServer.h)10
-rw-r--r--include/tgbot/net/TgLongPoll.h (renamed from src/tgbot/net/TgLongPoll.h)7
-rw-r--r--include/tgbot/net/TgWebhookLocalServer.h (renamed from src/tgbot/net/TgWebhookLocalServer.h)4
-rw-r--r--include/tgbot/net/TgWebhookServer.h (renamed from src/tgbot/net/TgWebhookServer.h)0
-rw-r--r--include/tgbot/net/TgWebhookTcpServer.h (renamed from src/tgbot/net/TgWebhookTcpServer.h)4
-rw-r--r--include/tgbot/net/Url.h (renamed from src/tgbot/net/Url.h)23
-rw-r--r--include/tgbot/tools/StringTools.h (renamed from src/tgbot/tools/StringTools.h)44
-rw-r--r--include/tgbot/types/Audio.h (renamed from src/tgbot/types/Audio.h)19
-rw-r--r--include/tgbot/types/Contact.h (renamed from src/tgbot/types/Contact.h)19
-rw-r--r--include/tgbot/types/Document.h (renamed from src/tgbot/types/Document.h)23
-rw-r--r--include/tgbot/types/ForceReply.h58
-rw-r--r--include/tgbot/types/GenericChat.h (renamed from src/tgbot/types/GenericChat.h)7
-rw-r--r--include/tgbot/types/GenericReply.h (renamed from src/tgbot/types/GenericReply.h)4
-rw-r--r--include/tgbot/types/GroupChat.h (renamed from src/tgbot/types/GroupChat.h)7
-rw-r--r--include/tgbot/types/InputFile.h (renamed from src/tgbot/types/InputFile.h)11
-rw-r--r--include/tgbot/types/Location.h (renamed from src/tgbot/types/Location.h)11
-rw-r--r--include/tgbot/types/Message.h (renamed from src/tgbot/types/Message.h)92
-rw-r--r--include/tgbot/types/PhotoSize.h (renamed from src/tgbot/types/PhotoSize.h)19
-rw-r--r--include/tgbot/types/ReplyKeyboardHide.h (renamed from src/tgbot/types/ReplyKeyboardHide.h)12
-rw-r--r--include/tgbot/types/ReplyKeyboardMarkup.h (renamed from src/tgbot/types/ReplyKeyboardMarkup.h)20
-rw-r--r--include/tgbot/types/Sticker.h (renamed from src/tgbot/types/Sticker.h)23
-rw-r--r--include/tgbot/types/Update.h (renamed from src/tgbot/types/Update.h)11
-rw-r--r--include/tgbot/types/User.h (renamed from src/tgbot/types/User.h)15
-rw-r--r--include/tgbot/types/UserProfilePhotos.h (renamed from src/tgbot/types/UserProfilePhotos.h)11
-rw-r--r--include/tgbot/types/Video.h (renamed from src/tgbot/types/Video.h)32
-rw-r--r--src/tgbot/Api.cpp10
-rw-r--r--src/tgbot/Api.h77
-rw-r--r--src/tgbot/TgTypeParser.cpp4
-rw-r--r--src/tgbot/types/ForceReply.h43
43 files changed, 1288 insertions, 130 deletions
diff --git a/.gitignore b/.gitignore
index 8813d62..8006986 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,6 @@ CMakeFiles/
Makefile
cmake_install.cmake
install_manifest.txt
-.idea/ \ No newline at end of file
+.idea/
+Thumbs.db
+doc/ \ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 37cf3bb..ba9ae76 100755..100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ option(ENABLE_SAMPLES "Set to ON to enable building of samples" OFF)
### sources
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-include_directories("${PROJECT_SOURCE_DIR}/src")
+include_directories("${PROJECT_SOURCE_DIR}/include")
set(SRC_LIST
src/tgbot/Api.cpp
src/tgbot/TgTypeParser.cpp
diff --git a/README.md b/README.md
index 2296aa7..8bbe708 100755..100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,57 @@
C++ library for Telegram bot API.
-It's not stable version yet. Something may not work.
+**Warning:** It's not stable version yet. Something may not work.
-Dependencies: Boost
+Documentaion is located [here](http://reo7sp.ru/proj/tgbot-cpp/doc)
+
+## Compilation
+
+Firstly you need to install some dependencies. You have to have Boost library at the runtime and CMake at the compilation step to be able to use this library. On Debian-based distibutives you can do it with these commands:
+```sh
+sudo apt-get install cmake libboost-dev
+```
+
+To compile the library execute this commands:
+```sh
+cd /path/where/you/have/cloned/the/library/repository
+cmake .
+make -j4
+```
+
+That's all. All you have to do now is just link compiled library to your project.
+
+## Samples
+
+Simple echo bot which sends everything it recieves:
+```cpp
+int main() {
+ TgBot::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);
+ });
+ try {
+ printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str());
+ TgBot::TgLongPoll longPoll(bot);
+ while (true) {
+ printf("Long poll started\n");
+ longPoll.start();
+ }
+ } catch (TgBot::TgException& e) {
+ printf("error: %s\n", e.what());
+ }
+ return 0;
+}
+```
+
+All samples are located [here](samples)
+
+## Feedback
+Feel free to [create new issues on GitHub](https://github.com/reo7sp/tgbot-cpp/issues) or [contact me on Telegram](https://telegram.me/Reo_SP)
diff --git a/doxygen.conf b/doxygen.conf
new file mode 100644
index 0000000..f68bfb3
--- /dev/null
+++ b/doxygen.conf
@@ -0,0 +1,332 @@
+# Doxyfile 1.8.10
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = tgbot-cpp
+PROJECT_NUMBER =
+PROJECT_BRIEF =
+PROJECT_LOGO =
+OUTPUT_DIRECTORY = doc
+CREATE_SUBDIRS = NO
+ALLOW_UNICODE_NAMES = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = NO
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 4
+ALIASES =
+TCL_SUBST =
+OPTIMIZE_OUTPUT_FOR_C = NO
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+EXTENSION_MAPPING =
+MARKDOWN_SUPPORT = YES
+AUTOLINK_SUPPORT = YES
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = YES
+DISTRIBUTE_GROUP_DOC = NO
+GROUP_NESTED_COMPOUNDS = NO
+SUBGROUPING = YES
+INLINE_GROUPED_CLASSES = NO
+INLINE_SIMPLE_STRUCTS = NO
+TYPEDEF_HIDES_STRUCT = NO
+LOOKUP_CACHE_SIZE = 0
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = NO
+EXTRACT_PACKAGE = NO
+EXTRACT_STATIC = NO
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = NO
+HIDE_SCOPE_NAMES = NO
+HIDE_COMPOUND_REFERENCE= NO
+SHOW_INCLUDE_FILES = YES
+SHOW_GROUPED_MEMB_INC = NO
+FORCE_LOCAL_INCLUDES = NO
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_MEMBERS_CTORS_1ST = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+STRICT_PROTO_MATCHING = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_FILES = YES
+SHOW_NAMESPACES = YES
+FILE_VERSION_FILTER =
+LAYOUT_FILE =
+CITE_BIB_FILES =
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = E:\m\code\tgbot-cpp\include
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS = *.h \
+ *.hh \
+ *.hxx \
+ *.hpp \
+ *.h++
+RECURSIVE = YES
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS = *
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE =
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = YES
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = NO
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+CLANG_ASSISTED_PARSING = NO
+CLANG_OPTIONS =
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_FILES =
+HTML_COLORSTYLE_HUE = 220
+HTML_COLORSTYLE_SAT = 100
+HTML_COLORSTYLE_GAMMA = 80
+HTML_TIMESTAMP = YES
+HTML_DYNAMIC_SECTIONS = NO
+HTML_INDEX_NUM_ENTRIES = 100
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+DOCSET_PUBLISHER_NAME = Publisher
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHP_CUST_FILTER_NAME =
+QHP_CUST_FILTER_ATTRS =
+QHP_SECT_FILTER_ATTRS =
+QHG_LOCATION =
+GENERATE_ECLIPSEHELP = NO
+ECLIPSE_DOC_ID = org.doxygen.Project
+DISABLE_INDEX = NO
+GENERATE_TREEVIEW = YES
+ENUM_VALUES_PER_LINE = 4
+TREEVIEW_WIDTH = 250
+EXT_LINKS_IN_WINDOW = NO
+FORMULA_FONTSIZE = 10
+FORMULA_TRANSPARENT = YES
+USE_MATHJAX = NO
+MATHJAX_FORMAT = HTML-CSS
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+MATHJAX_EXTENSIONS =
+MATHJAX_CODEFILE =
+SEARCHENGINE = YES
+SERVER_BASED_SEARCH = NO
+EXTERNAL_SEARCH = NO
+SEARCHENGINE_URL =
+SEARCHDATA_FILE = searchdata.xml
+EXTERNAL_SEARCH_ID =
+EXTRA_SEARCH_MAPPINGS =
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4
+EXTRA_PACKAGES =
+LATEX_HEADER =
+LATEX_FOOTER =
+LATEX_EXTRA_STYLESHEET =
+LATEX_EXTRA_FILES =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+LATEX_SOURCE_CODE = NO
+LATEX_BIB_STYLE = plain
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+RTF_SOURCE_CODE = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_SUBDIR =
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+GENERATE_DOCBOOK = NO
+DOCBOOK_OUTPUT = docbook
+DOCBOOK_PROGRAMLISTING = NO
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+EXTERNAL_PAGES = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = YES
+MSCGEN_PATH =
+DIA_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = NO
+DOT_NUM_THREADS = 0
+DOT_FONTNAME = Helvetica
+DOT_FONTSIZE = 10
+DOT_FONTPATH =
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+UML_LIMIT_NUM_FIELDS = 10
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+INTERACTIVE_SVG = NO
+DOT_PATH =
+DOTFILE_DIRS =
+MSCFILE_DIRS =
+DIAFILE_DIRS =
+PLANTUML_JAR_PATH =
+PLANTUML_INCLUDE_PATH =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
new file mode 100644
index 0000000..1b4987a
--- /dev/null
+++ b/include/tgbot/Api.h
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ *
+ * 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_CPP_API_H
+#define TGBOT_CPP_API_H
+
+#include <string>
+#include <vector>
+
+#include <boost/property_tree/ptree.hpp>
+
+#include "tgbot/net/HttpReqArg.h"
+#include "tgbot/types/User.h"
+#include "tgbot/types/Message.h"
+#include "tgbot/types/GenericReply.h"
+#include "tgbot/types/InputFile.h"
+#include "tgbot/types/UserProfilePhotos.h"
+#include "tgbot/types/Update.h"
+
+namespace TgBot {
+
+class Bot;
+
+/**
+ * This class executes telegram api methods. Telegram docs: <https://core.telegram.org/bots/api#available-methods>
+ * @ingroup general
+ */
+class Api {
+
+friend Bot;
+
+public:
+ Api(const std::string& token);
+
+ /**
+ * A simple method for testing your bot's auth token.
+ * @return Basic information about the bot in form of a User object.
+ */
+ User::Ptr getMe() const;
+
+ /**
+ * Use this method to send text messages.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param text Text of the message to be sent.
+ * @param disableWebPagePreview Optional. Disables link previews for links in this message.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup 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 sendMessage(int32_t chatId, const std::string& text, bool disableWebPagePreview = false, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to forward messages of any kind.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param fromChatId Unique identifier for the chat where the original message was sent — User or GroupChat id.
+ * @param messageId Unique message identifier.
+ * @return On success, the sent message is returned.
+ */
+ Message::Ptr forwardMessage(int32_t chatId, int32_t fromChatId, int32_t messageId) const;
+
+ /**
+ * Use this method to send photos.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param photo Photo to send.
+ * @param caption Optional. Photo caption.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup 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 sendPhoto(int32_t chatId, const InputFile::Ptr& photo, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send photos.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param photo Photo to send. Id of the photo that is already on the Telegram servers.
+ * @param caption Optional. Photo caption.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup 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 sendPhoto(int32_t chatId, const std::string& photo, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document).
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param audio Audio to send.
+ * @param duration Duration of sent audio in seconds.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup 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 sendAudio(int32_t chatId, const InputFile::Ptr& audio, int32_t duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document).
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param audio Id of the audio that is already on the Telegram servers.
+ * @param duration Duration of sent audio in seconds.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup 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 sendAudio(int32_t chatId, const std::string& audio, int32_t duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send general files.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param document Document to send.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup 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 sendDocument(int32_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send general files.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param document Id of the document that is already on the Telegram servers.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup Optional. Additional interface options. 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 sendDocument(int32_t chatId, const std::string& document, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send .webp stickers.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param sticker Sticker to send.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup 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 sendSticker(int32_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send .webp stickers.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param sticker Id of the sticker that is already on the Telegram servers.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
+ * @return On success, the sent message is returned.
+ */
+ Message::Ptr sendSticker(int32_t chatId, const std::string& sticker, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param video Video to send.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup 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 sendVideo(int32_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param video Id of the video that is already on the Telegram servers.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
+ * @return On success, the sent message is returned.
+ */
+ Message::Ptr sendVideo(int32_t chatId, const std::string& video, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method to send point on the map.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param latitude Latitude of location.
+ * @param longitude Longitude of location.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
+ * @return On success, the sent message is returned.
+ */
+ Message::Ptr sendLocation(int32_t chatId, float latitude, float longitude, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
+
+ /**
+ * Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
+ * Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.
+ * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
+ * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data.
+ */
+ void sendChatAction(int32_t chatId, const std::string& action) const;
+
+ /**
+ * Use this method to get a list of profile pictures for a user.
+ * @param userId Unique identifier of the target user.
+ * @param offset Optional. Sequential number of the first photo to be returned. By default, all photos are returned.
+ * @param limit Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
+ * @return A UserProfilePhotos object.
+ */
+ UserProfilePhotos::Ptr getUserProfilePhotos(int32_t userId, int32_t offset = 0, int32_t limit = 100) const;
+
+ /**
+ * Use this method to receive incoming updates using long polling.
+ * This method will not work if an outgoing webhook is set up.
+ * In order to avoid getting duplicate updates, recalculate offset after each server response.
+ * @param offset Optional. Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id.
+ * @param limit Optional. Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.
+ * @param timeout Optional. Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling.
+ * @return An Array of Update objects
+ */
+ std::vector<Update::Ptr> getUpdates(int32_t offset = 0, int32_t limit = 100, int32_t timeout = 0) const;
+
+ /**
+ * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts.
+ * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. www.example.com/<token>. Since nobody else knows your bot‘s token, you can be pretty sure it’s us.
+ * You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.
+ * We currently do not support self-signed certificates.
+ * Ports currently supported for Webhooks: 443, 80, 88, 8443.
+ * @param url Optional. HTTPS url to send updates to. Use an empty string to remove webhook integration.
+ */
+ void setWebhook(const std::string& url = "") const;
+
+private:
+ boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
+
+ const std::string _token;
+};
+
+}
+
+#endif //TGBOT_CPP_API_H
diff --git a/src/tgbot/Bot.h b/include/tgbot/Bot.h
index eeef27a..5e96642 100644
--- a/src/tgbot/Bot.h
+++ b/include/tgbot/Bot.h
@@ -31,24 +31,40 @@
namespace TgBot {
+/**
+ * This object holds other objects specific for this bot instance.
+ * @ingroup general
+ */
class Bot {
public:
explicit Bot(const std::string& token) : _token(token), _api(token), _eventHandler(&_eventBroadcaster) {
}
+ /**
+ * @return Token for accessing api.
+ */
inline const std::string& getToken() const {
return _token;
}
+ /**
+ * @return Object which can execute Telegram Bot API methods.
+ */
inline const Api& getApi() const {
return _api;
}
+ /**
+ * @return Object which holds all event listeners.
+ */
inline EventBroadcaster& getEvents() {
return _eventBroadcaster;
}
+ /**
+ * @return Object which handles new update objects. Usually it's only needed for TgLongPoll, TgWebhookLocalServer and TgWebhookTcpServer objects.
+ */
inline const EventHandler& getEventHandler() const {
return _eventHandler;
}
diff --git a/src/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h
index a6074e8..03d7df1 100644
--- a/src/tgbot/EventBroadcaster.h
+++ b/include/tgbot/EventBroadcaster.h
@@ -34,6 +34,10 @@ namespace TgBot {
class EventHandler;
+/**
+ * This class holds all event listeners.
+ * @ingroup general
+ */
class EventBroadcaster {
friend EventHandler;
@@ -41,18 +45,35 @@ friend EventHandler;
public:
typedef std::function<void (const Message::Ptr&)> MessageListener;
+ /**
+ * Registers listener which receives all messages which the bot can ever receive.
+ * @param listener Listener.
+ */
inline void onAnyMessage(const MessageListener& listener) {
_onAnyMessageListeners.push_back(listener);
}
+ /**
+ * Registers listener which receives all messages with commands (messages with leading '/' char).
+ * @param commandName Command name which listener can handle.
+ * @param listener Listener.
+ */
inline void onCommand(const std::string& commandName, const MessageListener& listener) {
_onCommandListeners[commandName] = listener;
}
+ /**
+ * Registers listener which receives all messages with commands (messages with leading '/' char) which haven't been handled by other listeners.
+ * @param listener Listener.
+ */
inline void onUnknownCommand(const MessageListener& listener) {
_onUnknownCommandListeners.push_back(listener);
}
+ /**
+ * Registers listener which receives all messages without commands (messages with no leading '/' char)
+ * @param listener Listener.
+ */
inline void onNonCommandMessage(const MessageListener& listener) {
_onNonCommandMessageListeners.push_back(listener);
}
diff --git a/src/tgbot/EventHandler.h b/include/tgbot/EventHandler.h
index abcf925..abcf925 100644
--- a/src/tgbot/EventHandler.h
+++ b/include/tgbot/EventHandler.h
diff --git a/src/tgbot/TgException.h b/include/tgbot/TgException.h
index c283a06..6f01fd3 100644
--- a/src/tgbot/TgException.h
+++ b/include/tgbot/TgException.h
@@ -28,6 +28,10 @@
namespace TgBot {
+/**
+ * Exception type which is only thrown when Telegram refuses API request.
+ * @ingroup general
+ */
class TgException : public std::runtime_error {
public:
diff --git a/src/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index 0571c25..0571c25 100644
--- a/src/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
diff --git a/include/tgbot/doxygenMain.h b/include/tgbot/doxygenMain.h
new file mode 100644
index 0000000..9478b4f
--- /dev/null
+++ b/include/tgbot/doxygenMain.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ *
+ * 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_DOXYGENMAIN_H
+#define TGBOT_DOXYGENMAIN_H
+
+/**
+ * @defgroup general
+ * @defgroup types
+ * @defgroup net
+ * @defgroup tools
+ *
+ * @mainpage
+ *
+ * @section Compilation
+ *
+ * Firstly you need to install some dependencies. You have to have boost library at the runtime and cmake at the compilation step to be able to use this library.
+ * On Debian-based distibutives you can do it with these commands:
+ * @code{.sh}
+sudo apt-get install cmake libboost-dev
+ * @endcode
+ *
+ * To compile the library execute this commands:
+ * @code{.sh}
+cd /path/where/you/have/cloned/the/library/repository
+cmake .
+make -j4
+ * @endcode
+ *
+ * That's all. All you have to do now is just link compiled library to your project.
+ *
+ * @section Samples
+ * Simple echo bot which sends everything it recieves:
+ * @code{.cpp}
+int main() {
+ TgBot::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);
+ });
+
+ try {
+ printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str());
+
+ TgBot::TgLongPoll longPoll(bot);
+ while (true) {
+ printf("Long poll started\n");
+ longPoll.start();
+ }
+ } catch (TgBot::TgException& e) {
+ printf("error: %s\n", e.what());
+ }
+
+ return 0;
+}
+ * @endcode
+ *
+ * All samples are located [here](https://github.com/reo7sp/tgbot-cpp/tree/master/samples)
+ *
+ * @section Feedback
+ * Feel free to [https://github.com/reo7sp/tgbot-cpp/issues](create new issues on GitHub) or [https://telegram.me/Reo_SP](contact me on Telegram)
+ */
+
+#endif //TGBOT_DOXYGENMAIN_H
diff --git a/src/tgbot/net/HttpClient.h b/include/tgbot/net/HttpClient.h
index 4b84dc3..d39e108 100644
--- a/src/tgbot/net/HttpClient.h
+++ b/include/tgbot/net/HttpClient.h
@@ -33,11 +33,23 @@
namespace TgBot {
+/**
+ * This class makes http requests.
+ * @ingroup net
+ */
class HttpClient {
public:
+ /**
+ * Returns instance which lives during all application lifetime.
+ */
static HttpClient& getInstance();
+ /**
+ * Sends a request to the url.
+ * If there's no args specified, a GET request will be sent, otherwise a POST request will be sent.
+ * If at least 1 arg is marked as file, the content type of a request will be multipart/form-data, otherwise it will be application/x-www-form-urlencoded.
+ */
std::string makeRequest(const Url& url, const std::vector<HttpReqArg>& args);
private:
diff --git a/src/tgbot/net/HttpParser.h b/include/tgbot/net/HttpParser.h
index dcb857b..dcb857b 100644
--- a/src/tgbot/net/HttpParser.h
+++ b/include/tgbot/net/HttpParser.h
diff --git a/src/tgbot/net/HttpReqArg.h b/include/tgbot/net/HttpReqArg.h
index e906e94..d70e8b5 100644
--- a/src/tgbot/net/HttpReqArg.h
+++ b/include/tgbot/net/HttpReqArg.h
@@ -29,6 +29,10 @@
namespace TgBot {
+/**
+ * This class represents argument in POST http requests.
+ * @ingroup net
+ */
class HttpReqArg {
public:
@@ -38,10 +42,25 @@ public:
{
}
+ /**
+ * Name of an argument.
+ */
std::string name;
+
+ /**
+ * Value of an argument.
+ */
std::string value;
+
+ /**
+ * Should be true if an argument value hold some file contents
+ */
bool isFile = false;
- std::string mimeType;
+
+ /**
+ * Mime type of an argument value. This field makes sense only if isFile is true.
+ */
+ std::string mimeType = "text/plain";
};
}
diff --git a/src/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h
index 92a667a..0a66900 100644
--- a/src/tgbot/net/HttpServer.h
+++ b/include/tgbot/net/HttpServer.h
@@ -31,6 +31,10 @@
namespace TgBot {
+/**
+ * This class handles HTTP requests from the Internet.
+ * @ingroup net
+ */
template<typename Protocol>
class HttpServer {
@@ -43,6 +47,9 @@ public:
HttpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) {
}
+ /**
+ * Starts receiving new connections.
+ */
void start() {
std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(new boost::asio::basic_stream_socket<Protocol>(acceptor->get_io_service()));
std::shared_ptr<Connection<Protocol>> connection(new Connection<Protocol>(socket, _handler));
@@ -53,6 +60,9 @@ public:
_ioService.run();
}
+ /**
+ * Stops receiving new connections.
+ */
void stop() {
_ioService.stop();
}
diff --git a/src/tgbot/net/TgLongPoll.h b/include/tgbot/net/TgLongPoll.h
index 6c5175e..932fc6d 100644
--- a/src/tgbot/net/TgLongPoll.h
+++ b/include/tgbot/net/TgLongPoll.h
@@ -29,12 +29,19 @@
namespace TgBot {
+/**
+ * This class handles long polling and updates parsing.
+ * @ingroup net
+ */
class TgLongPoll {
public:
TgLongPoll(const Api* api, const EventHandler* eventHandler);
TgLongPoll(const Bot& bot);
+ /**
+ * Starts long poll. After new update will come, this method will parse it and send to EventHandler which invokes your listeners. Designed to be executed in a loop.
+ */
void start();
private:
diff --git a/src/tgbot/net/TgWebhookLocalServer.h b/include/tgbot/net/TgWebhookLocalServer.h
index ec99ad7..7835f28 100644
--- a/src/tgbot/net/TgWebhookLocalServer.h
+++ b/include/tgbot/net/TgWebhookLocalServer.h
@@ -27,6 +27,10 @@
namespace TgBot {
+/**
+ * This class setups HTTP server for receiving Telegram Update objects from unix socket.
+ * @ingroup net
+ */
class TgWebhookLocalServer : public TgWebhookServer<boost::asio::local::stream_protocol> {
public:
diff --git a/src/tgbot/net/TgWebhookServer.h b/include/tgbot/net/TgWebhookServer.h
index a8155ff..a8155ff 100644
--- a/src/tgbot/net/TgWebhookServer.h
+++ b/include/tgbot/net/TgWebhookServer.h
diff --git a/src/tgbot/net/TgWebhookTcpServer.h b/include/tgbot/net/TgWebhookTcpServer.h
index 4dc58e1..cac2638 100644
--- a/src/tgbot/net/TgWebhookTcpServer.h
+++ b/include/tgbot/net/TgWebhookTcpServer.h
@@ -27,6 +27,10 @@
namespace TgBot {
+/**
+ * This class setups HTTP server for receiving Telegram Update objects from tcp connections.
+ * @ingroup net
+ */
class TgWebhookTcpServer : public TgWebhookServer<boost::asio::ip::tcp> {
public:
diff --git a/src/tgbot/net/Url.h b/include/tgbot/net/Url.h
index 39ae348..818e934 100644
--- a/src/tgbot/net/Url.h
+++ b/include/tgbot/net/Url.h
@@ -27,15 +27,38 @@
namespace TgBot {
+/**
+ * This class parses a string with the url
+ * @ingroup net
+ */
class Url {
public:
Url(const std::string& url);
+ /**
+ * Protocol part of an url. Example: https://
+ */
std::string protocol;
+
+ /**
+ * Host part of an url. Example: www.example.com
+ */
std::string host;
+
+ /**
+ * Path part of an url including preceding '/' char. Example: /index.html
+ */
std::string path;
+
+ /**
+ * Query part of an url without '?' char. Example: a=1&b=2&c=3
+ */
std::string query;
+
+ /**
+ * Fragment part of an url without '#' char. Example: section1
+ */
std::string fragment;
};
diff --git a/src/tgbot/tools/StringTools.h b/include/tgbot/tools/StringTools.h
index 37ab858..0a01b0d 100644
--- a/src/tgbot/tools/StringTools.h
+++ b/include/tgbot/tools/StringTools.h
@@ -27,15 +27,59 @@
#include <string>
#include <sstream>
+/**
+ * @ingroup tools
+ */
namespace StringTools {
+/**
+ * Checks if first string is starting with second string and vice-versa
+ * @param str1 First string
+ * @param str2 Second string
+ */
bool startsWith(const std::string& str1, const std::string& str2);
+
+/**
+ * Checks if first string is ending with second string and vice-versa
+ * @param str1 First string
+ * @param str2 Second string
+ */
bool endsWith(const std::string& str1, const std::string& str2);
+
+/**
+ * Splits string to smaller substrings which have between them a delimiter. Resulting substrings won't have delimiter.
+ * @param str Source string
+ * @param delimiter Delimiter
+ * @param dest Array to which substrings will be saved.
+ */
void split(const std::string& str, char delimiter, std::vector<std::string>& dest);
+
+/**
+ * Generates pseudo random string. It's recommended to call srand before this method.
+ * @param length Length of resulting string.
+ */
std::string generateRandomString(size_t length);
+
+/**
+ * Performs url encode.
+ * @param value Source url string
+ * @return Encoded url string
+ */
std::string urlEncode(const std::string& value);
+
+/**
+ * Performs url decode.
+ * @param value Encoded url string
+ * @return Decoded url string
+ */
std::string urlDecode(const std::string& value);
+/**
+ * Splits string to smaller substrings which have between them a delimiter. Resulting substrings won't have delimiter.
+ * @param str Source string
+ * @param delimiter Delimiter
+ * @return Array of substrings
+ */
inline std::vector<std::string> split(const std::string& str, char delimiter) {
std::vector<std::string> result;
split(str, delimiter, result);
diff --git a/src/tgbot/types/Audio.h b/include/tgbot/types/Audio.h
index 56374e4..8e255fe 100644
--- a/src/tgbot/types/Audio.h
+++ b/include/tgbot/types/Audio.h
@@ -28,14 +28,33 @@
namespace TgBot {
+/**
+ * This object represents an audio file (voice note).
+ * @ingroup types
+ */
class Audio {
public:
typedef std::shared_ptr<Audio> Ptr;
+ /**
+ * Unique identifier for this file.
+ */
std::string fileId;
+
+ /**
+ * Duration of the audio in seconds as defined by sender.
+ */
int32_t duration;
+
+ /**
+ * Optional. MIME type of the file as defined by sender.
+ */
std::string mimeType;
+
+ /**
+ * Optional. File size.
+ */
int32_t fileSize;
};
diff --git a/src/tgbot/types/Contact.h b/include/tgbot/types/Contact.h
index 1e79e53..dcd90b0 100644
--- a/src/tgbot/types/Contact.h
+++ b/include/tgbot/types/Contact.h
@@ -28,14 +28,33 @@
namespace TgBot {
+/**
+ * This object represents a phone contact.
+ * @ingroup types
+ */
class Contact {
public:
typedef std::shared_ptr<Contact> Ptr;
+ /**
+ * Contact's phone number.
+ */
std::string phoneNumber;
+
+ /**
+ * Contact's first name.
+ */
std::string firstName;
+
+ /**
+ * Optional. Contact's last name.
+ */
std::string lastName;
+
+ /**
+ * Optional. Contact's user identifier in Telegram.
+ */
std::string userId;
};
diff --git a/src/tgbot/types/Document.h b/include/tgbot/types/Document.h
index 6dd32c7..1fd0522 100644
--- a/src/tgbot/types/Document.h
+++ b/include/tgbot/types/Document.h
@@ -30,15 +30,38 @@
namespace TgBot {
+/**
+ * This object represents a general file (as opposed to photos and audio files).
+ * @ingroup types
+ */
class Document {
public:
typedef std::shared_ptr<Document> Ptr;
+ /**
+ * Unique file identifier.
+ */
std::string fileId;
+
+ /**
+ * Optional. Document thumbnail as defined by sender.
+ */
PhotoSize::Ptr thumb;
+
+ /**
+ * Optional. Original filename as defined by sender.
+ */
std::string fileName;
+
+ /**
+ * Optional. MIME type of the file as defined by sender.
+ */
std::string mimeType;
+
+ /**
+ * Optional. File size.
+ */
int32_t fileSize;
};
diff --git a/include/tgbot/types/ForceReply.h b/include/tgbot/types/ForceReply.h
new file mode 100644
index 0000000..237967e
--- /dev/null
+++ b/include/tgbot/types/ForceReply.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ *
+ * 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_CPP_FORCEREPLY_H
+#define TGBOT_CPP_FORCEREPLY_H
+
+#include <memory>
+
+#include "tgbot/types/GenericReply.h"
+
+namespace TgBot {
+
+/**
+ * Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.
+ * Example: A poll bot for groups runs in privacy mode (only receives commands, replies to its messages and mentions). There could be two ways to create a new poll:
+ * Explain the user how to send a command with parameters (e.g. /newpoll question answer1 answer2). May be appealing for hardcore users but lacks modern day polish.
+ * Guide the user through a step-by-step process. ‘Please send me your question’, ‘Cool, now let’s add the first answer option‘, ’Great. Keep adding answer options, then send /done when you‘re ready’.
+ * The last option is definitely more attractive. And if you use ForceReply in your bot‘s questions, it will receive the user’s answers even if it only receives replies, commands and mentions — without any extra work for the user.
+ * @ingroup types
+ */
+class ForceReply : public GenericReply {
+
+public:
+ typedef std::shared_ptr<ForceReply> Ptr;
+
+ /**
+ * Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply'
+ */
+ const bool forceReply = true;
+
+ /**
+ * Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
+ */
+ bool selective;
+};
+
+}
+
+#endif //TGBOT_CPP_FORCEREPLY_H
diff --git a/src/tgbot/types/GenericChat.h b/include/tgbot/types/GenericChat.h
index f641620..b590312 100644
--- a/src/tgbot/types/GenericChat.h
+++ b/include/tgbot/types/GenericChat.h
@@ -27,6 +27,10 @@
namespace TgBot {
+/**
+ * This abstract class is base of everything to which you can send a message.
+ * @ingroup types
+ */
class GenericChat {
public:
@@ -34,6 +38,9 @@ public:
virtual ~GenericChat() { }
+ /**
+ * Unique identifier for this user, bot or group chat
+ */
int32_t id;
};
diff --git a/src/tgbot/types/GenericReply.h b/include/tgbot/types/GenericReply.h
index 5b03ea5..124c83a 100644
--- a/src/tgbot/types/GenericReply.h
+++ b/include/tgbot/types/GenericReply.h
@@ -27,6 +27,10 @@
namespace TgBot {
+/**
+ * This abstract class is base of all keyboard related events.
+ * @ingroup types
+ */
class GenericReply {
public:
diff --git a/src/tgbot/types/GroupChat.h b/include/tgbot/types/GroupChat.h
index e9f1989..5704051 100644
--- a/src/tgbot/types/GroupChat.h
+++ b/include/tgbot/types/GroupChat.h
@@ -30,11 +30,18 @@
namespace TgBot {
+/**
+ * This object represents a group chat.
+ * @ingroup types
+ */
class GroupChat : public GenericChat {
public:
typedef std::shared_ptr<GroupChat> Ptr;
+ /**
+ * Group name.
+ */
std::string title;
};
diff --git a/src/tgbot/types/InputFile.h b/include/tgbot/types/InputFile.h
index 0c92d80..900838d 100644
--- a/src/tgbot/types/InputFile.h
+++ b/include/tgbot/types/InputFile.h
@@ -29,12 +29,23 @@
namespace TgBot {
+/**
+ * This object represents the contents of a file to be uploaded.
+ * @ingroup types
+ */
class InputFile {
public:
typedef std::shared_ptr<InputFile> Ptr;
+ /**
+ * Contents of a file.
+ */
std::string data;
+
+ /**
+ * Mime type of a file.
+ */
std::string mimeType;
};
diff --git a/src/tgbot/types/Location.h b/include/tgbot/types/Location.h
index e689d71..b35fdd7 100644
--- a/src/tgbot/types/Location.h
+++ b/include/tgbot/types/Location.h
@@ -27,12 +27,23 @@
namespace TgBot {
+/**
+ * This object represents a point on the map.
+ * @ingroup types
+ */
class Location {
public:
typedef std::shared_ptr<Location> Ptr;
+ /**
+ * Longitude as defined by sender.
+ */
float longitude;
+
+ /**
+ * Latitude as defined by sender.
+ */
float latitude;
};
diff --git a/src/tgbot/types/Message.h b/include/tgbot/types/Message.h
index 155a66c..de07563 100644
--- a/src/tgbot/types/Message.h
+++ b/include/tgbot/types/Message.h
@@ -40,32 +40,124 @@
namespace TgBot {
+/**
+ * This object represents a message.
+ * @ingroup types
+ */
class Message {
public:
typedef std::shared_ptr<Message> Ptr;
+ /**
+ * Unique message identifier.
+ */
int32_t messageId;
+
+ /**
+ * Sender.
+ */
User::Ptr from;
+
+ /**
+ * Date the message was sent in Unix time.
+ */
int32_t date;
+
+ /**
+ * Conversation the message belongs to — user in case of a private message, GroupChat in case of a group.
+ */
GenericChat::Ptr chat;
+
+ /**
+ * Optional. For forwarded messages, sender of the original message.
+ */
User::Ptr forwardFrom;
+
+ /**
+ * Optional. For forwarded messages, date the original message was sent in Unix time.
+ */
int32_t forwardDate;
+
+ /**
+ * Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
+ */
Message::Ptr replyToMessage;
+
+ /**
+ * Optional. For text messages, the actual UTF-8 text of the message.
+ */
std::string text;
+
+ /**
+ * Optional. Message is an audio file, information about the file.
+ */
Audio::Ptr audio;
+
+ /**
+ * Optional. Message is a general file, information about the file.
+ */
Document::Ptr document;
+
+ /**
+ * Optional. Message is a photo, available sizes of the photo.
+ */
std::vector<PhotoSize::Ptr> photo;
+
+ /**
+ * Optional. Message is a sticker, information about the sticker.
+ */
Sticker::Ptr sticker;
+
+ /**
+ * Optional. Message is a video, information about the video.
+ */
Video::Ptr video;
+
+ /**
+ * Optional. Message is a shared contact, information about the contact.
+ */
Contact::Ptr contact;
+
+ /**
+ * Optional. Message is a shared location, information about the location.
+ */
Location::Ptr location;
+
+ /**
+ * Optional. A new member was added to the group, information about them (this member may be bot itself).
+ */
User::Ptr newChatParticipant;
+
+ /**
+ * Optional. A member was removed from the group, information about them (this member may be bot itself).
+ */
User::Ptr leftChatParticipant;
+
+ /**
+ * Optional. A group title was changed to this value.
+ */
std::string newChatTitle;
+
+ /**
+ * Optional. A group photo was change to this value.
+ */
std::vector<PhotoSize::Ptr> newChatPhoto;
+
+ /**
+ * Optional. Informs that the group photo was deleted.
+ */
bool deleteChatPhoto;
+
+ /**
+ * Optional. Informs that the group has been created.
+ */
bool groupChatCreated;
+
+ /**
+ * Optional. Text description of the photo or the video.
+ */
+ std::string caption;
};
}
diff --git a/src/tgbot/types/PhotoSize.h b/include/tgbot/types/PhotoSize.h
index b048c15..c616423 100644
--- a/src/tgbot/types/PhotoSize.h
+++ b/include/tgbot/types/PhotoSize.h
@@ -28,14 +28,33 @@
namespace TgBot {
+/**
+ * This object represents one size of a photo or a file / sticker thumbnail.
+ * @ingroup types
+ */
class PhotoSize {
public:
typedef std::shared_ptr<PhotoSize> Ptr;
+ /**
+ * Unique identifier for this file.
+ */
std::string fileId;
+
+ /**
+ * Photo width.
+ */
int32_t width;
+
+ /**
+ * Photo height.
+ */
int32_t height;
+
+ /**
+ * Optional. File size.
+ */
int32_t fileSize;
};
diff --git a/src/tgbot/types/ReplyKeyboardHide.h b/include/tgbot/types/ReplyKeyboardHide.h
index f1dc867..18aa101 100644
--- a/src/tgbot/types/ReplyKeyboardHide.h
+++ b/include/tgbot/types/ReplyKeyboardHide.h
@@ -29,12 +29,24 @@
namespace TgBot {
+/**
+ * Upon receiving a message with this object, Telegram clients will hide the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).
+ * @ingroup types
+ */
class ReplyKeyboardHide : public GenericReply {
public:
typedef std::shared_ptr<ReplyKeyboardHide> Ptr;
+ /**
+ * Requests clients to hide the custom keyboard.
+ */
const bool hideKeyboard = true;
+
+ /**
+ * Optional. Use this parameter if you want to hide keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
+ * Example: A user votes in a poll, bot returns confirmation message in reply to the vote and hides keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.
+ */
bool selective;
};
diff --git a/src/tgbot/types/ReplyKeyboardMarkup.h b/include/tgbot/types/ReplyKeyboardMarkup.h
index 84b7799..0f9ce0d 100644
--- a/src/tgbot/types/ReplyKeyboardMarkup.h
+++ b/include/tgbot/types/ReplyKeyboardMarkup.h
@@ -31,14 +31,34 @@
namespace TgBot {
+/**
+ * This object represents a custom keyboard with reply options.
+ * @ingroup types
+ */
class ReplyKeyboardMarkup : public GenericReply {
public:
typedef std::shared_ptr<ReplyKeyboardMarkup> Ptr;
+ /**
+ * Array of button rows, each represented by an Array of Strings.
+ */
std::vector<std::vector<std::string>> keyboard;
+
+ /**
+ * Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
+ */
bool resizeKeyboard;
+
+ /**
+ * Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false.
+ */
bool oneTimeKeyboard;
+
+ /**
+ * Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
+ * Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard.
+ */
bool selective;
};
diff --git a/src/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h
index 7110ef9..c223081 100644
--- a/src/tgbot/types/Sticker.h
+++ b/include/tgbot/types/Sticker.h
@@ -30,15 +30,38 @@
namespace TgBot {
+/**
+ * This object represents a general file (as opposed to photos and audio files).
+ * @ingroup types
+ */
class Sticker {
public:
typedef std::shared_ptr<Sticker> Ptr;
+ /**
+ * Unique file identifier.
+ */
std::string fileId;
+
+ /**
+ * Optional. Sticker width.
+ */
int32_t width;
+
+ /**
+ * Optional. Sticker height.
+ */
int32_t height;
+
+ /**
+ * Optional. Optional. Sticker thumbnail in .webp or .jpg format.
+ */
PhotoSize::Ptr thumb;
+
+ /**
+ * Optional. File size.
+ */
int32_t fileSize;
};
diff --git a/src/tgbot/types/Update.h b/include/tgbot/types/Update.h
index a0b7d50..a4d41a4 100644
--- a/src/tgbot/types/Update.h
+++ b/include/tgbot/types/Update.h
@@ -29,12 +29,23 @@
namespace TgBot {
+/**
+ * This object represents an incoming update.
+ * @ingroup types
+ */
class Update {
public:
typedef std::shared_ptr<Update> Ptr;
+ /**
+ * The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
+ */
int32_t updateId;
+
+ /**
+ * Optional. New incoming message of any kind — text, photo, sticker, etc.
+ */
Message::Ptr message;
};
diff --git a/src/tgbot/types/User.h b/include/tgbot/types/User.h
index 7f0710d..048d20a 100644
--- a/src/tgbot/types/User.h
+++ b/include/tgbot/types/User.h
@@ -30,13 +30,28 @@
namespace TgBot {
+/**
+ * This object represents a Telegram user or bot.
+ * @ingroup types
+ */
class User : public GenericChat {
public:
typedef std::shared_ptr<User> Ptr;
+ /**
+ * User‘s or bot’s first name.
+ */
std::string firstName;
+
+ /**
+ * Optional. User‘s or bot’s last name.
+ */
std::string lastName;
+
+ /**
+ * Optional. User‘s or bot’s username.
+ */
std::string username;
};
diff --git a/src/tgbot/types/UserProfilePhotos.h b/include/tgbot/types/UserProfilePhotos.h
index cef4921..0079d37 100644
--- a/src/tgbot/types/UserProfilePhotos.h
+++ b/include/tgbot/types/UserProfilePhotos.h
@@ -30,12 +30,23 @@
namespace TgBot {
+/**
+ * This object represent a user's profile pictures.
+ * @ingroup types
+ */
class UserProfilePhotos {
public:
typedef std::shared_ptr<UserProfilePhotos> Ptr;
+ /**
+ * Total number of profile pictures the target user has.
+ */
int32_t totalCount;
+
+ /**
+ * Requested profile pictures (in up to 4 sizes each).
+ */
std::vector<std::vector<PhotoSize::Ptr>> photos;
};
diff --git a/src/tgbot/types/Video.h b/include/tgbot/types/Video.h
index 6c2c441..368f3e1 100644
--- a/src/tgbot/types/Video.h
+++ b/include/tgbot/types/Video.h
@@ -30,19 +30,49 @@
namespace TgBot {
+/**
+ * This object represents a video file.
+ * @ingroup types
+ */
class Video {
public:
typedef std::shared_ptr<Video> Ptr;
+ /**
+ * Unique identifier for this file.
+ */
std::string fileId;
+
+ /**
+ * Video width as defined by sender.
+ */
int32_t width;
+
+ /**
+ * Video height as defined by sender.
+ */
int32_t height;
+
+ /**
+ * Duration of the video in seconds as defined by sender.
+ */
int32_t duration;
+
+ /**
+ * Optional. Video thumbnail.
+ */
PhotoSize::Ptr thumb;
+
+ /**
+ * Optional. Mime type of a file as defined by sender
+ */
std::string mimeType;
+
+ /**
+ * Optional. File size.
+ */
int32_t fileSize;
- std::string caption;
};
}
diff --git a/src/tgbot/Api.cpp b/src/tgbot/Api.cpp
index 8da88c8..913401b 100644
--- a/src/tgbot/Api.cpp
+++ b/src/tgbot/Api.cpp
@@ -94,10 +94,13 @@ Message::Ptr Api::sendPhoto(int32_t chatId, const string& photo, const string& c
return TgTypeParser::getInstance().parseMessage(sendRequest("sendPhoto", args).find("result")->second);
}
-Message::Ptr Api::sendAudio(int32_t chatId, const InputFile::Ptr& audio, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendAudio(int32_t chatId, const InputFile::Ptr& audio, int32_t duration = 0, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType));
+ if (duration) {
+ args.push_back(HttpReqArg("duration", duration));
+ }
if (replyToMessageId) {
args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
}
@@ -107,10 +110,13 @@ Message::Ptr Api::sendAudio(int32_t chatId, const InputFile::Ptr& audio, int32_t
return TgTypeParser::getInstance().parseMessage(sendRequest("sendAudio", args).find("result")->second);
}
-Message::Ptr Api::sendAudio(int32_t chatId, const string& audio, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendAudio(int32_t chatId, const string& audio, int32_t duration = 0, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("audio", audio));
+ if (duration) {
+ args.push_back(HttpReqArg("duration", duration));
+ }
if (replyToMessageId) {
args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
}
diff --git a/src/tgbot/Api.h b/src/tgbot/Api.h
deleted file mode 100644
index 384de55..0000000
--- a/src/tgbot/Api.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2015 Oleg Morozenkov
- *
- * 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_CPP_API_H
-#define TGBOT_CPP_API_H
-
-#include <string>
-#include <vector>
-
-#include <boost/property_tree/ptree.hpp>
-
-#include "tgbot/net/HttpReqArg.h"
-#include "tgbot/types/User.h"
-#include "tgbot/types/Message.h"
-#include "tgbot/types/GenericReply.h"
-#include "tgbot/types/InputFile.h"
-#include "tgbot/types/UserProfilePhotos.h"
-#include "tgbot/types/Update.h"
-
-namespace TgBot {
-
-class Bot;
-
-class Api {
-
-friend Bot;
-
-public:
- Api(const std::string& token);
-
- User::Ptr getMe() const;
- Message::Ptr sendMessage(int32_t chatId, const std::string& text, bool disableWebPagePreview = false, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr forwardMessage(int32_t chatId, int32_t fromChatId, int32_t messageId) const;
- Message::Ptr sendPhoto(int32_t chatId, const InputFile::Ptr& photo, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendPhoto(int32_t chatId, const std::string& photo, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendAudio(int32_t chatId, const InputFile::Ptr& audio, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendAudio(int32_t chatId, const std::string& audio, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendDocument(int32_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendDocument(int32_t chatId, const std::string& document, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendSticker(int32_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendSticker(int32_t chatId, const std::string& sticker, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendVideo(int32_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendVideo(int32_t chatId, const std::string& video, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- Message::Ptr sendLocation(int32_t chatId, float latitude, float longitude, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
- void sendChatAction(int32_t chatId, const std::string& action) const;
- UserProfilePhotos::Ptr getUserProfilePhotos(int32_t userId, int32_t offset = 0, int32_t limit = 100) const;
- std::vector<Update::Ptr> getUpdates(int32_t offset = 0, int32_t limit = 100, int32_t timeout = 0) const;
- void setWebhook(const std::string& url = "") const;
-
-private:
- boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
-
- const std::string _token;
-};
-
-}
-
-#endif //TGBOT_CPP_API_H
diff --git a/src/tgbot/TgTypeParser.cpp b/src/tgbot/TgTypeParser.cpp
index 7abcc0e..70588da 100644
--- a/src/tgbot/TgTypeParser.cpp
+++ b/src/tgbot/TgTypeParser.cpp
@@ -99,6 +99,7 @@ Message::Ptr TgTypeParser::parseMessage(const ptree& data) const {
result->newChatPhoto = parseArray<PhotoSize>(parsePhotoSize, data, "new_chat_photo");
result->deleteChatPhoto = data.get("delete_chat_photo", false);
result->groupChatCreated = data.get("group_chat_created", false);
+ result->caption = data.get("caption", false);
return result;
}
@@ -129,6 +130,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "new_chat_photo", parseArray(parsePhotoSize, object->newChatPhoto));
appendToJson(result, "delete_chat_photo", object->deleteChatPhoto);
appendToJson(result, "group_chat_created", object->groupChatCreated);
+ appendToJson(result, "caption", object->caption);
result.erase(result.length() - 1);
result += '}';
return result;
@@ -243,7 +245,6 @@ Video::Ptr TgTypeParser::parseVideo(const ptree& data) const {
result->thumb = parsePhotoSize(data.find("thumb")->second);
result->mimeType = data.get("mime_type", "");
result->fileSize = data.get("file_size", 0);
- result->caption = data.get("caption", "");
return result;
}
@@ -260,7 +261,6 @@ string TgTypeParser::parseVideo(const Video::Ptr& object) const {
appendToJson(result, "thumb", parsePhotoSize(object->thumb));
appendToJson(result, "mime_type", object->mimeType);
appendToJson(result, "file_size", object->fileSize);
- appendToJson(result, "caption", object->caption);
result.erase(result.length() - 1);
result += '}';
return result;
diff --git a/src/tgbot/types/ForceReply.h b/src/tgbot/types/ForceReply.h
deleted file mode 100644
index d0ee706..0000000
--- a/src/tgbot/types/ForceReply.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2015 Oleg Morozenkov
- *
- * 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_CPP_FORCEREPLY_H
-#define TGBOT_CPP_FORCEREPLY_H
-
-#include <memory>
-
-#include "tgbot/types/GenericReply.h"
-
-namespace TgBot {
-
-class ForceReply : public GenericReply {
-
-public:
- typedef std::shared_ptr<ForceReply> Ptr;
-
- const bool forceReply = true;
- bool selective;
-};
-
-}
-
-#endif //TGBOT_CPP_FORCEREPLY_H