From ff8f9a2e745e44d1d00886bee7044f937fcaef88 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Wed, 9 Nov 2016 20:12:33 +0300 Subject: [PATCH] BotApi::send* now return Message, recieved from server. --- include/telebotxx/BotApi.hpp | 10 +++++++--- src/BotApi.cpp | 18 +++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/telebotxx/BotApi.hpp b/include/telebotxx/BotApi.hpp index 3aca14a..9e9a627 100644 --- a/include/telebotxx/BotApi.hpp +++ b/include/telebotxx/BotApi.hpp @@ -2,6 +2,7 @@ #define TELEBOTXX_BOTAPI_H #include "User.hpp" +#include "Message.hpp" #include #include @@ -31,19 +32,22 @@ namespace telebotxx /// \param [in] chat chat identifier /// \param [in] text message text /// \param [in] parseMode parse mode - void sendMessage(const std::string& chat, const std::string& text, ParseMode parseMode = ParseMode::Plain); + /// \return Message object, recieved from the server + Message sendMessage(const std::string& chat, const std::string& text, ParseMode parseMode = ParseMode::Plain); /// \brief Send image /// \param [in] chat chat identifier /// \param [in] filename image location /// \param [in] caption optional photo caption - void sendPhoto(const std::string& chat, const std::string& filename, const std::string& caption = ""); + /// \return Message object, recieved from the server + Message sendPhoto(const std::string& chat, const std::string& filename, const std::string& caption = ""); /// \brief Send image by URL /// \param [in] chat chat identifier /// \param [in] url image URL /// \param [in] caption optional photo caption - void sendPhotoUrl(const std::string& chat, const std::string& url, const std::string& caption = ""); + /// \return Message object, recieved from the server + Message sendPhotoUrl(const std::string& chat, const std::string& url, const std::string& caption = ""); private: class Impl; diff --git a/src/BotApi.cpp b/src/BotApi.cpp index db091ee..f6d4f8e 100644 --- a/src/BotApi.cpp +++ b/src/BotApi.cpp @@ -37,7 +37,7 @@ public: return *parseUser(doc, "result", REQUIRED); } - inline void sendMessage(const std::string& chat, const std::string& text, ParseMode parseMode) + inline Message sendMessage(const std::string& chat, const std::string& text, ParseMode parseMode) { // Construct JSON body using namespace rapidjson; @@ -72,10 +72,10 @@ public: /// \todo Parse message checkResponse(doc); - MessagePtr message = parseMessage(doc, "result", REQUIRED); + return *parseMessage(doc, "result", REQUIRED); } - inline void sendPhoto(const std::string& chat, const std::string& filename, const std::string& caption) + inline Message sendPhoto(const std::string& chat, const std::string& filename, const std::string& caption) { auto r = cpr::Post(cpr::Url{telegramMainUrl_ + "/sendPhoto"}, cpr::Multipart{{"chat_id", chat}, @@ -93,10 +93,10 @@ public: /// \todo Parse message checkResponse(doc); - MessagePtr message = parseMessage(doc, "result", REQUIRED); + return *parseMessage(doc, "result", REQUIRED); } - inline void sendPhotoUrl(const std::string& chat, const std::string& url, const std::string& caption) + inline Message sendPhotoUrl(const std::string& chat, const std::string& url, const std::string& caption) { // Construct JSON body using namespace rapidjson; @@ -128,7 +128,7 @@ public: /// \todo Parse message checkResponse(doc); - MessagePtr message = parseMessage(doc, "result", REQUIRED); + return *parseMessage(doc, "result", REQUIRED); } private: @@ -150,17 +150,17 @@ User BotApi::getMe() return impl_->getMe(); } -void BotApi::sendMessage(const std::string& chat, const std::string& text, ParseMode parseMode) +Message BotApi::sendMessage(const std::string& chat, const std::string& text, ParseMode parseMode) { return impl_->sendMessage(chat, text, parseMode); } -void BotApi::sendPhoto(const std::string& chat, const std::string& filename, const std::string& caption) +Message BotApi::sendPhoto(const std::string& chat, const std::string& filename, const std::string& caption) { return impl_->sendPhoto(chat, filename, caption); } -void BotApi::sendPhotoUrl(const std::string& chat, const std::string& url, const std::string& caption) +Message BotApi::sendPhotoUrl(const std::string& chat, const std::string& url, const std::string& caption) { return impl_->sendPhotoUrl(chat, url, caption); }