The Telegram Bot API provides an HTTP API for creating Telegram Bots. https://tdlight-team.github.io
Go to file
2021-10-26 14:27:03 +03:00
td@0208b7058b Update TDLib. 2021-09-29 20:34:21 +03:00
telegram-bot-api Limit number of concurrently sent messages to a chat. 2021-10-01 14:52:47 +03:00
.clang-format Update .clang-format. 2020-12-23 10:39:52 +03:00
.gitattributes Telegram Bot APi server initial commit. 2020-11-03 19:34:10 +03:00
.gitignore Telegram Bot APi server initial commit. 2020-11-03 19:34:10 +03:00
.gitmodules Fix submodule URL. 2020-11-04 17:29:42 +03:00
build.html Explicitly mention that libc++ needs to be installed when clang is used. 2021-10-26 14:27:03 +03:00
CMakeLists.txt Update version to 5.3.3. 2021-09-20 23:56:53 +03:00
LICENSE_1_0.txt Telegram Bot APi server initial commit. 2020-11-03 19:34:10 +03:00
README.md Explicitly specify differences of local mode in README. 2020-11-04 18:09:18 +03:00

Telegram Bot API

The Telegram Bot API provides an HTTP API for creating Telegram Bots.

If you've got any questions about bots or would like to report an issue with your bot, kindly contact us at @BotSupport in Telegram.

Please note that only global Bot API issues that affect all bots are suitable for this repository.

Table of Contents

Installation

The simplest way to build and install Telegram Bot API server is to use our Telegram Bot API server build instructions generator. If you do that, you'll only need to choose the target operating system to receive the complete build instructions.

In general, you need to install all Telegram Bot API server dependencies and compile the source code using CMake:

git clone --recursive https://github.com/tdlib/telegram-bot-api.git
cd telegram-bot-api
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --target install

Dependencies

To build and run Telegram Bot API server you will need:

  • OpenSSL
  • zlib
  • C++14 compatible compiler (e.g., Clang 3.4+, GCC 4.9+, MSVC 19.0+ (Visual Studio 2015+), Intel C++ Compiler 17+) (build only)
  • gperf (build only)
  • CMake (3.0.2+, build only)

Usage

Use telegram-bot-api --help to receive the list of all available options of the Telegram Bot API server.

The only mandatory options are --api-id and --api-hash. You must obtain your own api_id and api_hash as described in https://core.telegram.org/api/obtaining_api_id and specify them using the --api-id and --api-hash options or the TELEGRAM_API_ID and TELEGRAM_API_HASH environment variables.

To enable Bot API features not available at https://api.telegram.org, specify the option --local. In the local mode the Bot API server allows to:

  • Download files without a size limit.
  • Upload files up to 2000 MB.
  • Upload files using their local path and the file URI scheme.
  • Use an HTTP URL for the webhook.
  • Use any local IP address for the webhook.
  • Use any port for the webhook.
  • Set max_webhook_connections up to 100000.
  • Receive the absolute local path as a value of the file_path field without the need to download the file after a getFile request.

The Telegram Bot API server accepts only HTTP requests, so a TLS termination proxy needs to be used to handle remote HTTPS requests.

By default the Telegram Bot API server is launched on the port 8081, which can be changed using the option --http-port.

Documentation

See Bots: An introduction for developers for a brief description of Telegram Bots and their features.

See the Telegram Bot API documentation for a description of the Bot API interface and a complete list of available classes, methods and updates.

See the Telegram Bot API server build instructions generator for detailed instructions on how to build the Telegram Bot API server.

Subscribe to @BotNews to be the first to know about the latest updates and join the discussion in @BotTalk.

Moving a bot to a local server

To guarantee that your bot will receive all updates, you must deregister it with the https://api.telegram.org server by calling the method logOut. After the bot is logged out, you can replace the address to which the bot sends requests with the address of your local server and use it in the usual way. If the server is launched in --local mode, make sure that the bot can correctly handle absolute file paths in response to getFile requests.

Moving a bot from one local server to another

If the bot is logged in on more than one server simultaneously, there is no guarantee that it will receive all updates. To move a bot from one local server to another you can use the method logOut to log out on the old server before switching to the new one.

If you want to avoid losing updates between logging out on the old server and launching on the new server, you can remove the bot's webhook using the method deleteWebhook, then use the method close to close the bot instance. After the instance is closed, locate the bot's subdirectory in the working directory of the old server by the bot's user ID, move the subdirectory to the working directory of the new server and continue sending requests to the new server as usual.

License

Telegram Bot API server source code is licensed under the terms of the Boost Software License. See LICENSE_1_0.txt for more information.