Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

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

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