C++ library for Telegram bot API.
Documentation is located here.
This library implements most features from Telegram Bot API 7.2 with additional features from later versions.
- Message Reactions (Bot API 7.x+)
- MessageReactionUpdated event handling
- MessageReactionCountUpdated event handling
- Business Account Integration (Bot API 7.x+)
- BusinessConnection updates
- Business message handling
- Deleted business messages tracking
- Chat Boosts (Bot API 7.x+)
- ChatBoostUpdated events
- ChatBoostRemoved events
- MaybeInaccessibleMessage - Planned for future implementation
- Message->pinnedMessage - Requires MaybeInaccessibleMessage
- CallbackQuery->message - Requires MaybeInaccessibleMessage
- Deep Linking
Note: Full Bot API 8.x and 9.x support is planned. Contributions are welcome!
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;
}All other samples are located here.
Dependencies:
- CMake
- Boost
- OpenSSL
- ZLib
- nlohmann/json
- Libcurl (optional unless you want to use curl-based http client
CurlHttpClient).
You can install dependencies on Debian-based distibutives with these commands:
sudo apt install g++ make binutils cmake libboost-system-dev libssl-dev zlib1g-dev libcurl4-openssl-dev nlohmann-json3-devOptionally, install the dependencies for testing and documenting
sudo apt install libboost-test-dev doxygenYou can compile and install the library with these commands:
git clone https://github.com/Royna2544/tgbot-cpp
cd tgbot-cpp
cmake .
make -j4
sudo make installAlternatively, you can use Docker to build and run your bot. Set the base image of your's Dockerfile to reo7sp/tgbot-cpp.
You can install dependencies with these commands:
brew install gcc cmake boost openssl zlib curl nlohmann-jsonYou can compile and install the library like Linux instructions.
Taken from Vcpkg - Quick Start: Windows.
Prerequisites:
- Windows 7 or newer
- [Git][https://git-scm.com/downloads]
- [Visual Studio][https://visualstudio.microsoft.com] 2015 Update 3 or greater with the English language pack
First, download and bootstrap vcpkg itself; it can be installed anywhere, but generally we recommend using vcpkg as a submodule for CMake projects, and installing it globally for Visual Studio projects. We recommend somewhere like C:\src\vcpkg or C:\dev\vcpkg, since otherwise you may run into path issues for some port build systems.
> git clone https://github.com/microsoft/vcpkg
> .\vcpkg\bootstrap-vcpkg.batIn order to use vcpkg with Visual Studio, run the following command (may require administrator elevation):
> .\vcpkg\vcpkg integrate installTo install the libraries for Windows x64, run:
> .\vcpkg\vcpkg install tgbot-cpp:x64-windowsTo install for Windows x86, run:
> .\vcpkg\vcpkg install tgbot-cppThe library will now be installed and Visual Studio should be able to find the vcpkg installation.
Use the example CMakeLists.txt with changes:
- Remove
/usr/local/include - Change
/usr/local/lib/libTgBot.atoC:/src/vcpkg/installed/x64-windows/lib/TgBot.libor something simmilar according to your own installation path.
Also, you can treat this repository as a submodule of your project, for example, see echobot-submodule.