C++ library for Telegram bot API.
NOTE: Library is under massive reconstruction. Expect backwards-incompatible changes!
- Bot API 2.3.1
- Bot API 3.0 (everything except payments)
- Bot API 3.1
- Bot API 3.2
- Bot API 3.3
- Bot API 3.4
- CMake 3.2+
- Boost 1.59+ system compomnent for library; regex, iostreams, unit_test_framework for tests.
- OpenSSL
Following should be enough on Debian-based distros:
sudo apt-get install g++ make binutils cmake libssl-dev libboost-system-dev
git clone https://github.com/foxcpp/tgbot-cpp
cd tgbot-cpp
mkdir build; cd build
cmake ..
make
find_package(tgbot-cpp REQUIRED)
add_executable(bot-exe-name file.cpp)
target_link_libraries(bot-exe-name tgbot)
add_subdirectory(tgbot-cpp/) # Make sure it points to directory where you placed tgbot-cpp
add_executable(bot-exe-name files.cpp)
target_link_libraries(bot-exe-name tgbot)
Simple echo bot which sends everything it receives:
#include <stdio.h>
#include <tgbot/tgbot.h>
int main() {
TgBot::Bot bot("PLACE YOUR TOKEN HERE");
bot.getEvents().onCommand("start", [&bot](TgBot::Message::Ptr message) {
bot.getApi().sendMessage(message->chat->id, "Hi!");
});
bot.getEvents().onAnyMessage([&bot](TgBot::Message::Ptr message) {
printf("User wrote %s\n", message->text.c_str());
if (StringTools::startsWith(message->text, "/start")) {
return;
}
bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text);
});
try {
printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str());
TgBot::TgLongPoll longPoll(bot);
while (true) {
printf("Long poll started\n");
longPoll.start();
}
} catch (TgBot::TgException& e) {
printf("error: %s\n", e.what());
}
return 0;
}
For more advanced examples see examples/
PRs, issues, questions are welcome!