Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Make the fields of Telegram types really optional (right now LinkPreviewOptions, ReplyParameters only)#320

Draft
uralm1 wants to merge 3 commits intoreo7sp:masterreo7sp/tgbot-cpp:masterfrom
uralm1:optional-fields-sendmessageuralm1/tgbot-cpp:optional-fields-sendmessageCopy head branch name to clipboard
Draft

Make the fields of Telegram types really optional (right now LinkPreviewOptions, ReplyParameters only)#320
uralm1 wants to merge 3 commits intoreo7sp:masterreo7sp/tgbot-cpp:masterfrom
uralm1:optional-fields-sendmessageuralm1/tgbot-cpp:optional-fields-sendmessageCopy head branch name to clipboard

Conversation

@uralm1
Copy link

@uralm1 uralm1 commented Nov 8, 2024

This PR is an example approach how to make optional fields of a secondary type classes really optional.
I wrapped optional fields with boost::optional, right now only in LinkPreviewOptions, ReplyParameters classes.

It solves the problem described in issue #308

There are many such classes in Api, so consider this change as an example approach. Any way, it covers most used sendMessage() function, and solves problem with replies.

@Royna2544
Copy link
Contributor

Royna2544 commented Nov 13, 2024

Code becomes really complicated, tho, wrapping everything in boost optional?
Check my fork, can you test it?
https://github.com/Royna2544/tgbot-cpp

@uralm1
Copy link
Author

uralm1 commented Nov 13, 2024

Code becomes really complicated, tho, wrapping everything in boost optional? Check my fork, can you test it? https://github.com/Royna2544/tgbot-cpp

jsoncpp is promising.
I have some notes out of this topic while adapting my bot code, can you open issues in your project?

@Royna2544
Copy link
Contributor

sure, i didnt know it was closed, now it is open

@uralm1 uralm1 force-pushed the optional-fields-sendmessage branch from cdfb903 to d5a2690 Compare November 17, 2024 20:12
@uralm1 uralm1 force-pushed the optional-fields-sendmessage branch from d5a2690 to 42567f5 Compare November 17, 2024 20:31
include/tgbot/TgTypeParser.h Outdated Show resolved Hide resolved

// use for: OptionalPtr<std::shared/unique_ptr<TYPE>>
// for pointers, we assume optional value == nullptr (or not owned, etc)
template<typename T>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can specialize the Optional template to create a specific implementation for certain types.

samples/echobot-curl-client/src/main.cpp Outdated Show resolved Hide resolved
include/tgbot/TgTypeParser.h Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.