Skip to content

Commit b75f12c

Browse files
authored
Merge pull request #12 from Royna2544/copilot/fix-optional-field-comments
Wrap optional fields in std::optional<> to match documentation
2 parents 3407715 + d02168a commit b75f12c

6 files changed

Lines changed: 21 additions & 13 deletions

File tree

include/tgbot/types/CallbackQuery.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "tgbot/types/Message.h"
66

77
#include <memory>
8+
#include <optional>
89
#include <string>
910

1011
namespace TgBot {
@@ -35,7 +36,7 @@ class CallbackQuery {
3536
/**
3637
* @brief Optional. Identifier of the message sent via the bot in inline mode, that originated the query.
3738
*/
38-
std::string inlineMessageId;
39+
std::optional<std::string> inlineMessageId;
3940

4041
/**
4142
* @brief Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.

include/tgbot/types/InputInvoiceMessageContent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class InputInvoiceMessageContent : public InputMessageContent {
7171
* At most 4 suggested tip amounts can be specified.
7272
* The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed maxTipAmount.
7373
*/
74-
std::vector<std::int32_t> suggestedTipAmounts;
74+
std::optional<std::vector<std::int32_t>> suggestedTipAmounts;
7575

7676
/**
7777
* @brief Optional. A JSON-serialized object for data about the invoice, which will be shared with the payment provider.

include/tgbot/types/InputSticker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "tgbot/types/MaskPosition.h"
55

66
#include <memory>
7+
#include <optional>
78
#include <string>
89
#include <vector>
910

@@ -50,7 +51,7 @@ class InputSticker {
5051
*
5152
* For “regular” and “custom_emoji” stickers only.
5253
*/
53-
std::vector<std::string> keywords;
54+
std::optional<std::vector<std::string>> keywords;
5455
};
5556
}
5657

include/tgbot/types/Message.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class Message {
254254
/**
255255
* @brief Optional. Caption for the animation, audio, document, photo, video or voice
256256
*/
257-
std::string caption;
257+
std::optional<std::string> caption;
258258

259259
/**
260260
* @brief Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption

include/tgbot/types/WebhookInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class WebhookInfo {
6161
/**
6262
* @brief Optional. A list of update types the bot is subscribed to. Defaults to all update types except chatMember
6363
*/
64-
std::vector<std::string> allowedUpdates;
64+
std::optional<std::vector<std::string>> allowedUpdates;
6565
};
6666
}
6767

src/TgTypeParser.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,10 @@ DECLARE_PARSER_FROM_JSON(WebhookInfo) {
375375
parse(data, "last_synchronization_error_date",
376376
&result->lastSynchronizationErrorDate);
377377
parse(data, "max_connections", &result->maxConnections);
378-
result->allowedUpdates =
379-
parsePrimitiveArray<std::string>(data, "allowed_updates");
378+
if (data.contains("allowed_updates") && !data["allowed_updates"].is_null()) {
379+
result->allowedUpdates =
380+
parsePrimitiveArray<std::string>(data, "allowed_updates");
381+
}
380382
return result;
381383
}
382384

@@ -393,7 +395,7 @@ DECLARE_PARSER_TO_JSON(WebhookInfo) {
393395
object->lastSynchronizationErrorDate);
394396
json.put("max_connections", object->maxConnections);
395397

396-
json.put("allowed_updates", put(object->allowedUpdates));
398+
json.put("allowed_updates", object->allowedUpdates);
397399
}
398400
return json;
399401
}
@@ -3489,7 +3491,9 @@ DECLARE_PARSER_FROM_JSON(InputSticker) {
34893491
parse(data, "format", &result->format);
34903492
result->emojiList = parsePrimitiveArray<std::string>(data, "emoji_list");
34913493
result->maskPosition = parse<MaskPosition>(data, "mask_position");
3492-
result->keywords = parsePrimitiveArray<std::string>(data, "keywords");
3494+
if (data.contains("keywords") && !data["keywords"].is_null()) {
3495+
result->keywords = parsePrimitiveArray<std::string>(data, "keywords");
3496+
}
34933497
return result;
34943498
}
34953499

@@ -3503,7 +3507,7 @@ DECLARE_PARSER_TO_JSON(InputSticker) {
35033507
ptree.put("format", object->format);
35043508
ptree.put("emoji_list", put(object->emojiList));
35053509
ptree.put("mask_position", put(object->maskPosition));
3506-
ptree.put("keywords", put(object->keywords));
3510+
ptree.put("keywords", object->keywords);
35073511

35083512
return ptree;
35093513
}
@@ -4343,8 +4347,10 @@ DECLARE_PARSER_FROM_JSON(InputInvoiceMessageContent) {
43434347
parse(data, "currency", &result->currency);
43444348
result->prices = parseArray<LabeledPrice>(data, "prices");
43454349
parse(data, "max_tip_amount", &result->maxTipAmount);
4346-
result->suggestedTipAmounts =
4347-
parsePrimitiveArray<std::int32_t>(data, "suggested_tip_amounts");
4350+
if (data.contains("suggested_tip_amounts") && !data["suggested_tip_amounts"].is_null()) {
4351+
result->suggestedTipAmounts =
4352+
parsePrimitiveArray<std::int32_t>(data, "suggested_tip_amounts");
4353+
}
43484354
parse(data, "provider_data", &result->providerData);
43494355
parse(data, "photo_url", &result->photoUrl);
43504356
parse(data, "photo_size", &result->photoSize);
@@ -4373,7 +4379,7 @@ DECLARE_PARSER_TO_JSON(InputInvoiceMessageContent) {
43734379
ptree.put("currency", object->currency);
43744380
ptree.put("prices", put(object->prices));
43754381
ptree.put("max_tip_amount", object->maxTipAmount);
4376-
ptree.put("suggested_tip_amounts", put(object->suggestedTipAmounts));
4382+
ptree.put("suggested_tip_amounts", object->suggestedTipAmounts);
43774383
ptree.put("provider_data", object->providerData);
43784384
ptree.put("photo_url", object->photoUrl);
43794385
ptree.put("photo_size", object->photoSize);

0 commit comments

Comments
 (0)