From e285f54a80d9f1f7365698d1b256ea14179b0199 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Fri, 6 Nov 2020 23:59:38 +0200 Subject: [PATCH] Initial commit --- .dockerignore | 2 ++ .gitmodules | 3 ++ README.md | 85 ++++++++++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 44 +++++++++++++++++++++++ telegram-bot-api | 1 + 5 files changed, 135 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitmodules create mode 100644 README.md create mode 100644 docker-entrypoint.sh create mode 160000 telegram-bot-api diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3f7d546 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +./data +.github diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b26414c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "telegram-bot-api"] + path = telegram-bot-api + url = https://github.com/tdlib/telegram-bot-api.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..fb81339 --- /dev/null +++ b/README.md @@ -0,0 +1,85 @@ +# Unofficial Docker image of Telegram Bot API + +Here is Docker image for https://github.com/tdlib/telegram-bot-api + +The Telegram Bot API provides an HTTP API for creating [Telegram Bots](https://core.telegram.org/bots). + +If you've got any questions about bots or would like to report an issue with your bot, kindly contact us at [@BotSupport](https://t.me/BotSupport) in Telegram. + +## Quick reference + +Before start, you will need to obtain `api-id` and `api-hash` as described in https://core.telegram.org/api/obtaining_api_id and specify them using the `TELEGRAM_API_ID` and `TELEGRAM_API_HASH` environment variables. + +And then to start the Telegram Bot API all you need to do is +`docker run -d -p 8081:8081 --name=telegram-bot-api --restart=always -v telegram-bot-api-data:/var/lib/telegram-bot-api -e TELEGRAM_API_ID= -e TELEGRAM_API_HASH= aiogram/telegram-bot-api:latest` + +## Configuration + +Container can be configured via environment variables + +### `TELEGRAM_API_ID`, `TELEGRAM_API_HASH` + +Application identifiers for Telegram API access, which can be obtained at https://my.telegram.org as described in https://core.telegram.org/api/obtaining_api_id + +### `TELEGRAM_STAT` + +Enable statistics HTTP endpoint. + +Usage: `-e TELEGRAM_STAT=1 -p 8082:8082` and then check that `curl http://:8082` returns server statistic + + +### `TELEGRAM_FILTER` + +"/". Allow only bots with 'bot_user_id % modulo == remainder' + + +### `TELEGRAM_MAX_WEBHOOK_CONNECTIONS` + +default value of the maximum webhook connections per bot + +### `TELEGRAM_VERBOSITY` + +log verbosity level + +Logs will be stored to `/var/log/telegram-bot-server` directory inside container + +### `TELEGRAM_MAX_CONNECTIONS` + +maximum number of open file descriptors + +### `TELEGRAM_PROXY` + +HTTP proxy server for outgoing webhook requests in the format http://host:port + +### `TELEGRAM_LOCAL` + +allow the Bot API server to serve local requests + + +## Start with persistent storage + +Server working directory is `/var/lib/telegram-bot-api` so if you want to persist the server data you can mount this folder as volume: + +`-v telegram-bot-api-data:/etc/telegram/bot/api` + +Note that all files in this directory will be owned by user `telegram-bot-api` and group `telegram-bot-api` (uid: `101`, gid: `101`, compatible with [nginx](https://hub.docker.com/_/nginx) image) + +## Usage via docker stack deploy or docker-compose + +```yaml +version: '3.7' + +services: + telegram-bot-api: + image: aiogram/telegram-bot-api:latest + environment: + TELEGRAM_API_ID: "" + TELEGRAM_API_HASH: "" + volumes: + - telegram-bot-api-data:/var/lib/telegram-bot-api + ports: + - 8081:8081 + +volumes: + telegram-bot-api-data: +``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..4685eb1 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,44 @@ +#!/bin/sh +set -e + +LOG_FILENAME="telegram-bot-api.log" + +USERNAME=telegram-bot-api +GROUPNAME=telegram-bot-api + +chown ${USERNAME}:${GROUPNAME} "${TELEGRAM_LOGS_DIR}" "${TELEGRAM_WORK_DIR}" + +if [ -n "${1}" ]; then + exec "${*}" +fi + +DEFAULT_ARGS="--http-port 8081 --dir=${TELEGRAM_WORK_DIR} --temp-dir=${TELEGRAM_TEMP_DIR} --log=${TELEGRAM_LOGS_DIR}/${LOG_FILENAME} --username=${USERNAME} --groupname=${GROUPNAME}" +CUSTOM_ARGS="" + +if [ -n "$TELEGRAM_STAT" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --http-stat-port=8082" +fi +if [ -n "$TELEGRAM_FILTER" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --filter=$TELEGRAM_FILTER" +fi +if [ -n "$TELEGRAM_MAX_WEBHOOK_CONNECTIONS" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --max-webhook-connections=$TELEGRAM_MAX_WEBHOOK_CONNECTIONS" +fi +if [ -n "$TELEGRAM_VERBOSITY" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --verbosity=$TELEGRAM_VERBOSITY" +fi +if [ -n "$TELEGRAM_MAX_CONNECTIONS" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --max-connections=$TELEGRAM_MAX_CONNECTIONS" +fi +if [ -n "$TELEGRAM_PROXY" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --proxy=$TELEGRAM_PROXY" +fi +if [ -n "$TELEGRAM_LOCAL" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --local" +fi + +COMMAND="telegram-bot-api ${DEFAULT_ARGS}${CUSTOM_ARGS}" + +echo "$COMMAND" +# shellcheck disable=SC2086 +exec $COMMAND diff --git a/telegram-bot-api b/telegram-bot-api new file mode 160000 index 0000000..551103b --- /dev/null +++ b/telegram-bot-api @@ -0,0 +1 @@ +Subproject commit 551103b8cda61ef548b1f7673208fbd1acee7fa4