Giter Club home page Giter Club logo

telebotxx's Introduction

telebotxx

Branch Status
master Build Status
dev Build Status

Telegram Bot API 2.0 for C++14. It uses C++ Requests library to perform HTTP requests and RapidJSON to work with JSON data. In development, so you are welcome to contribute.

Requirements

  • C++14-compatible compiler
  • CMake 2.8 or newer
  • Boost 1.54+
  • Boost Unit Test Framework (only for tests)

Building

You can set available options in CMakeLists.txt before running configure script.

git submodule update --init --recursive
mkdir build
cd build
cmake ..
make

Usage

Sending text message

Here is a simple example of how to send text message:

#include <telebotxx/BotApi.hpp>

std::string token = "YOUR:BOT:TOKEN";
int main()
{
  using namespace telebotxx;
  BotApi bot(token);
  Message answer = bot.sendMessage(ChatId{"@chat_name"},
                                   Text{"Hello, world!"}
                                  );
  return 0;
}

Member function BotApi::sendMessage() returns information about sent message on success or throws an exception.

You can pass additional options in any combination and order:

int messageId = ...; // ID of the original message to reply
Message answer = bot.sendMessage(ChatId{"@chat_name"},
                                 Text{"Hello, world!"},
                                 ReplyTo{messageId},
                                 ParseMode::Markdown,
                                 DisableNotification(),
                                 DisableWebPagePreview()
                                );

Note, that ChatId argument can be specified with its name or id:

ChatId{"@chat_name"}
ChatId{123456}

Sending images

To send a photo use any of the folowing variants depending of image source:

// for local file
Message answer = bot.sendPhoto(ChatId{"@chat_name"}, Photo{File{"photo.jpg"}});

// for in-memory image stored in std::vector
std::vector<char> photo = ...;
Message answer = bot.sendPhoto(ChatId{"@chat_name"},
                               Photo{Buffer{photo, "photo.jpg"}}
                              );

// for in-memory image stored in C-array
Message answer = bot.sendPhoto(ChatId{"@chat_name"},
                               Photo{Buffer{photo.data(), photo.size(), "photo.jpg"}}
                              );

// for image available by URL
Message answer = bot.sendPhoto(ChatId{"@chat_name"},
                               Photo{Url{"http://sample.com/sample.jpg"}}
                              );

// for already uploaded photo you can send it by id
Message answer = bot.sendPhoto(ChatId{"@chat_name"}, Photo{123456});

As in the case of messages, you can pass additional options:

Message answer = bot.sendPhoto(ChatId{"@chat_name"},
                               Photo{File{"photo.jpg"}}
                               Caption{"Sample photo"},
                               ReplyTo(messageId),
                               DisableNotification()
                              );

telebotxx's People

Contributors

ultracoderru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jackkek

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.