This is an example of a C++ telegram bot using a reactive API. See this repository for details.
The usingstdcpp2019::urp
API implements an event stream API similar to
Rx. This bot is an example of integrating that API
into the tgbot_cpp API to compose
powerful Telegram message handling mechanisms. To do so, the example
bop.cpp
implements a ReactiveBot
class that subscribes to any user
message sent to the Telegram bot with
TgBot::EventBroadcaster::onAnyMessage()
and sends them through the
urp::trigger
API to generate an event. From there the message is an
event that can be streamed and combined using different operators.
The example uses conan to gather all dependencies, which are all linked statically to generate a deps-free standalone executable. To set up the project run the following commands from the source tree:
$ mkdir build && cd build
$ conan install .. --build=missing
$ cmake ..
$ make
You need the following conan repositories:
- Manu343726 (For
tgbot_cpp
andconan_common_recipes
): https://api.bintray.com/conan/manu343726/conan-packages- bincrafters (For
boost
,fmt
, etc): https://api.bintray.com/conan/bincrafters/public-conanThe repositories are configured in your machine as follows:
$ conan remote add Manu343726 https://api.bintray.com/conan/manu343726/conan-packages $ conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
If everything runs smoothly there should be a bot
executable in
build/bin/
.
Telegram bots use an unique API token to identify themselves. This token
should be given to the bot through an environment variable called
USINGSTDCPP2019_BOT_TOKEN
:
$ export USINGSTDCPP2019_BOT_TOKEN="your telegram bot API token"
$ ./bin/bot
Hi! I'm @usingstdcpp2019_bot, I'm ready to talk with you!
See the Telegram Bot docs to get a new API token.