diff --git a/include/Telegram/TelegramBot.h b/include/Telegram/TelegramBot.h index ca422dd..ca90464 100644 --- a/include/Telegram/TelegramBot.h +++ b/include/Telegram/TelegramBot.h @@ -38,8 +38,8 @@ namespace Telegram { void addCommand(TCommand); void setWebhook(std::string); void processMessage(std::string); - void sendMessage(std::string, Json::Int64); - void sendMessage(std::string, std::string); + Telegram::Message* sendMessage(std::string, Json::Int64); + Telegram::Message* sendMessage(std::string, std::string); Telegram::Message *sendPhoto(std::string, Json::Int64); Telegram::Message *sendPhoto(std::string, std::string); @@ -55,7 +55,7 @@ namespace Telegram { void init(); void apiRequest(std::string, std::map); - Telegram::Message *apiRequestJson(std::string, std::map); + Json::Value apiRequestJson(std::string, std::map); std::string processCommand(std::string); }; } diff --git a/src/TelegramBot.cc b/src/TelegramBot.cc index dac4402..eb5d97c 100644 --- a/src/TelegramBot.cc +++ b/src/TelegramBot.cc @@ -87,21 +87,25 @@ void Telegram::TelegramBot::processMessage(std::string message) { /** * Send a text message to a user */ -void Telegram::TelegramBot::sendMessage(std::string message, Json::Int64 chat_id) { +Telegram::Message *Telegram::TelegramBot::sendMessage(std::string message, Json::Int64 chat_id) { - this->sendMessage(message, SSTR(chat_id)); + return(this->sendMessage(message, SSTR(chat_id))); } /** * sendMessage sends a simple text message to a given chat (might be a user or a group) */ -void Telegram::TelegramBot::sendMessage(std::string message, std::string chat_id) { +Telegram::Message* Telegram::TelegramBot::sendMessage(std::string message, std::string chat_id) { - std::map params; - params["chat_id"] = chat_id; - params["text"] = message; + std::map params; + Json::Value obj; + + params["chat_id"] = chat_id; + params["text"] = message; - this->apiRequestJson("sendMessage", params); + obj = this->apiRequestJson("sendMessage", params); + + return(new Telegram::Message(obj["result"])); } /** @@ -117,12 +121,16 @@ Telegram::Message* Telegram::TelegramBot::sendPhoto(std::string URL, Json::Int64 */ Telegram::Message* Telegram::TelegramBot::sendPhoto(std::string URL, std::string chat_id) { + Json::Value obj; + std::map params; params["chat_id"] = chat_id; params["photo"] = URL; - return(this->apiRequestJson("sendPhoto", params)); + obj = this->apiRequestJson("sendPhoto", params); + + return(new Telegram::Message(obj["result"])); } Telegram::Message *Telegram::TelegramBot::getMessage() { @@ -181,7 +189,7 @@ void Telegram::TelegramBot::apiRequest(std::string method, std::map parameters) { +Json::Value Telegram::TelegramBot::apiRequestJson(std::string method, std::map parameters) { std::stringstream result; // Stores the result of the api call parameters["method"] = method; @@ -214,7 +222,7 @@ Telegram::Message* Telegram::TelegramBot::apiRequestJson(std::string method, std Json::Value obj; jreader.parse(result.str(), obj); - return (new Telegram::Message(obj["result"])); + return (obj); } std::string Telegram::TelegramBot::processCommand(std::string cmd) {