• Stars
    star
    950
  • Rank 46,941 (Top 1.0 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++ library for Telegram bot API

tgbot-cpp

GitHub contributors

C++ library for Telegram bot API.

Documentation is located here.

State

  • Telegram Bot API 6.5

Sample

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

Dependencies:

  • CMake
  • Boost
  • OpenSSL
  • ZLib
  • Libcurl (optional unless you want to use curl-based http client CurlHttpClient).

Library installation on Linux

You can install dependencies on Debian-based distibutives with these commands:

sudo apt-get install g++ make binutils cmake libboost-system-dev libssl-dev zlib1g-dev libcurl4-openssl-dev

You can compile and install the library with these commands:

git clone https://github.com/reo7sp/tgbot-cpp
cd tgbot-cpp
cmake .
make -j4
sudo make install

Alternatively, you can use Docker to build and run your bot. Set the base image of your's Dockerfile to reo7sp/tgbot-cpp.

Library installation on MacOS

You can install dependencies with these commands:

brew install gcc cmake boost openssl zlib curl

You can compile and install the library like Linux instructions.

Library installation on Windows

Download vcpkg and tgbot-cpp

Taken from Vcpkg - Quick Start: Windows.

Prerequisites:

  • Windows 7 or newer
  • Git
  • Visual Studio 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.bat

In order to use vcpkg with Visual Studio, run the following command (may require administrator elevation):

> .\vcpkg\vcpkg integrate install

To install the libraries for Windows x64, run:

> .\vcpkg\vcpkg install tgbot-cpp:x64-windows

To install for Windows x86, run:

> .\vcpkg\vcpkg install tgbot-cpp

The library will now be installed and Visual Studio should be able to find the vcpkg installation.

Setup project with CMakeLists

Use the example CMakeLists.txt with changes:

  1. Remove /usr/local/include
  2. Change /usr/local/lib/libTgBot.a to C:/src/vcpkg/installed/x64-windows/lib/TgBot.lib or something simmilar according to your own installation path.

Bot compilation

With CMake

Example CMakeLists.txt

Also, you can treat this repository as a submodule of your project, for example, see echobot-submodule.

Without CMake

g++ telegram_bot.cpp -o telegram_bot --std=c++14 -I/usr/local/include -lTgBot -lboost_system -lssl -lcrypto -lpthread

Build options

-DTGBOT_DISABLE_NAGLES_ALGORITHM   # Disable 'Nagle's algorithm'
-DTGBOT_CHANGE_SOCKET_BUFFER_SIZE  # Socket Buffer Size Expansion
-DTGBOT_CHANGE_READ_BUFFER_SIZE    # Read Buffer Size Expansion

Licence

The MIT License.

More Repositories

1

vk-channelify

Create Telegram channel from VK group
Python
20
star
2

baumanki-net-tools

Скачивает и распаковывает файлы с сайта studizba.com (ранее baumanki.net)
Python
9
star
3

ReoVimRC

Vim config
Vim Script
5
star
4

dotfiles

Config files
Shell
4
star
5

uwsgi-php-docker

Docker image for uwsgi with pre-installed php plugin
Dockerfile
3
star
6

minimal-ok-page

Sane defaults for simple pages with text
HTML
3
star
7

tells

Хорошие ссылки
HTML
3
star
8

Rocket.CMS

DISCONTINUED: Check out https://github.com/reo7sp/thylogale
C++
2
star
9

swagger-ui-fancier

Swagger UI with css fixes
HTML
2
star
10

drop

Drop text for 5 minutes
Go
2
star
11

jetbrains-internship-testtask

Go
2
star
12

generator-cocos-starter-kit

Boilerplate for cocos2d-x javascript games
JavaScript
2
star
13

GoToHack2

Предсказывание лайков, репостов и лайков от репостов
Jupyter Notebook
2
star
14

phabricator-docker

Docker image for phabricator
Shell
2
star
15

resume

HTML
2
star
16

reo-web-starter-kit

Boilerplate for sites (gulp + browserify + coffeescript + sass + nunjucks)
CoffeeScript
2
star
17

two-step-migrate

SQL migration tool for blue-green deployments
Go
2
star
18

Socn

VK and Twitter desktop notifications
Java
1
star
19

NoBadge

Automatically marks muted conversations as read so you won't distracted by them
Python
1
star
20

technopark-algo

Домашка к курсу "Алгоритмы" Технопарка Mail.Ru
C++
1
star
21

generator-reo-web-starter-kit

Boilerplate for sites
JavaScript
1
star
22

http-repo

Simple as a stick tool to save and fetch files
Python
1
star
23

dokku-mariadb-sc

MariaDB in single container dokku plugin
Shell
1
star
24

thylogale

Content management system (CMS) for static sites
Ruby
1
star
25

recaptcha-demo

Used to get 'g-recaptcha-response' key
HTML
1
star
26

technopark-db

Домашка к курсу "Базы Данных" Технопарка Mail.Ru
Go
1
star
27

Face3dMatch

Андроид апп, который авторизирует человека по 3Д модели
Scala
1
star
28

vk-autoread

Автоматически помечает беседы прочитанными, чтобы не маячил гребанный кружочек с циферкой
Python
1
star