GithubHelp home page GithubHelp logo

athena1433 / tgbot-cpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from reo7sp/tgbot-cpp

0.0 0.0 0.0 5.94 MB

C++ library for Telegram bot API

Home Page: http://reo7sp.github.io/tgbot-cpp

License: MIT License

CMake 0.83% C++ 97.19% Shell 0.32% Dockerfile 0.10% C 1.55%

tgbot-cpp's Introduction

tgbot-cpp

Travis build Status
GitHub contributors

C++14 library for Telegram bot API.

Documentation is located here.

State

  • Bot API 3.0 ~ 3.6
  • Bot API 4.0 ~ 4.4 (Implemented all APIs except 'Telegram Passport')

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

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:

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

If you want to use curl-based http client CurlHttpClient, you also need to install libcurl4-openssl-dev package.

Library installation

If 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 compilation

With CMake

Example CMakeLists.txt

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.

tgbot-cpp's People

Contributors

reo7sp avatar egorpugin avatar jellybrick avatar kukin-konstantin avatar aadeg avatar flode avatar ogretransporter avatar yjbeetle avatar nitanmarcel avatar mpsspm avatar zamazan4ik avatar andijcr avatar wtdcode avatar behrouz-m avatar ymuv avatar nesc1 avatar ingjieye avatar asapelkin avatar xdqi avatar xvitaly avatar naveenvhegde avatar gravechapa avatar vanbwodonk avatar demidko avatar derobyj avatar chungzh avatar kirilldanilchuk avatar nicholascw avatar gitter-badger avatar smertig avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.