Skip to content

ragnarok22/telegram-bot-api-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot API Dockerized

Dockerized Telegram Bot API

Docker Image Version Docker Pulls Docker Image Size

Dockerized Telegram Bot API server.

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

Table of Contents

Installation

  • Install Docker
  • Pull the image from Docker Hub
    docker pull ragnarok22/telegram-bot-api-docker
  • Create a .env file with the following content
    TELEGRAM_API_ID=12345
    TELEGRAM_API_HASH=1234567890abcdef1234567890abcdef
    You can get the TELEGRAM_API_ID and TELEGRAM_API_HASH from Telegram's website
  • Run the container
    docker run -d -p 8081:8081 ragnarok22/telegram-bot-api-docker
  • The server will be available at http://localhost:8081

Also, you can use Docker Compose to run the container

version: '3'
services:
  telegram-bot-api:
    image: ragnarok22/telegram-bot-api-docker
    ports:
      - "8081:8081"
    env_file:
      - .env

Environment Variables

  • TELEGRAM_API_ID: The API ID obtained from Telegram's website
  • TELEGRAM_API_HASH: The API hash obtained from Telegram's website
  • TELEGRAM_HTTP_PORT: The port the server will listen to. Default is 8081
  • TELEGRAM_HTTP_STAT_PORT: The port the server will listen to for statistics. Default is 8082
  • TELEGRAM_DIR: The directory where the server will store the data. Default is /data
  • TELEGRAM_TEMP_DIR: The directory where the server will store temporary files. Default is /tmp
  • TELEGRAM_LOG_FILE: The file where the server will store the logs. Default is /data/logs/telegram-bot-api.log
  • TELEGRAM_LOCAL: If set to true, the server will run in local mode. Default is false

Usage

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.

Switching

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

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 for more information.