From 45f46c60f6253a4b7c0cebf047983dd7cfce1683 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Wed, 6 Apr 2016 18:26:16 +0200 Subject: Added certificate to setWebhook method --- src/Api.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index ed06d27..4070230 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -249,9 +249,13 @@ vector Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo return TgTypeParser::getInstance().parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); } -void Api::setWebhook(const string& url) const { +void Api::setWebhook(const string& url, const InputFile::Ptr& certificate) const { vector args; - args.push_back(HttpReqArg("url", url)); + if (!url.empty()) + args.push_back(HttpReqArg("url", url)); + if (certificate != nullptr) + args.push_back(HttpReqArg("certificate", certificate->data, true, certificate->mimeType, certificate->fileName)); + sendRequest("setWebhook", args); } -- cgit v1.2.3 From abbd611b34ccb5f77c1c28160294f1481c9479c2 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sat, 16 Apr 2016 22:23:38 +0200 Subject: Added the disable_method parameter to all methods --- src/Api.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 13 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 4070230..087b742 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -38,13 +38,16 @@ User::Ptr Api::getMe() const { return TgTypeParser::getInstance().parseJsonAndGetUser(sendRequest("getMe")); } -Message::Ptr Api::sendMessage(int64_t chatId, const string& text, bool disableWebPagePreview, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendMessage(int64_t chatId, const string& text, bool disableWebPagePreview, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("text", text)); if (disableWebPagePreview) { args.push_back(HttpReqArg("disable_web_page_preview", disableWebPagePreview)); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -54,15 +57,18 @@ Message::Ptr Api::sendMessage(int64_t chatId, const string& text, bool disableWe return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendMessage", args)); } -Message::Ptr Api::forwardMessage(int64_t chatId, int64_t fromChatId, int32_t messageId) const { +Message::Ptr Api::forwardMessage(int64_t chatId, int64_t fromChatId, int32_t messageId, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("from_chat_id", fromChatId)); args.push_back(HttpReqArg("message_id", messageId)); + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("forwardMessage", args)); } -Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr& photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr& photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName)); @@ -75,10 +81,13 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr& photo, const s if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("photo", photoId)); @@ -91,10 +100,13 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName)); @@ -107,10 +119,13 @@ Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audioId)); @@ -123,10 +138,13 @@ Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t durat if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("document", document->data, true, document->mimeType, document->fileName)); @@ -136,10 +154,13 @@ Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, i if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args)); } -Message::Ptr Api::sendDocument(int64_t chatId, const string& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendDocument(int64_t chatId, const string& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("document", document)); @@ -149,10 +170,13 @@ Message::Ptr Api::sendDocument(int64_t chatId, const string& document, int32_t r if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args)); } -Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("sticker", sticker->data, true, sticker->mimeType, sticker->fileName)); @@ -162,10 +186,13 @@ Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr& sticker, int if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args)); } -Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("sticker", stickerId)); @@ -175,10 +202,13 @@ Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t r if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args)); } -Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video", video->data, true, video->mimeType, video->fileName)); @@ -188,10 +218,13 @@ Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video", videoId)); @@ -201,10 +234,13 @@ Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t reply if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { +Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("latitude", latitude)); @@ -215,6 +251,9 @@ Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, if (replyMarkup) { args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendLocation", args)); } -- cgit v1.2.3 From 730407e8df5031d19a097be4e3e597f2f3b868fd Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sat, 16 Apr 2016 22:38:00 +0200 Subject: Added sendVoice method and update sendAudio method --- src/Api.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 087b742..3ae582c 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -106,13 +106,19 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName)); if (duration) { args.push_back(HttpReqArg("duration", duration)); } + if (!performer.empty()){ + args.push_back(HttpReqArg("performer", performer)); + } + if (!title.empty()){ + args.push_back(HttpReqArg("title", title)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -125,13 +131,19 @@ Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audioId)); if (duration) { args.push_back(HttpReqArg("duration", duration)); } + if (!performer.empty()){ + args.push_back(HttpReqArg("performer", performer)); + } + if (!title.empty()){ + args.push_back(HttpReqArg("title", title)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -240,6 +252,44 @@ Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t reply return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } +Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr& voice, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("voice", voice->data, true, voice->mimeType, voice->fileName)); + if (duration){ + args.push_back(HttpReqArg("duration", duration)); + } + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); +} + +Message::Ptr Api::sendVoice(int64_t chatId, const std::string& voiceId, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("voice", voiceId)); + if (duration){ + args.push_back(HttpReqArg("duration", duration)); + } + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); +} + Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); -- cgit v1.2.3 From 9ba69d7e87c9b8ff9997294b68550852ef0274b8 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sun, 17 Apr 2016 22:09:52 +0200 Subject: Added new type: Venue, MessageEntity Update Message type Added new method: sendVenue, sendContact, kickChatMember, unbanChatMember --- src/Api.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 3ae582c..55c0320 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -307,6 +307,46 @@ Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendLocation", args)); } +Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, std::string title, std::string address, std::string foursquareId, bool disableNotification, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("latitude", latitude)); + args.push_back(HttpReqArg("longitude", longitude)); + args.push_back(HttpReqArg("title", title)); + args.push_back(HttpReqArg("address", address)); + if (!foursquareId.empty()) { + args.push_back(HttpReqArg("foursquare_id", foursquareId)); + } + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVenue", args)); +} + +Message::Ptr Api::sendContact(int64_t chatId, std::string phoneNumber, std::string firstName, std::string lastName, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("phone_number", phoneNumber)); + args.push_back(HttpReqArg("first_name", firstName)); + args.push_back(HttpReqArg("last_name", lastName)); + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendContact", args)); +} + void Api::sendChatAction(int64_t chatId, const string& action) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); @@ -360,6 +400,20 @@ void Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector< sendRequest("answerInlineQuery", args); } +void Api::kickChatMember(int64_t chatId, int32_t userId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + sendRequest("kickChatMember", args); +} + +void Api::unbanChatMember(int64_t chatId, int32_t userId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + sendRequest("unbanChatMember", args); +} + ptree Api::sendRequest(const string& method, const vector& args) const { string url = "https://api.telegram.org/bot"; -- cgit v1.2.3