开源软件名称:reo7sp/tgbot-cpp开源软件地址:https://github.com/reo7sp/tgbot-cpp开源编程语言:C++ 97.2%开源软件介绍:tgbot-cppC++14 library for Telegram bot API. Documentation is located here. State
SampleSimple 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. DependenciesFirstly you need to install some dependencies such as Boost and build tools such as CMake. On Debian-based distibutives you can do it with these commands: sudo apt-get install g++ make binutils cmake libssl-dev libboost-system-dev zlib1g-dev If you want to use curl-based http client Library installationIf you want to install the library system-wide: git clone https://github.com/reo7sp/tgbot-cpp
cd tgbot-cpp
cmake .
make -j4
sudo make install You can treat this repository as a submodule of your project, for example, see echobot-submodule You can use Docker to build and run your bot. Set the base image of your's Dockerfile to reo7sp/tgbot-cpp. Bot compilationWith CMakeWithout CMakeg++ telegram_bot.cpp -o telegram_bot --std=c++14 -I/usr/local/include -lTgBot -lboost_system -lssl -lcrypto -lpthread Build options
Licence |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论