TGBM is a easy-to-use, flexible C++20 library for creating telegram bots
- Easy Integration: by CPM or even cmake fetch content
- High Performance: designed with efficiency and speed in mind, ensuring optimal performance.
- User-Friendly: simple, intuitive, developer-friendly API for a smooth experience.
- Extensible: flexible and modular; does not impose unnecessary abstractions or dependencies, leaving room for your own design.
- HTTP2
Preferred way with CPM
CPMAddPackage(
NAME TGBM
GIT_REPOSITORY https://github.com/bot-motherlib/TGBM
GIT_TAG origin/master
OPTIONS "TGBM_ENABLE_EXAMPLES ON"
)
target_link_libraries(MyTargetName tgbmlib)
simple way with fetch content:
include(FetchContent)
FetchContent_Declare(
TGBM
GIT_REPOSITORY https://github.com/bot-motherlib/TGBM
GIT_TAG origin/master
)
FetchContent_MakeAvailable(TGBM)
target_link_libraries(MyTargetName tgbmlib)
Then just run
cmake .
Note: its recomended for windows to use clang and Ninja (cmake -G Ninja)
This bot responds with the same text that the user sent it
#include <tgbm/bot.hpp>
dd::task<void> coro_main(tgbm::bot& bot) {
// bot presented as sequence of updates
co_foreach(tgbm::api::Update u, bot.updates()) {
tgbm::api::Message* m = u.get_message();
if (!m || !m->text)
continue;
co_await bot.api.sendMessage({
.chat_id = m->chat->id,
.text = *m->text,
});
}
}
int main() {
tgbm::bot bot{/* your bot token from @BotFather */};
coro_main(bot).start_and_detach();
bot.run();
return 0;
}