From 2960435ac64dcacd6d30a67b0387487a55c81531 Mon Sep 17 00:00:00 2001 From: Gravechapa Date: Sat, 23 Feb 2019 16:52:45 +0300 Subject: Fix curl client issue https://github.com/reo7sp/tgbot-cpp/issues/84 --- src/net/CurlHttpClient.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/net/CurlHttpClient.cpp b/src/net/CurlHttpClient.cpp index 932fd68..8b1aec4 100644 --- a/src/net/CurlHttpClient.cpp +++ b/src/net/CurlHttpClient.cpp @@ -37,10 +37,8 @@ CurlHttpClient::~CurlHttpClient() { } static size_t curlWriteString(char* ptr, size_t size, size_t nmemb, void* userdata) { - std::string &s = *(std::string *)userdata; - auto read = size * nmemb; - s.append(ptr, ptr + read); - return read; + static_cast(userdata)->append(ptr, size * nmemb); + return size * nmemb; }; std::string CurlHttpClient::makeRequest(const Url& url, const std::vector& args) const { @@ -56,18 +54,21 @@ std::string CurlHttpClient::makeRequest(const Url& url, const std::vector escaped; + curl_mime *mime; + curl_mimepart *part; + mime = curl_mime_init(curl); if (!args.empty()) { for (const HttpReqArg& a : args) { - escaped.push_back(curl_easy_escape(curl, a.name.c_str(), a.name.size())); - data += escaped.back() + std::string("="); - escaped.push_back(curl_easy_escape(curl, a.value.c_str(), a.value.size())); - data += escaped.back() + std::string("&"); + part = curl_mime_addpart(mime); + + curl_mime_data(part, a.value.c_str(), a.value.size()); + curl_mime_type(part, a.mimeType.c_str()); + curl_mime_name(part, a.name.c_str()); + if (a.isFile) { + curl_mime_filename(part, a.fileName.c_str()); + } } - data.resize(data.size() - 1); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)data.size()); + curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime); } std::string response; @@ -77,10 +78,7 @@ std::string CurlHttpClient::makeRequest(const Url& url, const std::vector Date: Tue, 12 Nov 2019 20:59:24 +0800 Subject: update api and fix https://core.telegram.org/bots/api#deletestickerfromset --- src/Api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index 6b41947..5e41551 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -362,11 +362,11 @@ bool Api::setStickerPositionInSet(const string& sticker, uint32_t position) cons return sendRequest("setStickerPositionInSet", args).get("", false); } -bool Api::deleteStickerPositionInSet(const string& sticker) const { +bool Api::deleteStickerFromSet(const string& sticker) const { vector args; args.reserve(1); args.emplace_back("sticker", sticker); - return sendRequest("setStickerPositionInSet", args).get("", false); + return sendRequest("deleteStickerFromSet", args).get("", false); } Message::Ptr Api::sendVideo(int64_t chatId, const boost::variant video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const boost::variant thumb, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { -- cgit v1.2.3 From 9caa6efaf13214613f21e11f5e1536b4ab05c6d6 Mon Sep 17 00:00:00 2001 From: YJBeetle Date: Tue, 12 Nov 2019 23:11:17 +0800 Subject: update api addStickerToSet: remove title https://core.telegram.org/bots/api#addstickertoset --- src/Api.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index 5e41551..9996108 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -335,12 +335,11 @@ bool Api::createNewStickerSet(int32_t userId, const string& name, const string& return sendRequest("createNewStickerSet", args).get("", false); } -bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const boost::variant pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { +bool Api::addStickerToSet(int32_t userId, const string& name, const boost::variant pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { vector args; args.reserve(6); args.emplace_back("user_id", userId); args.emplace_back("name", name); - args.emplace_back("title", title); if (pngSticker.which() == 0 /* InputFile::Ptr */) { auto file = boost::get(pngSticker); args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); -- cgit v1.2.3 From b3cc5149f8337a43fe7f5174e35c739cd5e6b229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=9E=E4=BA=A6=E9=94=AE?= Date: Tue, 12 Nov 2019 14:15:56 -0800 Subject: update api: Inline result type remove "cached_" https://core.telegram.org/bots/api#inlinequeryresult --- src/types/InlineQueryResult.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/types/InlineQueryResult.cpp b/src/types/InlineQueryResult.cpp index 9f90e19..79debe0 100644 --- a/src/types/InlineQueryResult.cpp +++ b/src/types/InlineQueryResult.cpp @@ -25,14 +25,14 @@ using namespace TgBot; -const std::string InlineQueryResultCachedAudio::TYPE = "cached_audio"; -const std::string InlineQueryResultCachedDocument::TYPE = "cached_document"; -const std::string InlineQueryResultCachedGif::TYPE = "cached_gif"; -const std::string InlineQueryResultCachedMpeg4Gif::TYPE = "cached_mpeg4gif"; -const std::string InlineQueryResultCachedPhoto::TYPE = "cached_photo"; -const std::string InlineQueryResultCachedSticker::TYPE = "cached_sticker"; -const std::string InlineQueryResultCachedVideo::TYPE = "cached_video"; -const std::string InlineQueryResultCachedVoice::TYPE = "cached_voice"; +const std::string InlineQueryResultCachedAudio::TYPE = "audio"; +const std::string InlineQueryResultCachedDocument::TYPE = "document"; +const std::string InlineQueryResultCachedGif::TYPE = "gif"; +const std::string InlineQueryResultCachedMpeg4Gif::TYPE = "mpeg4_gif"; +const std::string InlineQueryResultCachedPhoto::TYPE = "photo"; +const std::string InlineQueryResultCachedSticker::TYPE = "sticker"; +const std::string InlineQueryResultCachedVideo::TYPE = "video"; +const std::string InlineQueryResultCachedVoice::TYPE = "voice"; const std::string InlineQueryResultArticle::TYPE = "article"; const std::string InlineQueryResultAudio::TYPE = "audio"; -- cgit v1.2.3 From 2318c534d4286436a668c5a33220dfc8d5b85686 Mon Sep 17 00:00:00 2001 From: YJBeetle Date: Fri, 29 Nov 2019 05:01:03 +0800 Subject: fix: answerInlineQuery BUTTON_TYPE_INVALID error https://core.telegram.org/bots/api#inlinekeyboardbutton pay: NOTE: This type of button must always be the first button in the first row. --- src/TgTypeParser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 4e31c94..daa7b4b 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1723,12 +1723,13 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton:: } string result; result += '{'; + if(object->pay) + appendToJson(result, "pay", object->pay); appendToJson(result, "text", object->text); appendToJson(result, "url", object->url); appendToJson(result, "callback_data", object->callbackData); appendToJson(result, "switch_inline_query", object->switchInlineQuery); appendToJson(result, "switch_inline_query_current_chat", object->switchInlineQueryCurrentChat); - appendToJson(result, "pay", object->pay); removeLastComma(result); result += '}'; return result; -- cgit v1.2.3