diff --git a/include.pri b/include.pri new file mode 100644 index 0000000..e5f2f1d --- /dev/null +++ b/include.pri @@ -0,0 +1,11 @@ + +HEADERS += \ + $$PWD/src/telegrambot.h \ + $$PWD/modules/httpserver/httpserver.h \ + $$PWD/vendor/qdelegate/include/qdelegate.h + +INCLUDEPATH += $$PWD/src/ +INCLUDEPATH += $$PWD/modules/sslserver/ +INCLUDEPATH += $$PWD/modules/httpserver/ +INCLUDEPATH += $$PWD/vendor/qdelegate/include/ + diff --git a/modules/httpserver/httpserver.cpp b/modules/httpserver/httpserver.cpp index 82978e3..9a64913 100644 --- a/modules/httpserver/httpserver.cpp +++ b/modules/httpserver/httpserver.cpp @@ -46,14 +46,15 @@ void HttpServer::handleNewData() // build response QByteArray responseContent; - responseContent += (response->version.isEmpty() ? "HTTP/1.1" : response->version) + " "; // Version - responseContent += QByteArray::number((qint32)response->status) + " " + response->StatusNames.value((qint32)response->status, "") + "\r\n"; // Status + responseContent += (response->version.isEmpty() ? "HTTP/1.1" : response->version.toUtf8()) + " "; // Version + responseContent += QByteArray::number((qint32)response->status) + " " + + response->StatusNames.value((qint32)response->status, "").toUtf8() + "\r\n"; // Status // add headers qint64 contentLength = 0; for(auto itr = response->headers.begin(); itr != response->headers.end(); itr++) { if(itr.key().toLower() == "content-length") contentLength = itr.value().toLongLong(); - responseContent += itr.key() + ": " + itr.value() + "\r\n"; + responseContent += itr.key().toUtf8() + ": " + itr.value().toUtf8() + "\r\n"; } // add content length if not available diff --git a/src/jsonhelper.cpp b/src/jsonhelper.cpp index c8352b0..643d7a8 100644 --- a/src/jsonhelper.cpp +++ b/src/jsonhelper.cpp @@ -3,7 +3,7 @@ QVariant JsonHelper::jsonPathGetImpl(QJsonValue data, QString path, bool showWarnings) { // json parse - QStringList splittedPath = path.split('.', QString::SkipEmptyParts); + QStringList splittedPath = path.split('.'); QStringList processed; while(!splittedPath.isEmpty()) { QString pathElement = splittedPath.takeFirst(); diff --git a/src/telegrambot.cpp b/src/telegrambot.cpp index a5df7a1..4dcd440 100644 --- a/src/telegrambot.cpp +++ b/src/telegrambot.cpp @@ -191,6 +191,38 @@ void TelegramBot::answerCallbackQuery(QString callbackQueryId, QString text, boo this->callApiTemplate("answerCallbackQuery", params, response); } +void TelegramBot::answerInlineQuery(const QString inlineQueryId, + QList &results , + bool is_personal, + int cacheTime, + QString switch_pm_text, + QString switch_pm_parameter, + QString url, + bool *response) { + QUrlQuery params; + params.addQueryItem("inline_query_id", inlineQueryId); + QJsonArray formedResults; + for (auto result : results) { + QJsonObject resultObj; + result->toJson(resultObj); + formedResults.append(resultObj); + delete result; + } + if (!switch_pm_parameter.isEmpty()) + params.addQueryItem("switch_pm_parameter", switch_pm_parameter); + + if (!switch_pm_text.isEmpty()) + params.addQueryItem("switch_pm_text", switch_pm_text); + + params.addQueryItem("is_personal", is_personal?"true":"false"); + + params.addQueryItem("results", QJsonDocument(formedResults).toJson(QJsonDocument::Compact)); + if(!url.isNull()) params.addQueryItem("url", url); + if (cacheTime > 0) params.addQueryItem("cache_time", QString::number(cacheTime)); + + this->callApiTemplate("answerInlineQuery", params, response); +} + /* * Message Functions @@ -201,13 +233,14 @@ void TelegramBot::sendMessage(QVariant chatId, QString text, int replyToMessageI params.addQueryItem("chat_id", chatId.toString()); params.addQueryItem("text", text); if(flags && TelegramFlags::Markdown) params.addQueryItem("parse_mode", "Markdown"); + else if(flags && TelegramFlags::MarkDownV2) params.addQueryItem("parse_mode", "MarkdownV2"); else if(flags && TelegramFlags::Html) params.addQueryItem("parse_mode", "HTML"); if(flags && TelegramFlags::DisableWebPagePreview) params.addQueryItem("disable_web_page_preview", "true"); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // call api return this->callApiTemplate("sendMessage", params, response); @@ -233,7 +266,7 @@ void TelegramBot::editMessageText(QVariant chatId, QVariant messageId, QString t // only build inline keyboard if(!(flags && TelegramFlags::ReplyKeyboardMarkup) && !(flags && TelegramFlags::ForceReply) && !(flags && TelegramFlags::ReplyKeyboardRemove)) { - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); } // call api @@ -251,7 +284,7 @@ void TelegramBot::editMessageCaption(QVariant chatId, QVariant messageId, QStrin if(!caption.isNull()) params.addQueryItem("caption", caption); // only build inline keyboard - this->hanldeReplyMarkup(params, TelegramFlags(), keyboard); + this->handleReplyMarkup(params, TelegramFlags(), keyboard); // call api this->callApiTemplate("editMessageCaption", params, response); @@ -267,7 +300,7 @@ void TelegramBot::editMessageReplyMarkup(QVariant chatId, QVariant messageId, Te params.addQueryItem(isInlineMessageId ? "inline_message_id" : "message_id", messageId.toString()); // only build inline keyboard - this->hanldeReplyMarkup(params, TelegramFlags(), keyboard); + this->handleReplyMarkup(params, TelegramFlags(), keyboard); // call api this->callApiTemplate("editMessageReplyMarkup", params, response); @@ -279,7 +312,7 @@ void TelegramBot::forwardMessage(QVariant targetChatId, QVariant fromChatId, qin params.addQueryItem("chat_id", targetChatId.toString()); params.addQueryItem("from_chat_id", fromChatId.toString()); params.addQueryItem("message_id", QString::number(fromMessageId)); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); this->callApiTemplate("forwardMessage", params, response); } @@ -301,11 +334,15 @@ void TelegramBot::sendPhoto(QVariant chatId, QVariant photo, QString caption, in QUrlQuery params; params.addQueryItem("chat_id", chatId.toString()); if(!caption.isNull()) params.addQueryItem("caption", caption); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::Markdown) params.addQueryItem("parse_mode", "Markdown"); + else if(flags && TelegramFlags::Html) params.addQueryItem("parse_mode", "HTML"); + if(flags && TelegramFlags::MarkDownV2) params.addQueryItem("parse_mode", "MarkdownV2"); + if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("photo", photo, params); @@ -322,11 +359,11 @@ void TelegramBot::sendAudio(QVariant chatId, QVariant audio, QString caption, QS if(duration >= 0) params.addQueryItem("duration", QString::number(duration)); if(!performer.isNull()) params.addQueryItem("performer", performer); if(!title.isNull()) params.addQueryItem("title", title); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("audio", audio, params); @@ -340,11 +377,11 @@ void TelegramBot::sendDocument(QVariant chatId, QVariant document, QString capti QUrlQuery params; params.addQueryItem("chat_id", chatId.toString()); if(!caption.isNull()) params.addQueryItem("caption", caption); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("document", document, params); @@ -357,11 +394,11 @@ void TelegramBot::sendSticker(QVariant chatId, QVariant sticker, int replyToMess { QUrlQuery params; params.addQueryItem("chat_id", chatId.toString()); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("sticker", sticker, params); @@ -378,11 +415,11 @@ void TelegramBot::sendVideo(QVariant chatId, QVariant video, QString caption, in if(duration >= 0) params.addQueryItem("duration", QString::number(duration)); if(width >= 0) params.addQueryItem("width", QString::number(width)); if(height >= 0) params.addQueryItem("height", QString::number(height)); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("video", video, params); @@ -397,11 +434,11 @@ void TelegramBot::sendVoice(QVariant chatId, QVariant voice, QString caption, in params.addQueryItem("chat_id", chatId.toString()); if(!caption.isNull()) params.addQueryItem("caption", caption); if(duration >= 0) params.addQueryItem("duration", QString::number(duration)); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("voice", voice, params); @@ -416,11 +453,11 @@ void TelegramBot::sendVideoNote(QVariant chatId, QVariant videoNote, int length, params.addQueryItem("chat_id", chatId.toString()); if(length >= 0) params.addQueryItem("length", QString::number(length)); if(duration >= 0) params.addQueryItem("duration", QString::number(duration)); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("video_note", videoNote, params); @@ -435,11 +472,11 @@ void TelegramBot::sendLocation(QVariant chatId, double latitude, double longitud params.addQueryItem("chat_id", chatId.toString()); params.addQueryItem("latitude", QString::number(latitude)); params.addQueryItem("longitude", QString::number(longitude)); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // call api this->callApiTemplate("sendLocation", params, response); @@ -454,11 +491,11 @@ void TelegramBot::sendVenue(QVariant chatId, double latitude, double longitude, params.addQueryItem("title", title); params.addQueryItem("address", address); if(!foursquareId.isNull()) params.addQueryItem("foursquare_id", foursquareId); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // call api this->callApiTemplate("sendVenue", params, response); @@ -471,11 +508,11 @@ void TelegramBot::sendContact(QVariant chatId, QString phoneNumber, QString firs params.addQueryItem("phone_number", phoneNumber); params.addQueryItem("first_name", firstName); if(!lastName.isNull()) params.addQueryItem("last_name", lastName); - if(flags && TelegramFlags::DisableNotfication) params.addQueryItem("disable_notification", "true"); + if(flags && TelegramFlags::DisableNotification) params.addQueryItem("disable_notification", "true"); if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // call api this->callApiTemplate("sendContact", params, response); @@ -754,8 +791,6 @@ QNetworkReply* TelegramBot::callApi(QString method, QUrlQuery params, bool delet QUrl url(QString("https://api.telegram.org/bot%1/%2").arg(this->apiKey, method)); url.setQuery(params); - qDebug() << url; - // execute QNetworkRequest request(url); QNetworkReply* reply = multiPart ? this->aManager.post(request, multiPart) : this->aManager.get(request); @@ -793,7 +828,7 @@ QHttpMultiPart* TelegramBot::createUploadFile(QString name, QString fileName, QB return multiPart; } -void TelegramBot::hanldeReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest &keyboard) +void TelegramBot::handleReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest &keyboard) { // handle types QString replyMarkup; diff --git a/src/telegrambot.h b/src/telegrambot.h index 2627511..0426e62 100644 --- a/src/telegrambot.h +++ b/src/telegrambot.h @@ -56,23 +56,24 @@ class TelegramBot : public QObject // Message Markdown = 1 << 0, - Html = 1 << 1, - DisableWebPagePreview = 1 << 2, - DisableNotfication = 1 << 3, + MarkDownV2 = 1 << 1, + Html = 1 << 2, + DisableWebPagePreview = 1 << 3, + DisableNotification = 1 << 4, // Keyboard Global - Selective = 1 << 4, + Selective = 1 << 5, // ReplyKeyboardMarkup - ReplyKeyboardMarkup = 1 << 5, - ResizeKeyboard = 1 << 6, - OneTimeKeyboard = 1 << 7, + ReplyKeyboardMarkup = 1 << 6, + ResizeKeyboard = 1 << 7, + OneTimeKeyboard = 1 << 8, // ReplyKeyboardRemove - ReplyKeyboardRemove = 1 << 8, + ReplyKeyboardRemove = 1 << 9, // ForceReply - ForceReply = 1 << 9 + ForceReply = 1 << 10 }; // Keyboard construction helpers @@ -107,7 +108,7 @@ class TelegramBot : public QObject // Callback Query Functions void answerCallbackQuery(QString callbackQueryId, QString text = QString(), bool showAlert = false, int cacheTime = 0, QString url = QString(), bool* response = 0); - + void answerInlineQuery(const QString inlineQueryId, QList &results, bool is_personal = false, int cacheTime=0, QString switch_pm_text="", QString switch_pm_parameter="", QString url="", bool* response = 0); // Message Functions void sendMessage(QVariant chatId, QString text, int replyToMessageId = 0, TelegramFlags flags = TelegramFlags::NoFlag, TelegramKeyboardRequest keyboard = TelegramKeyboardRequest(), TelegramBotMessage* response = 0); void editMessageText(QVariant chatId, QVariant messageId, QString text, TelegramFlags flags = TelegramFlags::NoFlag, TelegramKeyboardRequest keyboard = TelegramKeyboardRequest(), bool* response = 0); @@ -164,7 +165,7 @@ class TelegramBot : public QObject // helpers QHttpMultiPart* createUploadFile(QString name, QString fileName, QByteArray& content, bool detectMimeType = false, QHttpMultiPart* multiPart = 0); - void hanldeReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest& keyboard); + void handleReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest& keyboard); QHttpMultiPart* handleFile(QString fieldName, QVariant file, QUrlQuery& params, QHttpMultiPart* multiPart = 0); // global data diff --git a/src/telegramdatainterface.h b/src/telegramdatainterface.h index e3346fe..eea809c 100644 --- a/src/telegramdatainterface.h +++ b/src/telegramdatainterface.h @@ -3,9 +3,11 @@ #include "jsonhelper.h" -struct TelegramBotObject +class TelegramBotObject { +public: virtual void fromJson(QJsonObject& object) = 0; + virtual void toJson(QJsonObject& object) {Q_UNUSED(object)}; virtual ~TelegramBotObject() {} }; @@ -15,7 +17,11 @@ class JsonHelperT::jsonPathGet(object, "id", this->id); + JsonHelperT::jsonPathGet(object, "id", this->id); JsonHelperT::jsonPathGet(object, "first_name", this->firstName); JsonHelperT::jsonPathGet(object, "last_name", this->lastName, false); JsonHelperT::jsonPathGet(object, "username", this->username, false); @@ -219,7 +219,7 @@ struct TelegramBotKeyboardButton : public TelegramBotObject TelegramBotGame callbackGame; // parse logic - virtual void fromJson(QJsonObject& object) { + virtual void fromJson(QJsonObject& object) override { JsonHelperT::jsonPathGet(object, "text", this->text); JsonHelperT::jsonPathGet(object, "url", this->url, false); JsonHelperT::jsonPathGet(object, "callback_data", this->callbackData, false); @@ -229,12 +229,17 @@ struct TelegramBotKeyboardButton : public TelegramBotObject JsonHelperT::jsonPathGet(object, "request_contact", this->requestContact, false); JsonHelperT::jsonPathGet(object, "request_location", this->requestLocation, false); } + void toJson(QJsonObject & object) override { + object.insert("text", text); + if (!callbackData.isEmpty()) + object.insert("callback_data", callbackData); + } }; typedef QList> TelegramKeyboard; // TelegramBotChat - This object represents a chat. struct TelegramBotChat : public TelegramBotObject { - qint32 id; // Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + qint64 id; // Unique identifier for this chat. This number from now can be signed 64 bit integer or double-precision float type are safe for storing this identifier. QString type; // Type of chat, can be either “private”, “group”, “supergroup” or “channel” QString title; // Optional. Title, for supergroups, channels and group chats QString username; // Optional. Username, for private chats, supergroups and channels if available @@ -247,7 +252,7 @@ struct TelegramBotChat : public TelegramBotObject { // parse logic virtual void fromJson(QJsonObject& object) { - JsonHelperT::jsonPathGet(object, "id", this->id); + JsonHelperT::jsonPathGet(object, "id", this->id); JsonHelperT::jsonPathGet(object, "type", this->type); JsonHelperT::jsonPathGet(object, "title", this->title, false); JsonHelperT::jsonPathGet(object, "username", this->username, false); @@ -605,36 +610,93 @@ struct TelegramBotInputMessageContent : public TelegramBotObject { JsonHelperT::jsonPathGet(object, "parse_mode", this->parseMode, false); JsonHelperT::jsonPathGet(object, "disable_web_page_preview", this->disableWebPagePreview, false); } + QJsonObject toJson() { + QJsonObject ret; + ret.insert("message_text", messageText); + if (!parseMode.isEmpty()) + ret.insert("parse_mode", parseMode); + return ret; + } }; // This object represents one result of an inline query. Telegram clients currently support results of the following 20 types: -struct TelegramBotInlineQueryResult : public TelegramBotObject { - +class TelegramBotInlineQueryResult : public TelegramBotObject { +public: QString type; // Type of the result, must be article QString id; // Unique identifier for this result, 1-64 Bytes QString title; // Title of the result - TelegramBotInputMessageContent inputMessageContent; // Content of the message to be sent + QString description; // Optional. Short description of the result TelegramKeyboard replyMarkup; // Optional. Inline keyboard attached to the message QString url; // Optional. URL of the result bool hideUrl; // Optional. Pass True, if you don't want the URL to be shown in the message - QString description; // Optional. Short description of the result QString thumbUrl; // Optional. Url of the thumbnail for the result qint32 thumbWidth; // Optional. Thumbnail width qint32 thumbHeight; // Optional. Thumbnail height - virtual void fromJson(QJsonObject& object) { + virtual void fromJson(QJsonObject& object) override { JsonHelperT::jsonPathGet(object, "type", this->type); JsonHelperT::jsonPathGet(object, "id", this->id); JsonHelperT::jsonPathGet(object, "title", this->title); - JsonHelperT::jsonPathGet(object, "input_message_content", this->inputMessageContent); + JsonHelperT::jsonPathGet(object, "description", this->description); JsonHelperT::jsonPathGetArrayArray(object, "reply_markup", this->replyMarkup, false); JsonHelperT::jsonPathGet(object, "url", this->url, false); JsonHelperT::jsonPathGet(object, "hide_url", this->hideUrl, false); - JsonHelperT::jsonPathGet(object, "description", this->description, false); JsonHelperT::jsonPathGet(object, "thumb_url", this->thumbUrl, false); JsonHelperT::jsonPathGet(object, "thumb_width", this->thumbWidth, false); JsonHelperT::jsonPathGet(object, "thumb_height", this->thumbHeight, false); } + virtual void toJson(QJsonObject & object) override { + object.insert("id", id); + object.insert("type", type); + object.insert("title", title); + object.insert("description", description); + if (!replyMarkup.isEmpty()) { + QJsonArray keyboardJ; + for (const auto &keyboardRow : replyMarkup) { + QJsonArray keyboardLine; + for (auto keyboard : keyboardRow) { + QJsonObject keyObj; + keyboard.toJson(keyObj); + + keyboardLine.append(keyObj); + } + keyboardJ.append(keyboardLine); + } + QJsonObject inlineObj; + inlineObj.insert("inline_keyboard", keyboardJ); + object.insert("reply_markup", inlineObj); + } + + } +}; + +// This object represents one result of an inline query. Telegram clients currently support results of the following 20 types: +class TelegramBotInlineQueryResultArticle : + public TelegramBotInlineQueryResult { +public: + TelegramBotInlineQueryResultArticle() { + type = "article"; + } + TelegramBotInputMessageContent inputMessageContent; // Content of the message to be sent + QString thumbUrl; // Optional. Url of the thumbnail for the result + qint32 thumbWidth; // Optional. Thumbnail width + qint32 thumbHeight; // Optional. Thumbnail height + void fromJson(QJsonObject& object) override { + TelegramBotInlineQueryResult::fromJson(object); + JsonHelperT::jsonPathGet(object, "input_message_content", this->inputMessageContent); + JsonHelperT::jsonPathGet(object, "url", this->url, false); + JsonHelperT::jsonPathGet(object, "hide_url", this->hideUrl, false); + JsonHelperT::jsonPathGet(object, "thumb_url", this->thumbUrl, false); + JsonHelperT::jsonPathGet(object, "thumb_width", this->thumbWidth, false); + JsonHelperT::jsonPathGet(object, "thumb_height", this->thumbHeight, false); + } + void toJson(QJsonObject & object) override { + TelegramBotInlineQueryResult::toJson(object); + object.insert("input_message_content", + inputMessageContent.toJson()); + if (!description.isEmpty()) + object.insert("description", description); + } }; // Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use inputMessageContent to send a message with the specified content instead of the photo. @@ -933,26 +995,37 @@ struct TelegramBotInlineQueryResultGame : public TelegramBotObject { }; // Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use inputMessageContent to send a message with the specified content instead of the photo. -struct TelegramBotInlineQueryResultCachedPhoto : public TelegramBotObject { - QString type; // Type of the result, must be photo - QString id; // Unique identifier for this result, 1-64 bytes +class TelegramBotInlineQueryResultCachedPhoto : + public TelegramBotInlineQueryResult { + +public: + TelegramBotInlineQueryResultCachedPhoto() { + type = "photo"; + } QString photoFileId; // A valid file identifier of the photo - QString title; // Optional. Title for the result - QString description; // Optional. Short description of the result QString caption; // Optional. Caption of the photo to be sent, 0-200 characters - TelegramKeyboard replyMarkup; // Optional. Inline keyboard attached to the message + QString parseMode; TelegramBotInputMessageContent inputMessageContent; // Optional. Content of the message to be sent instead of the photo - virtual void fromJson(QJsonObject& object) { - JsonHelperT::jsonPathGet(object, "type", this->type); - JsonHelperT::jsonPathGet(object, "id", this->id); + virtual void fromJson(QJsonObject& object) override { + TelegramBotInlineQueryResult::fromJson(object); JsonHelperT::jsonPathGet(object, "photo_file_id", this->photoFileId); - JsonHelperT::jsonPathGet(object, "title", this->title, false); - JsonHelperT::jsonPathGet(object, "description", this->description, false); JsonHelperT::jsonPathGet(object, "caption", this->caption, false); - JsonHelperT::jsonPathGetArrayArray(object, "reply_markup", this->replyMarkup, false); + JsonHelperT::jsonPathGet(object, "parse_mode", this->parseMode, false); JsonHelperT::jsonPathGet(object, "input_message_content", this->inputMessageContent, false); } + void toJson(QJsonObject & object) override { + TelegramBotInlineQueryResult::toJson(object); + + object.insert("photo_file_id", photoFileId); + object.insert("caption", caption); + object.insert("parse_mode", parseMode); + if (!inputMessageContent.messageText.isEmpty()) + object.insert("input_message_content", + inputMessageContent.toJson()); + if (!description.isEmpty()) + object.insert("description", description); + } }; // Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use inputMessageContent to send a message with specified content instead of the animation.