diff options
author | Andrea Giove <andreagiove@outlook.com> | 2016-04-16 22:38:00 +0200 |
---|---|---|
committer | Andrea Giove <andreagiove@outlook.com> | 2016-04-16 22:38:00 +0200 |
commit | 730407e8df5031d19a097be4e3e597f2f3b868fd (patch) | |
tree | 610cbc5a27b10c0a2152eaaec0210ff2aec161ee | |
parent | abbd611b34ccb5f77c1c28160294f1481c9479c2 (diff) |
Added sendVoice method and update sendAudio method
-rw-r--r-- | include/tgbot/Api.h | 36 | ||||
-rw-r--r-- | src/Api.cpp | 54 |
2 files changed, 86 insertions, 4 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 0670ea0..d7cfc0e 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -112,12 +112,15 @@ public: * @param chatId Unique identifier for the target chat. * @param audio Audio to send. * @param duration Duration of sent audio in seconds. + * @param performer Performer + * @param title Track name * @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 sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration = 0, int32_t replyToMessageId = 0, + Message::Ptr sendAudio(int64_t chatId, const InputFile::Ptr& audio, 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; /** @@ -125,12 +128,15 @@ public: * @param chatId Unique identifier for the target chat. * @param audio Id of the audio that is already on the Telegram servers. * @param duration Duration of sent audio in seconds. + * @param performer Performer + * @param title Track name * @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 sendAudio(int64_t chatId, const std::string& audioId, int32_t duration = 0, int32_t replyToMessageId = 0, + Message::Ptr sendAudio(int64_t chatId, const std::string& audioId, 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; /** @@ -206,6 +212,32 @@ public: 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 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, + 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 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, + const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + + /** * Use this method to send point on the map. * @param chatId Unique identifier for the target chat. * @param latitude Latitude of location. 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<HttpReqArg> 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<HttpReqArg> 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<HttpReqArg> 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<HttpReqArg> 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<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); |