A C++ library for constructing Telegram bots in compile-time!
The recommended way of connecting the library is via Conan package manager. For now it should be possible to install it via
conan create . --build=missingSee test.cpp
All handlers are constexpr structural lambdas or similar objects.
If you need some runtime dependecies, pass them through Dependecies template type parameter of Setup and Stater's constructor argument.
Valid handler signatures:
- from
void(const EventArgs&...) - up to
void(StateOption&, const EventArgs&..., const TgBot::Api&, const StateStorageProxy&, const Dependencies&)
Everything except for EventArgs is optional.
Handlers that are not bound to a specific state can't take state parameter.
For the lists of EventArgs see CallbackArgs member at event.hpp
Note
To get chatId or an event's similar target id, you'd better use StateProxy.getKey().
But it's also possible to reference message.chat->... objects in message handlers as the chat's id is used for chat/user recognition.
Other handler types have similar things, but you'd better check the source code of event.hpp for that information.
Important
When you put a new state object into a storage, the old one most probably dies and its reference is invalidated. Be very careful with this! See an example:
[](StateA& state, const Message& m, const StateProxy& stateManager) {
std::println("{}", state.foo); // OK
stateManager.put(StateB{});
std::println("{}", state.foo); // UB, the reference is dangling
}