# tgbot-cpp [![Build Status](https://travis-ci.org/reo7sp/tgbot-cpp.svg?branch=master)](https://travis-ci.org/reo7sp/tgbot-cpp) [![Docker Hub pulls](https://img.shields.io/docker/pulls/reo7sp/tgbot-cpp.svg)](https://hub.docker.com/r/reo7sp/tgbot-cpp/) [![GitHub contributors](https://img.shields.io/github/contributors/reo7sp/tgbot-cpp.svg)](https://github.com/reo7sp/tgbot-cpp/graphs/contributors) [![Contact reo7sp](https://img.shields.io/badge/telegram-contact-green.svg)](https://t.me/reo7sp) [![Join the chat at https://gitter.im/reo7sp/tgbot-cpp](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/reo7sp/tgbot-cpp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Donate using PayPal](https://img.shields.io/badge/donate-PayPal-brightgreen.svg)](https://paypal.me/reo7sp) [![Donate using Yandex.Money](https://img.shields.io/badge/donate-Yandex.Money-brightgreen.svg)](https://money.yandex.ru/to/410011554060830) C++ library for Telegram bot API. Documentation is located [here](http://reo7sp.github.io/tgbot-cpp). ## Forks The largest fork of this library is https://github.com/foxcpp/tgbot-cpp. There is a development of payment and video notes APIs and more. ## Library compilation Firstly 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: ```sh sudo apt-get install g++ make binutils cmake libssl-dev libboost-system-dev ``` To compile the library execute this commands: ```sh cd /path/where/you/have/cloned/the/library/repository cmake . make -j4 sudo make install ``` ## Bot compilation ### With CMake [Example CMakeLists.txt](samples/echobot/CMakeLists.txt) ### Without CMake ```sh g++ telegram_bot.cpp -o telegram_bot --std=c++11 -I/usr/local/include -lTgBot -lboost_system -lssl -lcrypto -lpthread ``` You can use Docker to build and run your bot. Set the base image of your's Dockerfile to [reo7sp/tgbot-cpp](https://hub.docker.com/r/reo7sp/tgbot-cpp/). ## Samples Simple echo bot which sends everything it receives: ```cpp #include #include 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 samples are located [here](samples). ## Feedback Feel free to [create new issues on GitHub](https://github.com/reo7sp/tgbot-cpp/issues) or [contact me on Telegram](https://t.me/reo7sp). ## Licence [The MIT License](http://opensource.org/licenses/MIT).