Sign inSign up

heilkit/telegram-bot-api

By heilkit

•Updated over 2 years ago

Plug-and-play Telegram Bot API server. Alpine based, cross-compiled for amd64, arm64, arm/v7.

Image
1

1.9K

heilkit/telegram-bot-api repository overview

⁠Quick refference

The solo purpose of this package is to provide the most hands-free experience of running your own Telegram Bot API server.

⁠Advantages of your own Telegram Bot API:

  • 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.

Official source: https://github.com/tdlib/telegram-bot-api⁠.

NOTE: If you don't have Telegram app API keys, you could get them at https://core.telegram.org/api/obtaining_api_id⁠.

NOTE: These commands include sudo, you might need to replace/delete it depending on your system.

  1. git clone https://github.com/heilkit/telegram-bot-api && cd telegram-bot-api
  2. Provide your API ID and HASH in .env file.
  3. USER_ID="$(id -u)" GROUP_ID="$(id -g)" sudo docker compose up -d

Alternatively you could use a "one-liner":

git clone https://github.com/heilkit/telegram-bot-api && 
cd telegram-bot-api && 
"${EDITOR:-nano}" .env && 
USER_ID="$(id -u)" GROUP_ID="$(id -g)" sudo docker compose up -d

⁠Setup via classic Docker

  1. git clone https://github.com/heilkit/telegram-bot-api && cd telegram-bot-api
  2. Create storage directory, i.e., /var/lib/telegram-bot-api (replace it with something custom, if you wish, but make sure it matches the -d argument of telegram-bot-api).
  3. Ensure, you put good permissions on the directory, sudo setfacl -m u:$(id -u):rwx -R /var/lib/telegram-bot-api.
  4. sudo STORAGE=/var/lib/telegram-bot-api docker run --name telegram-bot-api -u "$(id -u):$(id -g)" --restart=always -v $STORAGE:$STORAGE -d heilkit/telegram-bot-api -d $STORAGE -v 1 --local --api-id=<API_ID> --api-hash=<API_HASH>

⁠compose.yaml example

# Why compose.yaml is so complicated?
# Because of Docker file permission nuances, and your bots wanting to be able to access your local telegram-bot-api's files.
#
# Recommended command to run this (unless you've defined $USER_ID & $GROUP_ID in your ENV):
# USER_ID="$(id -u)" GROUP_ID="$(id -g)" sudo docker compose up -d
services:
  telegram-bot-api:
    image: heilkit/telegram-bot-api:latest
    command: -d "${STORAGE}" -v 1 --local --api-id="${API_ID}" --api-hash="${API_HASH}"
    restart: on-failure:10
    depends_on:
      telegram-bot-api-prelude:
        condition: service_completed_successfully
    env_file:
      - .env
    user: ${USER_ID}:${GROUP_ID}
    ports:
      - ${PORT}:8081
    volumes:
      - ${STORAGE}:${STORAGE}
    environment:
      - API_ID
      - API_HASH
      - PORT
      - STORAGE
      - USER_ID
      - GROUP_ID

  # This could be moved into a separated image, but I don't think it's necessary hence
  # telegram-bot-api wouldn't get restated too often and this image weights only 10MB. So, KISS.
  telegram-bot-api-prelude:
    image: alpine:latest
    entrypoint: apk add --update --no-cache acl && setfacl -m u:${USER_ID}:rwx -R ${STORAGE}
    volumes:
      - ${STORAGE}:${STORAGE}

Tag summary

Content type

Image

Digest

sha256:6e5634c16…

Size

16 MB

Last updated

over 2 years ago

docker pull heilkit/telegram-bot-api