summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tgbot/Api.h33
-rw-r--r--src/Api.cpp39
2 files changed, 49 insertions, 23 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 9142fef..693eb21 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -558,7 +558,7 @@ public:
*
* @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message with live location to stop
- * @param inlineMessageId Optional. Required if chatId and message_id are not specified. Identifier of the inline message
+ * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message
* @param replyMarkup Optional. A JSON-serialized object for a new inline keyboard.
*
* @return On success, the edited Message is returned.
@@ -743,17 +743,6 @@ public:
File::Ptr getFile(const std::string& fileId) const;
/**
- * @brief Download a file from Telegram and save it in memory.
- *
- * @param filePath Telegram file path from Api::getFile
- * @param args Additional api parameters
- *
- * @return File content in a string.
- */
- std::string downloadFile(const std::string& filePath,
- const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
-
- /**
* @brief Use this method to ban a user in a group, a supergroup or a channel.
*
* In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first.
@@ -1769,6 +1758,26 @@ public:
std::int64_t chatId = 0,
std::int32_t messageId = 0,
const std::string& inlineMessageId = "") const;
+
+ /**
+ * @brief Download a file from Telegram and save it in memory.
+ *
+ * @param filePath Telegram file path from Api::getFile
+ * @param args Additional api parameters
+ *
+ * @return File content in a string.
+ */
+ std::string downloadFile(const std::string& filePath,
+ const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
+
+ /**
+ * @brief Check if user has blocked the bot
+ *
+ * @param chatId Unique identifier for the target chat
+ *
+ * @return Returns True if bot is blocked by user
+ */
+ bool blockedByUser(std::int64_t chatId) const;
private:
boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
diff --git a/src/Api.cpp b/src/Api.cpp
index ea9a550..875a79a 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -1024,17 +1024,6 @@ File::Ptr Api::getFile(const std::string& fileId) const {
return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args));
}
-std::string Api::downloadFile(const std::string& filePath,
- const std::vector<HttpReqArg>& args) const {
- std::string url(_url);
- url += "/file/bot";
- url += _token;
- url += "/";
- url += filePath;
-
- return _httpClient.makeRequest(url, args);
-}
-
bool Api::banChatMember(boost::variant<std::int64_t, const std::string&> chatId,
std::int64_t userId,
std::int32_t untilDate,
@@ -2243,6 +2232,34 @@ std::vector<GameHighScore::Ptr> Api::getGameHighScores(std::int64_t userId,
return _tgTypeParser.parseJsonAndGetArray<GameHighScore>(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args));
}
+std::string Api::downloadFile(const std::string& filePath,
+ const std::vector<HttpReqArg>& args) const {
+ std::string url(_url);
+ url += "/file/bot";
+ url += _token;
+ url += "/";
+ url += filePath;
+
+ return _httpClient.makeRequest(url, args);
+}
+
+bool Api::blockedByUser(std::int64_t chatId) const {
+ bool isBotBlocked = false;
+
+ try {
+ sendChatAction(chatId, "typing");
+
+ } catch (std::exception& e) {
+ std::string error = e.what();
+
+ if (error.compare("Forbidden: bot was blocked by the user") == 0) {
+ isBotBlocked = true;
+ }
+ }
+
+ return isBotBlocked;
+}
+
boost::property_tree::ptree Api::sendRequest(const std::string& method, const std::vector<HttpReqArg>& args) const {
std::string url(_url);
url += "/bot";