From a882b61a9e7ac7fb3b5b8ca8819eada0226a2f17 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 03:23:32 +0000 Subject: [PATCH 1/3] Initial plan From a4126415583b2ee8cee31239af7e14d179ef9e36 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 03:32:35 +0000 Subject: [PATCH 2/3] Fixed 5 optional fields: wrapped them in std::optional and updated parser code Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com> --- include/tgbot/types/CallbackQuery.h | 3 ++- include/tgbot/types/InputInvoiceMessageContent.h | 2 +- include/tgbot/types/InputSticker.h | 3 ++- include/tgbot/types/Message.h | 2 +- include/tgbot/types/WebhookInfo.h | 2 +- src/TgTypeParser.cpp | 16 +++++++++++----- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/tgbot/types/CallbackQuery.h b/include/tgbot/types/CallbackQuery.h index 58e02b35..6d994f42 100644 --- a/include/tgbot/types/CallbackQuery.h +++ b/include/tgbot/types/CallbackQuery.h @@ -5,6 +5,7 @@ #include "tgbot/types/Message.h" #include +#include #include namespace TgBot { @@ -35,7 +36,7 @@ class CallbackQuery { /** * @brief Optional. Identifier of the message sent via the bot in inline mode, that originated the query. */ - std::string inlineMessageId; + std::optional inlineMessageId; /** * @brief Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games. diff --git a/include/tgbot/types/InputInvoiceMessageContent.h b/include/tgbot/types/InputInvoiceMessageContent.h index 17721c87..aba5ab13 100644 --- a/include/tgbot/types/InputInvoiceMessageContent.h +++ b/include/tgbot/types/InputInvoiceMessageContent.h @@ -71,7 +71,7 @@ class InputInvoiceMessageContent : public InputMessageContent { * At most 4 suggested tip amounts can be specified. * The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed maxTipAmount. */ - std::vector suggestedTipAmounts; + std::optional> suggestedTipAmounts; /** * @brief Optional. A JSON-serialized object for data about the invoice, which will be shared with the payment provider. diff --git a/include/tgbot/types/InputSticker.h b/include/tgbot/types/InputSticker.h index a5b5a313..6987dd01 100644 --- a/include/tgbot/types/InputSticker.h +++ b/include/tgbot/types/InputSticker.h @@ -4,6 +4,7 @@ #include "tgbot/types/MaskPosition.h" #include +#include #include #include @@ -50,7 +51,7 @@ class InputSticker { * * For “regular” and “custom_emoji” stickers only. */ - std::vector keywords; + std::optional> keywords; }; } diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index 66f29561..01a6196c 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -254,7 +254,7 @@ class Message { /** * @brief Optional. Caption for the animation, audio, document, photo, video or voice */ - std::string caption; + std::optional caption; /** * @brief Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption diff --git a/include/tgbot/types/WebhookInfo.h b/include/tgbot/types/WebhookInfo.h index a55ed088..7e475eb8 100644 --- a/include/tgbot/types/WebhookInfo.h +++ b/include/tgbot/types/WebhookInfo.h @@ -61,7 +61,7 @@ class WebhookInfo { /** * @brief Optional. A list of update types the bot is subscribed to. Defaults to all update types except chatMember */ - std::vector allowedUpdates; + std::optional> allowedUpdates; }; } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index e6039c87..54e4f739 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -375,8 +375,10 @@ DECLARE_PARSER_FROM_JSON(WebhookInfo) { parse(data, "last_synchronization_error_date", &result->lastSynchronizationErrorDate); parse(data, "max_connections", &result->maxConnections); - result->allowedUpdates = - parsePrimitiveArray(data, "allowed_updates"); + if (data.contains("allowed_updates") && !data["allowed_updates"].is_null()) { + result->allowedUpdates = + parsePrimitiveArray(data, "allowed_updates"); + } return result; } @@ -3489,7 +3491,9 @@ DECLARE_PARSER_FROM_JSON(InputSticker) { parse(data, "format", &result->format); result->emojiList = parsePrimitiveArray(data, "emoji_list"); result->maskPosition = parse(data, "mask_position"); - result->keywords = parsePrimitiveArray(data, "keywords"); + if (data.contains("keywords") && !data["keywords"].is_null()) { + result->keywords = parsePrimitiveArray(data, "keywords"); + } return result; } @@ -4343,8 +4347,10 @@ DECLARE_PARSER_FROM_JSON(InputInvoiceMessageContent) { parse(data, "currency", &result->currency); result->prices = parseArray(data, "prices"); parse(data, "max_tip_amount", &result->maxTipAmount); - result->suggestedTipAmounts = - parsePrimitiveArray(data, "suggested_tip_amounts"); + if (data.contains("suggested_tip_amounts") && !data["suggested_tip_amounts"].is_null()) { + result->suggestedTipAmounts = + parsePrimitiveArray(data, "suggested_tip_amounts"); + } parse(data, "provider_data", &result->providerData); parse(data, "photo_url", &result->photoUrl); parse(data, "photo_size", &result->photoSize); From d02168add4d047a3b37cfef1a5f8e389ac5ad0ab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 03:55:47 +0000 Subject: [PATCH 3/3] Fix serialization of optional vector fields - use JsonWrapper::put directly Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com> --- src/TgTypeParser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 54e4f739..6fbf8040 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -395,7 +395,7 @@ DECLARE_PARSER_TO_JSON(WebhookInfo) { object->lastSynchronizationErrorDate); json.put("max_connections", object->maxConnections); - json.put("allowed_updates", put(object->allowedUpdates)); + json.put("allowed_updates", object->allowedUpdates); } return json; } @@ -3507,7 +3507,7 @@ DECLARE_PARSER_TO_JSON(InputSticker) { ptree.put("format", object->format); ptree.put("emoji_list", put(object->emojiList)); ptree.put("mask_position", put(object->maskPosition)); - ptree.put("keywords", put(object->keywords)); + ptree.put("keywords", object->keywords); return ptree; } @@ -4379,7 +4379,7 @@ DECLARE_PARSER_TO_JSON(InputInvoiceMessageContent) { ptree.put("currency", object->currency); ptree.put("prices", put(object->prices)); ptree.put("max_tip_amount", object->maxTipAmount); - ptree.put("suggested_tip_amounts", put(object->suggestedTipAmounts)); + ptree.put("suggested_tip_amounts", object->suggestedTipAmounts); ptree.put("provider_data", object->providerData); ptree.put("photo_url", object->photoUrl); ptree.put("photo_size", object->photoSize);