diff options
-rw-r--r-- | include/tgbot/Api.h | 34 | ||||
-rw-r--r-- | src/Api.cpp | 58 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 6 |
3 files changed, 77 insertions, 21 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 928a017..55a09cb 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -115,6 +115,7 @@ public: * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. * @param audio Audio to send. + * @param caption Audio caption, 0-200 characters * @param duration Duration of sent audio in seconds. * @param performer Performer * @param title Track name @@ -123,7 +124,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration = 0, + Message::Ptr sendAudio(int64_t chatId, const InputFile::Ptr& audio, const std::string &caption = "", int32_t duration = 0, const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; @@ -131,6 +132,7 @@ public: * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. * @param audio Id of the audio that is already on the Telegram servers. + * @param caption Audio caption, 0-200 characters * @param duration Duration of sent audio in seconds. * @param performer Performer * @param title Track name @@ -139,7 +141,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(int64_t chatId, const std::string& audioId, int32_t duration = 0, + Message::Ptr sendAudio(int64_t chatId, const std::string& audioId, const std::string &caption = "", int32_t duration = 0, const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; @@ -147,24 +149,26 @@ public: * Use this method to send general files. * @param chatId Unique identifier for the target chat. * @param document Document to send. + * @param caption Document caption (may also be used when resending documents by file_id), 0-200 characters * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(int64_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId = 0, + Message::Ptr sendDocument(int64_t chatId, const InputFile::Ptr& document, const std::string &caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** * Use this method to send general files. * @param chatId Unique identifier for the target chat. * @param document Id of the document that is already on the Telegram servers. + * @param caption Document caption (may also be used when resending documents by file_id), 0-200 characters * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(int64_t chatId, const std::string& documentId, int32_t replyToMessageId = 0, + Message::Ptr sendDocument(int64_t chatId, const std::string& documentId, const std::string &caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** @@ -195,50 +199,60 @@ public: * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. * @param video Video to send. + * @param duration Duration of sent video in seconds + * @param width Video width + * @param height Video height + * @param caption Video caption (may also be used when resending videos by file_id), 0-200 characters * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId = 0, - const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "", + int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. * @param video Id of the video that is already on the Telegram servers. + * @param duration Duration of sent video in seconds + * @param width Video width + * @param height Video height + * @param caption Video caption (may also be used when resending videos by file_id), 0-200 characters * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVideo(int64_t chatId, const std::string& videoId, int32_t replyToMessageId = 0, - const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + Message::Ptr sendVideo(int64_t chatId, const std::string& videoId, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "", + int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. * @param chatId Unique identifier for the target chat. * @param voice Audio file to send. + * @param caption Voice message caption, 0-200 characters * @param duration Duration of send audio in seconds. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVoice(int64_t chatId, const InputFile::Ptr& voice, int duration = 0, int32_t replyToMessageId = 0, + Message::Ptr sendVoice(int64_t chatId, const InputFile::Ptr& voice, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. * @param chatId Unique identifier for the target chat. * @param voiceId Id of the voice that is already on the Telegram servers. + * @param caption Voice message caption, 0-200 characters * @param duration Duration of send audio in seconds. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVoice(int64_t chatId, const std::string& voiceId, int duration = 0, int32_t replyToMessageId = 0, + Message::Ptr sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** diff --git a/src/Api.cpp b/src/Api.cpp index c4baa2b..451a8c0 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -109,10 +109,13 @@ 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, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, const std::string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (duration) { args.push_back(HttpReqArg("duration", duration)); } @@ -134,10 +137,13 @@ 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, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const std::string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audioId)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (duration) { args.push_back(HttpReqArg("duration", duration)); } @@ -159,10 +165,13 @@ Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t durat 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, bool disableNotification) const { +Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("document", document->data, true, document->mimeType, document->fileName)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -175,10 +184,13 @@ Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, i return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args)); } -Message::Ptr Api::sendDocument(int64_t chatId, const string& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("document", document)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -223,10 +235,22 @@ Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t r 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, bool disableNotification) const { +Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t duration, int32_t width, int32_t height, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video", video->data, true, video->mimeType, video->fileName)); + if (duration) { + args.push_back(HttpReqArg("duration", duration)); + } + if (width) { + args.push_back(HttpReqArg("width", width)); + } + if (height) { + args.push_back(HttpReqArg("height", height)); + } + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -239,10 +263,22 @@ Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t duration, int32_t width, int32_t height, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video", videoId)); + if (duration) { + args.push_back(HttpReqArg("duration", duration)); + } + if (width) { + args.push_back(HttpReqArg("width", width)); + } + if (height) { + args.push_back(HttpReqArg("height", height)); + } + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -255,10 +291,13 @@ 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 { +Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr& voice, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("voice", voice->data, true, voice->mimeType, voice->fileName)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (duration){ args.push_back(HttpReqArg("duration", duration)); } @@ -274,10 +313,13 @@ Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr& voice, int dur 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 { +Message::Ptr Api::sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("voice", voiceId)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (duration){ args.push_back(HttpReqArg("duration", duration)); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 20b8ea2..45124e2 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1411,13 +1411,13 @@ InputMessageContent::Ptr TgTypeParser::parseJsonAndGetInputMessageContent(const string tTitle = data.get<string>("title", ""); string tPnoneNumber = data.get<string>("phone_number", ""); - if (tMessageText != std::string("")) { + if (!tMessageText.empty()) { result = static_pointer_cast<InputMessageContent>(parseJsonAndGetInputTextMessageContent(data)); - } else if (tTitle !=std::string("")) { + } else if (!tTitle.empty()) { result = static_pointer_cast<InputMessageContent>(parseJsonAndGetInputVenueMessageContent(data)); } else if (tLatitude != 1000) { result = static_pointer_cast<InputMessageContent>(parseJsonAndGetInputLocationMessageContent(data)); - } else if (tPnoneNumber!= std::string("")) { + } else if (!tPnoneNumber.empty()) { result = static_pointer_cast<InputMessageContent>(parseJsonAndGetInputContactMessageContent(data)); } |