diff options
Diffstat (limited to 'src/Api.cpp')
-rw-r--r-- | src/Api.cpp | 938 |
1 files changed, 757 insertions, 181 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index 070d72e..c1c86d2 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -40,15 +40,22 @@ vector<Update::Ptr> Api::getUpdates(std::int32_t offset, std::int32_t limit, std return _tgTypeParser.parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); } -void Api::setWebhook(const string& url, const InputFile::Ptr certificate, std::int32_t maxConnection, const StringArrayPtr& allowedUpdates) const { +bool Api::setWebhook(const std::string& url, + InputFile::Ptr certificate, + std::int32_t maxConnection, + const StringArrayPtr& allowedUpdates, + const std::string& ipAddress, + bool dropPendingUpdates) const { vector<HttpReqArg> args; - args.reserve(4); - if (!url.empty()) { - args.emplace_back("url", url); - } + args.reserve(6); + + args.emplace_back("url", url); if (certificate != nullptr) { args.emplace_back("certificate", certificate->data, true, certificate->mimeType, certificate->fileName); } + if (!ipAddress.empty()) { + args.emplace_back("ip_address", ipAddress); + } if (maxConnection != 40) { args.emplace_back("max_connections", maxConnection); } @@ -59,11 +66,21 @@ void Api::setWebhook(const string& url, const InputFile::Ptr certificate, std::i }, *allowedUpdates); args.emplace_back("allowed_updates", allowedUpdatesJson); } + if (dropPendingUpdates) { + args.emplace_back("drop_pending_updates", dropPendingUpdates); + } - sendRequest("setWebhook", args); + return sendRequest("setWebhook").get<bool>("", false); } -bool Api::deleteWebhook() const { +bool Api::deleteWebhook(bool dropPendingUpdates) const { + vector<HttpReqArg> args; + args.reserve(1); + + if (dropPendingUpdates) { + args.emplace_back("drop_pending_updates", dropPendingUpdates); + } + return sendRequest("deleteWebhook").get<bool>("", false); } @@ -84,17 +101,26 @@ User::Ptr Api::getMe() const { return _tgTypeParser.parseJsonAndGetUser(sendRequest("getMe")); } -Message::Ptr Api::sendMessage(boost::variant<std::int64_t, const std::string&> chatId, const std::string& text, bool disableWebPagePreview, - std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& parseMode, - bool disableNotification) const { +Message::Ptr Api::sendMessage(boost::variant<std::int64_t, const std::string&> chatId, + const std::string& text, + bool disableWebPagePreview, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& parseMode, + bool disableNotification, + const std::vector<MessageEntity::Ptr>& entities, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(7); + args.reserve(9); args.emplace_back("chat_id", chatId); args.emplace_back("text", text); if (!parseMode.empty()) { args.emplace_back("parse_mode", parseMode); } + if (!entities.empty()) { + args.emplace_back("entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, entities)); + } if (disableWebPagePreview) { args.emplace_back("disable_web_page_preview", disableWebPagePreview); } @@ -104,6 +130,9 @@ Message::Ptr Api::sendMessage(boost::variant<std::int64_t, const std::string&> c if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } @@ -123,37 +152,101 @@ Message::Ptr Api::forwardMessage(std::int64_t chatId, std::int64_t fromChatId, s return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args)); } -Message::Ptr Api::sendPhoto(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> photo, const string& caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +MessageId::Ptr Api::copyMessage(std::int64_t chatId, std::int64_t fromChatId, std::int32_t messageId, + const std::string& caption, const std::string& parseMode, const std::vector<MessageEntity::Ptr>& captionEntities, + bool disableNotification, std::int32_t replyToMessageId, bool allowSendingWithoutReply, + GenericReply::Ptr replyMarkup) const { vector<HttpReqArg> args; - args.reserve(7); + args.reserve(10); + args.emplace_back("chat_id", chatId); - if (photo.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get<InputFile::Ptr>(photo); - args.emplace_back("photo", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("photo", boost::get<std::string>(photo)); - } + args.emplace_back("from_chat_id", fromChatId); + args.emplace_back("message_id", messageId); if (!caption.empty()) { args.emplace_back("caption", caption); } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities)); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } + + return _tgTypeParser.parseJsonAndGetMessageId(sendRequest("copyMessage", args)); +} + +Message::Ptr Api::sendPhoto(std::int64_t chatId, + boost::variant<InputFile::Ptr, std::string> photo, + const std::string& caption, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& parseMode, + bool disableNotification, + const std::vector<MessageEntity::Ptr>& captionEntities, + bool allowSendingWithoutReply) const { + vector<HttpReqArg> args; + args.reserve(9); + + args.emplace_back("chat_id", chatId); + if (photo.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(photo); + args.emplace_back("photo", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("photo", boost::get<std::string>(photo)); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } if (!parseMode.empty()) { args.emplace_back("parse_mode", parseMode); } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities)); + } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (replyToMessageId) { + args.emplace_back("reply_to_message_id", replyToMessageId); + } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendAudio(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> audio, const string& caption, std::int32_t duration, const string& performer, const string& title, boost::variant<InputFile::Ptr, std::string> thumb, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendAudio(std::int64_t chatId, + boost::variant<InputFile::Ptr, std::string> audio, + const std::string& caption, + std::int32_t duration, + const std::string& performer, + const std::string& title, + boost::variant<InputFile::Ptr, std::string> thumb, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& parseMode, + bool disableNotification, + const std::vector<MessageEntity::Ptr>& captionEntities, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(11); + args.reserve(13); + args.emplace_back("chat_id", chatId); if (audio.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(audio); @@ -164,6 +257,12 @@ Message::Ptr Api::sendAudio(std::int64_t chatId, boost::variant<InputFile::Ptr, if (!caption.empty()) { args.emplace_back("caption", caption); } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities)); + } if (duration) { args.emplace_back("duration", duration); } @@ -182,24 +281,36 @@ Message::Ptr Api::sendAudio(std::int64_t chatId, boost::variant<InputFile::Ptr, args.emplace_back("thumb", thumbStr); } } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendDocument(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> document, boost::variant<InputFile::Ptr, std::string> thumb, const string& caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendDocument(std::int64_t chatId, + boost::variant<InputFile::Ptr, std::string> document, + boost::variant<InputFile::Ptr, std::string> thumb, + const std::string& caption, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& parseMode, + bool disableNotification, + const std::vector<MessageEntity::Ptr>& captionEntities, + bool disableContentTypeDetection, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(8); + args.reserve(11); + args.emplace_back("chat_id", chatId); if (document.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(document); @@ -219,24 +330,48 @@ Message::Ptr Api::sendDocument(std::int64_t chatId, boost::variant<InputFile::Pt if (!caption.empty()) { args.emplace_back("caption", caption); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } if (!parseMode.empty()) { args.emplace_back("parse_mode", parseMode); } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities)); + } + if (disableContentTypeDetection) { + args.emplace_back("disable_content_type_detection", disableContentTypeDetection); + } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (replyToMessageId) { + args.emplace_back("reply_to_message_id", replyToMessageId); + } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDocument", args)); } -Message::Ptr Api::sendVideo(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming, std::int32_t duration, std::int32_t width, std::int32_t height, boost::variant<InputFile::Ptr, std::string> thumb, const string& caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendVideo(std::int64_t chatId, + boost::variant<InputFile::Ptr, std::string> video, + bool supportsStreaming, + std::int32_t duration, + std::int32_t width, + std::int32_t height, + boost::variant<InputFile::Ptr, std::string> thumb, + const std::string& caption, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& parseMode, + bool disableNotification, + const std::vector<MessageEntity::Ptr>& captionEntities, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(12); + args.reserve(14); + args.emplace_back("chat_id", chatId); if (video.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(video); @@ -244,9 +379,6 @@ Message::Ptr Api::sendVideo(std::int64_t chatId, boost::variant<InputFile::Ptr, } else /* std::string */ { args.emplace_back("video", boost::get<std::string>(video)); } - if (supportsStreaming) { - args.emplace_back("supports_streaming", supportsStreaming); - } if (duration) { args.emplace_back("duration", duration); } @@ -268,24 +400,47 @@ Message::Ptr Api::sendVideo(std::int64_t chatId, boost::variant<InputFile::Ptr, if (!caption.empty()) { args.emplace_back("caption", caption); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } if (!parseMode.empty()) { args.emplace_back("parse_mode", parseMode); } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities)); + } + if (supportsStreaming) { + args.emplace_back("supports_streaming", supportsStreaming); + } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (replyToMessageId) { + args.emplace_back("reply_to_message_id", replyToMessageId); + } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendAnimation(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> animation, std::int32_t duration, std::int32_t width, std::int32_t height, boost::variant<InputFile::Ptr, std::string> thumb, const string& caption, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendAnimation(std::int64_t chatId, + boost::variant<InputFile::Ptr, std::string> animation, + std::int32_t duration, + std::int32_t width, + std::int32_t height, + boost::variant<InputFile::Ptr, std::string> thumb, + const std::string& caption, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& parseMode, + bool disableNotification, + const std::vector<MessageEntity::Ptr>& captionEntities, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(11); + args.reserve(13); + args.emplace_back("chat_id", chatId); if (animation.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(animation); @@ -314,24 +469,41 @@ Message::Ptr Api::sendAnimation(std::int64_t chatId, boost::variant<InputFile::P if (!caption.empty()) { args.emplace_back("caption", caption); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } if (!parseMode.empty()) { args.emplace_back("parse_mode", parseMode); } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities)); + } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (replyToMessageId) { + args.emplace_back("reply_to_message_id", replyToMessageId); + } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); } -Message::Ptr Api::sendVoice(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> voice, const string& caption, int duration, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendVoice(std::int64_t chatId, + boost::variant<InputFile::Ptr, std::string> voice, + const std::string& caption, + std::int32_t duration, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& parseMode, + bool disableNotification, + const std::vector<MessageEntity::Ptr>& captionEntities, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(8); + args.reserve(10); + args.emplace_back("chat_id", chatId); if (voice.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(voice); @@ -342,27 +514,43 @@ Message::Ptr Api::sendVoice(std::int64_t chatId, boost::variant<InputFile::Ptr, if (!caption.empty()) { args.emplace_back("caption", caption); } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities)); + } if (duration) { args.emplace_back("duration", duration); } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args)); } -Message::Ptr Api::sendVideoNote(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> videoNote, std::int64_t replyToMessageId, bool disableNotification, std::int32_t duration, std::int32_t length, boost::variant<InputFile::Ptr, std::string> thumb, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendVideoNote(std::int64_t chatId, + boost::variant<InputFile::Ptr, std::string> videoNote, + std::int64_t replyToMessageId, + bool disableNotification, + std::int32_t duration, + std::int32_t length, + boost::variant<InputFile::Ptr, std::string> thumb, + GenericReply::Ptr replyMarkup, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(8); + args.reserve(9); + args.emplace_back("chat_id", chatId); if (videoNote.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(videoNote); @@ -370,9 +558,6 @@ Message::Ptr Api::sendVideoNote(std::int64_t chatId, boost::variant<InputFile::P } else /* std::string */ { args.emplace_back("video_note", boost::get<std::string>(videoNote)); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } if (duration) { args.emplace_back("duration", duration); } @@ -388,52 +573,99 @@ Message::Ptr Api::sendVideoNote(std::int64_t chatId, boost::variant<InputFile::P args.emplace_back("thumb", thumbStr); } } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideoNote", args)); } -vector<Message::Ptr> Api::sendMediaGroup(std::int64_t chatId, const vector<InputMedia::Ptr>& media, bool disableNotification, std::int32_t replyToMessageId) const { +vector<Message::Ptr> Api::sendMediaGroup(std::int64_t chatId, const std::vector<InputMedia::Ptr>& media, bool disableNotification, + std::int32_t replyToMessageId, bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(4); + args.reserve(5); + args.emplace_back("chat_id", chatId); - string mediaJson = _tgTypeParser.parseArray<InputMedia>(&TgTypeParser::parseInputMedia, media); - args.emplace_back("media", mediaJson); - args.emplace_back("disable_notification", disableNotification); - args.emplace_back("reply_to_message_id", replyToMessageId); + args.emplace_back("media", _tgTypeParser.parseArray<InputMedia>(&TgTypeParser::parseInputMedia, media)); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (replyToMessageId != 0) { + args.emplace_back("reply_to_message_id", replyToMessageId); + } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } + return _tgTypeParser.parseJsonAndGetArray<Message>(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); } -Message::Ptr Api::sendLocation(std::int64_t chatId, float latitude, float longitude, std::uint32_t livePeriod, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendLocation(std::int64_t chatId, + float latitude, + float longitude, + std::uint32_t livePeriod, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + bool disableNotification, + float horizontalAccuracy, + std::uint32_t heading, + std::uint32_t proximityAlertRadius, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(7); + args.reserve(11); + args.emplace_back("chat_id", chatId); args.emplace_back("latitude", latitude); args.emplace_back("longitude", longitude); + if (horizontalAccuracy) { + args.emplace_back("horizontal_accuracy", horizontalAccuracy); + } if (livePeriod) { args.emplace_back("live_period", livePeriod); } + if (heading) { + args.emplace_back("heading", heading); + } + if (proximityAlertRadius) { + args.emplace_back("proximity_alert_radius", proximityAlertRadius); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendLocation", args)); } -Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, std::int64_t chatId, std::int32_t messageId, std::int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { +Message::Ptr Api::editMessageLiveLocation(float latitude, + float longitude, + std::int64_t chatId, + std::int32_t messageId, + std::int32_t inlineMessageId, + InlineKeyboardMarkup::Ptr replyMarkup, + float horizontalAccuracy, + std::int32_t heading, + std::int32_t proximityAlertRadius) const { vector<HttpReqArg> args; - args.reserve(6); - args.emplace_back("latitude", latitude); - args.emplace_back("longitude", longitude); + args.reserve(9); + if (chatId) { args.emplace_back("chat_id", chatId); } @@ -443,9 +675,21 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, std:: if (inlineMessageId) { args.emplace_back("inline_message_id", inlineMessageId); } + args.emplace_back("latitude", latitude); + args.emplace_back("longitude", longitude); + if (horizontalAccuracy) { + args.emplace_back("horizontal_accuracy", horizontalAccuracy); + } + if (heading) { + args.emplace_back("heading", heading); + } + if (proximityAlertRadius) { + args.emplace_back("proximity_alert_radius", proximityAlertRadius); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); } @@ -467,9 +711,22 @@ Message::Ptr Api::stopMessageLiveLocation(std::int64_t chatId, std::int32_t mess return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); } -Message::Ptr Api::sendVenue(std::int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, const string& foursquareType, bool disableNotification, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendVenue(std::int64_t chatId, + float latitude, + float longitude, + const std::string& title, + const std::string& address, + const std::string& foursquareId, + const std::string& foursquareType, + bool disableNotification, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& googlePlaceId, + const std::string& googlePlaceType, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(10); + args.reserve(13); + args.emplace_back("chat_id", chatId); args.emplace_back("latitude", latitude); args.emplace_back("longitude", longitude); @@ -481,21 +738,40 @@ Message::Ptr Api::sendVenue(std::int64_t chatId, float latitude, float longitude if (!foursquareType.empty()) { args.emplace_back("foursquare_type", foursquareType); } + if (!googlePlaceId.empty()) { + args.emplace_back("google_place_id", googlePlaceId); + } + if (!googlePlaceType.empty()) { + args.emplace_back("google_place_type", googlePlaceType); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args)); } -Message::Ptr Api::sendContact(std::int64_t chatId, const string& phoneNumber, const string& firstName, const string& lastName, const string& vcard, bool disableNotification, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendContact(std::int64_t chatId, + const std::string& phoneNumber, + const std::string& firstName, + const std::string& lastName, + const std::string& vcard, + bool disableNotification, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(8); + args.reserve(9); + args.emplace_back("chat_id", chatId); args.emplace_back("phone_number", phoneNumber); args.emplace_back("first_name", firstName); @@ -505,25 +781,41 @@ Message::Ptr Api::sendContact(std::int64_t chatId, const string& phoneNumber, co if (!vcard.empty()) { args.emplace_back("vcard", vcard); } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendContact", args)); } -Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, const std::vector<std::string>& options, - bool isAnonymous, const std::string& type, bool allowsMultipleAnswers, - std::int32_t correctOptionId, const std::string& explanation, const std::string& explanationParseMode, - std::int32_t openPeriod, std::int64_t closeDate, bool isClosed, - bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { - vector<HttpReqArg> args; - args.reserve(15); +Message::Ptr Api::sendPoll(std::int64_t chatId, + const std::string& question, + const std::vector<std::string>& options, + bool disableNotification, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + bool isAnonymous, + const std::string& type, + bool allowsMultipleAnswers, + std::int32_t correctOptionId, + const std::string& explanation, + const std::string& explanationParseMode, + const std::vector<MessageEntity::Ptr>& explanationEntities, + std::int32_t openPeriod, + std::int32_t closeDate, + bool isClosed, + bool allowSendingWithoutReply) const { + vector<HttpReqArg> args; + args.reserve(17); args.emplace_back("chat_id", chatId); args.emplace_back("question", question); @@ -548,6 +840,9 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, con if (!explanationParseMode.empty()) { args.emplace_back("explanation_parse_mode", explanationParseMode); } + if (!explanationEntities.empty()) { + args.emplace_back("explanation_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, explanationEntities)); + } if (openPeriod != 0) { args.emplace_back("open_period", openPeriod); } @@ -563,6 +858,9 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, con if (replyToMessageId != 0) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } @@ -570,21 +868,24 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, con return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); } -Message::Ptr Api::sendDice(std::int64_t chatId, const std::string& emoji, bool disableNotification, - std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendDice(std::int64_t chatId, + bool disableNotification, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + const std::string& emoji, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(5); + args.reserve(6); args.emplace_back("chat_id", chatId); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } if (!emoji.empty()) { args.emplace_back("emoji", emoji); } + args.emplace_back("disable_notification", disableNotification); if (replyToMessageId != 0) { args.emplace_back("reply_to_message_id", replyToMessageId); } + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } @@ -592,12 +893,15 @@ Message::Ptr Api::sendDice(std::int64_t chatId, const std::string& emoji, bool d return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args)); } -void Api::sendChatAction(std::int64_t chatId, const string& action) const { +bool Api::sendChatAction(std::int64_t chatId, + const std::string& action) const { vector<HttpReqArg> args; args.reserve(2); + args.emplace_back("chat_id", chatId); args.emplace_back("action", action); - sendRequest("sendChatAction", args); + + return sendRequest("sendChatAction", args).get<bool>("", false); } UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, std::int32_t offset, std::int32_t limit) const { @@ -631,22 +935,29 @@ string Api::downloadFile(const string& filePath, const std::vector<HttpReqArg>& return serverResponse; } -bool Api::kickChatMember(std::int64_t chatId, std::int64_t userId, std::uint64_t untilDate) const { +bool Api::banChatMember(std::int64_t chatId, + std::int64_t userId, + std::uint64_t untilDate, + bool revokeMessages) const { vector<HttpReqArg> args; - args.reserve(3); + args.reserve(4); + args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); - if (untilDate) { - args.emplace_back("until_date", untilDate); - } - return sendRequest("kickChatMember", args).get<bool>("", false); + args.emplace_back("until_date", untilDate); + args.emplace_back("revoke_messages", revokeMessages); + + return sendRequest("banChatMember", args).get<bool>("", false); } -bool Api::unbanChatMember(std::int64_t chatId, std::int64_t userId) const { +bool Api::unbanChatMember(std::int64_t chatId, std::int64_t userId, bool onlyIfBanned) const { vector<HttpReqArg> args; - args.reserve(2); + args.reserve(3); + args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); + args.emplace_back("only_if_banned", onlyIfBanned); + return sendRequest("unbanChatMember", args).get<bool>("", false); } @@ -664,14 +975,29 @@ bool Api::restrictChatMember(std::int64_t chatId, std::int64_t userId, TgBot::Ch return sendRequest("restrictChatMember", args).get<bool>("", false); } -bool Api::promoteChatMember(std::int64_t chatId, std::int64_t userId, bool canChangeInfo, bool canPostMessages, - bool canEditMessages, bool canDeleteMessages, bool canInviteUsers, bool canPinMessages, bool canPromoteMembers) const { +bool Api::promoteChatMember(std::int64_t chatId, + std::int64_t userId, + bool canChangeInfo, + bool canPostMessages, + bool canEditMessages, + bool canDeleteMessages, + bool canInviteUsers, + bool canPinMessages, + bool canPromoteMembers, + bool isAnonymous, + bool canManageChat, + bool canManageVoiceChats, + bool canRestrictMembers) const { vector<HttpReqArg> args; - args.reserve(9); + args.reserve(13); + args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); - if (canChangeInfo) { - args.emplace_back("can_change_info", canChangeInfo); + if (isAnonymous) { + args.emplace_back("is_anonymous", isAnonymous); + } + if (canManageChat) { + args.emplace_back("can_manage_chat", canManageChat); } if (canPostMessages) { args.emplace_back("can_post_messages", canPostMessages); @@ -682,15 +1008,25 @@ bool Api::promoteChatMember(std::int64_t chatId, std::int64_t userId, bool canCh if (canDeleteMessages) { args.emplace_back("can_delete_messages", canDeleteMessages); } + if (canManageVoiceChats) { + args.emplace_back("can_manage_voice_chats", canManageVoiceChats); + } + if (canRestrictMembers) { + args.emplace_back("can_restrict_members", canRestrictMembers); + } + if (canPromoteMembers) { + args.emplace_back("can_promote_members", canPromoteMembers); + } + if (canChangeInfo) { + args.emplace_back("can_change_info", canChangeInfo); + } if (canInviteUsers) { args.emplace_back("can_invite_users", canInviteUsers); } if (canPinMessages) { args.emplace_back("can_pin_messages", canPinMessages); } - if (canPromoteMembers) { - args.emplace_back("can_promote_members", canPromoteMembers); - } + return sendRequest("promoteChatMember", args).get<bool>("", false); } @@ -705,6 +1041,28 @@ bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t user return sendRequest("setChatAdministratorCustomTitle", args).get<bool>("", false); } +bool Api::banChatSenderChat(std::int64_t chatId, + std::int64_t senderChatId) const { + vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("sender_chat_id", senderChatId); + + return sendRequest("banChatSenderChat", args).get<bool>("", false); +} + +bool Api::unbanChatSenderChat(std::int64_t chatId, + std::int64_t senderChatId) const { + vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("sender_chat_id", senderChatId); + + return sendRequest("unbanChatSenderChat", args).get<bool>("", false); +} + bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const { vector<HttpReqArg> args; args.reserve(2); @@ -720,6 +1078,91 @@ string Api::exportChatInviteLink(std::int64_t chatId) const { return sendRequest("exportChatInviteLink", args).get("", ""); } +ChatInviteLink::Ptr Api::createChatInviteLink(std::int64_t chatId, + std::int32_t expireDate, + std::int32_t memberLimit, + const std::string& name, + bool createsJoinRequest) const { + vector<HttpReqArg> args; + args.reserve(5); + + args.emplace_back("chat_id", chatId); + if (!name.empty()) { + args.emplace_back("name", name); + } + if (expireDate != 0) { + args.emplace_back("expire_date", expireDate); + } + if (memberLimit != 0) { + args.emplace_back("member_limit", memberLimit); + } + if (createsJoinRequest) { + args.emplace_back("createsJoinRequest", createsJoinRequest); + } + + return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("createChatInviteLink", args)); +} + +ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId, + std::string inviteLink, + std::int32_t expireDate, + std::int32_t memberLimit, + const std::string& name, + bool createsJoinRequest) const { + vector<HttpReqArg> args; + args.reserve(6); + + args.emplace_back("chat_id", chatId); + args.emplace_back("invite_link", inviteLink); + if (!name.empty()) { + args.emplace_back("name", name); + } + if (expireDate != 0) { + args.emplace_back("expire_date", expireDate); + } + if (memberLimit != 0) { + args.emplace_back("member_limit", memberLimit); + } + if (createsJoinRequest) { + args.emplace_back("createsJoinRequest", createsJoinRequest); + } + + return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("editChatInviteLink", args)); +} + +ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId, + std::string inviteLink) const { + vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("invite_link", inviteLink); + + return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("revokeChatInviteLink", args)); +} + +bool Api::approveChatJoinRequest(std::int64_t chatId, + std::int64_t userId) const { + vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + + return sendRequest("approveChatJoinRequest", args).get<bool>("", false); +} + +bool Api::declineChatJoinRequest(std::int64_t chatId, + std::int64_t userId) const { + vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + + return sendRequest("declineChatJoinRequest", args).get<bool>("", false); +} + bool Api::setChatPhoto(std::int64_t chatId, const InputFile::Ptr photo) const { vector<HttpReqArg> args; args.reserve(2); @@ -762,13 +1205,25 @@ bool Api::pinChatMessage(std::int64_t chatId, std::int32_t messageId, bool disab return sendRequest("pinChatMessage", args).get<bool>("", false); } -bool Api::unpinChatMessage(std::int64_t chatId) const { +bool Api::unpinChatMessage(std::int64_t chatId, std::int32_t messageId) const { vector<HttpReqArg> args; - args.reserve(1); + args.reserve(2); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + return sendRequest("unpinChatMessage", args).get<bool>("", false); } +bool Api::unpinAllChatMessages(std::int64_t chatId) const { + vector<HttpReqArg> args; + args.reserve(1); + + args.emplace_back("chat_id", chatId); + + return sendRequest("unpinAllChatMessages", args).get<bool>("", false); +} + bool Api::leaveChat(std::int64_t chatId) const { vector<HttpReqArg> args; args.reserve(1); @@ -779,7 +1234,9 @@ bool Api::leaveChat(std::int64_t chatId) const { Chat::Ptr Api::getChat(std::int64_t chatId) const { vector<HttpReqArg> args; args.reserve(1); + args.emplace_back("chat_id", chatId); + return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args)); } @@ -790,11 +1247,13 @@ vector<ChatMember::Ptr> Api::getChatAdministrators(std::int64_t chatId) const { return _tgTypeParser.parseJsonAndGetArray<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); } -int32_t Api::getChatMembersCount(std::int64_t chatId) const { +int32_t Api::getChatMemberCount(std::int64_t chatId) const { vector<HttpReqArg> args; args.reserve(1); + args.emplace_back("chat_id", chatId); - return sendRequest("getChatMembersCount", args).get<int32_t>("", 0); + + return sendRequest("getChatMemberCount", args).get<int32_t>("", 0); } ChatMember::Ptr Api::getChatMember(std::int64_t chatId, std::int64_t userId) const { @@ -839,26 +1298,64 @@ bool Api::answerCallbackQuery(const string& callbackQueryId, const string& text, return sendRequest("answerCallbackQuery", args).get<bool>("", false); } -bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands) const { +bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands, + BotCommandScope::Ptr scope, + const std::string& languageCode) const { vector<HttpReqArg> args; - args.reserve(5); + args.reserve(3); - string commandsJson = _tgTypeParser.parseArray<BotCommand>(&TgTypeParser::parseBotCommand, commands); - args.emplace_back("commands", commandsJson); + args.emplace_back("commands", _tgTypeParser.parseArray<BotCommand>(&TgTypeParser::parseBotCommand, commands)); + if (scope != nullptr) { + args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } return sendRequest("setMyCommands", args).get<bool>("", false); } -std::vector<BotCommand::Ptr> Api::getMyCommands() const { - return _tgTypeParser.parseJsonAndGetArray<BotCommand>(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands")); +bool Api::deleteMyCommands(BotCommandScope::Ptr scope, + const std::string& languageCode) const { + vector<HttpReqArg> args; + args.reserve(2); + + if (scope != nullptr) { + args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return sendRequest("deleteMyCommands", args).get<bool>("", false); } -Message::Ptr Api::editMessageText(const string& text, std::int64_t chatId, std::int32_t messageId, const string& inlineMessageId, - const string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const { +std::vector<BotCommand::Ptr> Api::getMyCommands(BotCommandScope::Ptr scope, + const std::string& languageCode) const { + vector<HttpReqArg> args; + args.reserve(2); +; + if (scope != nullptr) { + args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return _tgTypeParser.parseJsonAndGetArray<BotCommand>(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands", args)); +} +Message::Ptr Api::editMessageText(const std::string& text, + std::int64_t chatId, + std::int32_t messageId, + const std::string& inlineMessageId, + const std::string& parseMode, + bool disableWebPagePreview, + GenericReply::Ptr replyMarkup, + const std::vector<MessageEntity::Ptr>& entities) const { vector<HttpReqArg> args; - args.reserve(7); - args.emplace_back("text", text); + args.reserve(8); + if (chatId) { args.emplace_back("chat_id", chatId); } @@ -868,15 +1365,20 @@ Message::Ptr Api::editMessageText(const string& text, std::int64_t chatId, std:: if (!inlineMessageId.empty()) { args.emplace_back("inline_message_id", inlineMessageId); } + args.emplace_back("text", text); if (!parseMode.empty()) { args.emplace_back("parse_mode", parseMode); } + if (!entities.empty()) { + args.emplace_back("entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, entities)); + } if (disableWebPagePreview) { args.emplace_back("disable_web_page_preview", disableWebPagePreview); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } + ptree p = sendRequest("editMessageText", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); @@ -885,25 +1387,38 @@ Message::Ptr Api::editMessageText(const string& text, std::int64_t chatId, std:: } } -Message::Ptr Api::editMessageCaption(std::int64_t chatId, std::int32_t messageId, const string& caption, - const string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::editMessageCaption(std::int64_t chatId, + std::int32_t messageId, + const std::string& caption, + const std::string& inlineMessageId, + GenericReply::Ptr replyMarkup, + const std::string& parseMode, + const std::vector<MessageEntity::Ptr>& captionEntities) const { vector<HttpReqArg> args; - args.reserve(5); + args.reserve(7); + if (chatId) { args.emplace_back("chat_id", chatId); } if (messageId) { args.emplace_back("message_id", messageId); } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } if (!caption.empty()) { args.emplace_back("caption", caption); } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } + ptree p = sendRequest("editMessageCaption", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); @@ -978,9 +1493,15 @@ void Api::deleteMessage(std::int64_t chatId, std::int32_t messageId) const { sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) }); } -Message::Ptr Api::sendSticker(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> sticker, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendSticker(std::int64_t chatId, + boost::variant<InputFile::Ptr, std::string> sticker, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + bool disableNotification, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(5); + args.reserve(6); + args.emplace_back("chat_id", chatId); if (sticker.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(sticker); @@ -988,22 +1509,28 @@ Message::Ptr Api::sendSticker(std::int64_t chatId, boost::variant<InputFile::Ptr } else /* std::string */ { args.emplace_back("sticker", boost::get<std::string>(sticker)); } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendSticker", args)); } StickerSet::Ptr Api::getStickerSet(const string& name) const { vector<HttpReqArg> args; args.reserve(1); + args.emplace_back("name", name); + return _tgTypeParser.parseJsonAndGetStickerSet(sendRequest("getStickerSet", args)); } @@ -1015,9 +1542,14 @@ File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSt return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); } -bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, - const std::string& emojis, boost::variant<InputFile::Ptr, std::string> pngSticker, boost::variant<InputFile::Ptr, std::string> tgsSticker, - bool containsMasks, MaskPosition::Ptr maskPosition) const { +bool Api::createNewStickerSet(std::int64_t userId, + const std::string& name, + const std::string& title, + const std::string& emojis, + bool containsMasks, + MaskPosition::Ptr maskPosition, + boost::variant<InputFile::Ptr, std::string> pngSticker, + boost::variant<InputFile::Ptr, std::string> tgsSticker) const { vector<HttpReqArg> args; args.reserve(8); @@ -1047,8 +1579,12 @@ bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, cons return sendRequest("createNewStickerSet", args).get<bool>("", false); } -bool Api::addStickerToSet(std::int64_t userId, const std::string& name, const std::string& emojis, - boost::variant<InputFile::Ptr, std::string> pngSticker, boost::variant<InputFile::Ptr, std::string> tgsSticker, MaskPosition::Ptr maskPosition) const { +bool Api::addStickerToSet(std::int64_t userId, + const std::string& name, + const std::string& emojis, + MaskPosition::Ptr maskPosition, + boost::variant<InputFile::Ptr, std::string> pngSticker, + boost::variant<InputFile::Ptr, std::string> tgsSticker) const { vector<HttpReqArg> args; args.reserve(6); @@ -1130,23 +1666,51 @@ bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector<Inlin return sendRequest("answerInlineQuery", args).get<bool>("", false); } -Message::Ptr Api::sendInvoice(std::int64_t chatId, const std::string& title, const std::string& description, const std::string& payload, - const std::string& providerToken, const std::string& startParameter, const std::string& currency, const std::vector<LabeledPrice::Ptr>& prices, - const std::string& providerData, const std::string& photoUrl, std::int32_t photoSize, - std::int32_t photoWidth, std::int32_t photoHeight, bool needName, - bool needPhoneNumber, bool needEmail, bool needShippingAddress, - bool sendPhoneNumberToProvider, bool sendEmailToProvider, bool isFlexible, - std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { - vector<HttpReqArg> args; - args.reserve(23); +Message::Ptr Api::sendInvoice(std::int64_t chatId, + const std::string& title, + const std::string& description, + const std::string& payload, + const std::string& providerToken, + const std::string& currency, + const std::vector<LabeledPrice::Ptr>& prices, + const std::string& providerData, + const std::string& photoUrl, + std::int32_t photoSize, + std::int32_t photoWidth, + std::int32_t photoHeight, + bool needName, + bool needPhoneNumber, + bool needEmail, + bool needShippingAddress, + bool sendPhoneNumberToProvider, + bool sendEmailToProvider, + bool isFlexible, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + bool disableNotification, + bool allowSendingWithoutReply, + std::int32_t maxTipAmount, + const std::vector<std::int32_t>& suggestedTipAmounts, + const std::string& startParameter) const { + vector<HttpReqArg> args; + args.reserve(26); + args.emplace_back("chat_id", chatId); args.emplace_back("title", title); args.emplace_back("description", description); args.emplace_back("payload", payload); args.emplace_back("provider_token", providerToken); - args.emplace_back("start_parameter", startParameter); args.emplace_back("currency", currency); args.emplace_back("prices", _tgTypeParser.parseArray<LabeledPrice>(&TgTypeParser::parseLabeledPrice, prices)); + args.emplace_back("max_tip_amount", maxTipAmount); + if (!suggestedTipAmounts.empty()) { + args.emplace_back("suggested_tip_amounts", _tgTypeParser.parseArray<std::int32_t>([] (const std::int32_t& option) -> std::int32_t { + return option; + }, suggestedTipAmounts)); + } + if (!startParameter.empty()) { + args.emplace_back("start_parameter", startParameter); + } if (!providerData.empty()) { args.emplace_back("provider_data", providerData); } @@ -1183,15 +1747,19 @@ Message::Ptr Api::sendInvoice(std::int64_t chatId, const std::string& title, con if (isFlexible) { args.emplace_back("is_flexible", isFlexible); } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendInvoice", args)); } @@ -1230,20 +1798,30 @@ bool Api::setPassportDataErrors(std::int64_t userId, const std::vector<PassportE return sendRequest("setPassportDataErrors", args).get<bool>("", false); } -Message::Ptr Api::sendGame(std::int64_t chatId, const std::string& gameShortName, std::int32_t replyToMessageId, const InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendGame(std::int64_t chatId, + const std::string& gameShortName, + std::int32_t replyToMessageId, + InlineKeyboardMarkup::Ptr replyMarkup, + bool disableNotification, + bool allowSendingWithoutReply) const { vector<HttpReqArg> args; - args.reserve(5); + args.reserve(6); + args.emplace_back("chat_id", chatId); args.emplace_back("game_short_name", gameShortName); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendGame", args)); } @@ -1270,17 +1848,14 @@ Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool for return _tgTypeParser.parseJsonAndGetMessage(sendRequest("setGameScore", args)); } -vector<GameHighScore::Ptr> Api::getGameHighScores(std::int64_t userId, std::int32_t score, bool force, bool disableEditMessage, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const { +vector<GameHighScore::Ptr> Api::getGameHighScores(std::int64_t userId, + std::int64_t chatId, + std::int32_t messageId, + const std::string& inlineMessageId) const { vector<HttpReqArg> args; - args.reserve(7); + args.reserve(4); + args.emplace_back("user_id", userId); - args.emplace_back("score", score); - if (force) { - args.emplace_back("force", force); - } - if (disableEditMessage) { - args.emplace_back("disable_edit_message", disableEditMessage); - } if (chatId) { args.emplace_back("chat_id", chatId); } @@ -1290,6 +1865,7 @@ vector<GameHighScore::Ptr> Api::getGameHighScores(std::int64_t userId, std::int3 if (!inlineMessageId.empty()) { args.emplace_back("inline_message_id", inlineMessageId); } + return _tgTypeParser.parseJsonAndGetArray<GameHighScore>(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args)); } |