diff --git a/include/tgbot/types/ReplyParameters.h b/include/tgbot/types/ReplyParameters.h index c027e619..1b7f0864 100644 --- a/include/tgbot/types/ReplyParameters.h +++ b/include/tgbot/types/ReplyParameters.h @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -60,7 +61,7 @@ class ReplyParameters { * * It can be specified instead of quoteParseMode. */ - std::vector quoteEntities; + std::optional> quoteEntities; /** * @brief Optional. Position of the quote in the original message in UTF-16 code units diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index efb2fcf9..e6039c87 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -47,6 +47,14 @@ struct JsonWrapper { } data_[std::string(key)] = *value; } + template , bool> = true> + void put(const std::string_view key, std::optional value) { + if (!value) { + return; // Skip empty optional + } + data_[std::string(key)] = TgBot::put(*value); + } static void merge(nlohmann::json &thiz, const nlohmann::json &other) { if (!thiz.is_object() || !other.is_object()) { @@ -818,7 +826,9 @@ DECLARE_PARSER_FROM_JSON(ReplyParameters) { &result->allowSendingWithoutReply); parse(data, "quote", &result->quote); parse(data, "quote_parse_mode", &result->quoteParseMode); - result->quoteEntities = parseArray(data, "quote_entities"); + if (data.contains("quote_entities")) { + result->quoteEntities = parseArray(data, "quote_entities"); + } parse(data, "quote_position", &result->quotePosition); return result; } @@ -833,7 +843,7 @@ DECLARE_PARSER_TO_JSON(ReplyParameters) { object->allowSendingWithoutReply); json.put("quote", object->quote); json.put("quote_parse_mode", object->quoteParseMode); - json.put("quote_entities", put(object->quoteEntities)); + json.put("quote_entities", object->quoteEntities); json.put("quote_position", object->quotePosition); }