Deploy your own Telegram Bot API
Inspired on aiogram
- Zero config
- Restricted mode (
Only your bots will be able to use your bot API
) - Easy build of telegram-bot-api
- Continuous Deployment with Github Actions
- Increase bot API limits
- Your own API endpoint(
https://yourdomain.com/bot<token>/getMe
) - Deploy your bot API to Heroku or fly.io
Important
Need to install Docker Engine, Heroku CLI or fly.io CLI.
Note
Before deploying, please read this
git clone https://github.com/hypernova7/tg-server.git
cd tg-server
git submodule update --init --recursive
# Sign In on heroku
heroku auth:login
heroku apps:create <heroku-app-name>
or
flyctl auth signup
flyctl auth login
flyctl launch # This command will generate a fly.toml file (Please see this: https://fly.io/docs/reference/configuration/#fly-toml-line-by-line)
# List your bot-ids seprate by commas so that
# only your bots can use the API `<bot-id>:AABBCdfghijklmopqrstuvwxyz1234567890`
heroku config:add ALLOWED_BOT_IDS=<bot-id>,<bot-id>,<bot-id> -a <heroku-app-name>
heroku config:add TELEGRAM_API_ID=<api-id> TELEGRAM_API_HASH=<api-hash> -a <heroku-app-name>
# NOTE: To pass extra arguments to telegram-bot-api, you can add the environment var EXTRA_ARGS
heroku config:add EXTRA_ARGS="--proxy=<proxy> --local" -a <heroku-app-name>
# List your bot-ids seprate by commas so that
# only your bots can use the API `<bot-id>:AABBCdfghijklmopqrstuvwxyz1234567890`
flyctl secrets set ALLOWED_BOT_IDS=<bot-id>,<bot-id>,<bot-id> -a <heroku-app-name>
flyctl secrets set TELEGRAM_API_ID=<api-id> TELEGRAM_API_HASH=<api-hash> -a <heroku-app-name>
# NOTE: To pass extra arguments to telegram-bot-api, you can add the environment var EXTRA_ARGS
flyctl secrets set EXTRA_ARGS="--proxy=<proxy> --local" -a <heroku-app-name>
Tip
Optionally and if required, you can set the SWAP_SIZE environment variable to setup swap, by default is disabled. Example: SWAP_SIZE=51200K
(51200K
= 50MB
) or SWAP_SIZE=200M
(200M
= 200MB
) or SWAP_SIZE=4G
(4GB
= 4GB
) or SWAP_SIZE=8589934592
(8589934592
= 8GB
in bytes)
Tip
Optionally can add full-tokens to ALLOWED_BOT_IDS, if you want to avoid exposing your token when sharing links to your bot files. For example: ALLOWED_BOT_IDS=<bot-id>,<bot-id>:<bot-token>,<bot-id>
# Sign In into Container Registry
heroku container:login
# Push and deploy Container
heroku container:push web -a <heroku-app-name>
heroku container:release web -a <heroku-app-name>
flyctl deploy
# Run the following commands only once
# Since it allocates IP's as many as it runs
# Please see this https://fly.io/docs/flyctl/ips/#usage
flyctl ips allocate-v4
flyctl ips allocate-v6
PORT=8080 # (required) Default port
TELEGRAM_API_ID=<api-id> # (required) API ID
TELEGRAM_API_HASH=<api-hash> # (required) API HASH
ALLOWED_BOT_IDS=<your-bot-tokens> # (required) List of your bot tokens separated by comma
STATS_PATH_NAME=<my-secret-stats-path> # (optional) Secret path for bot API stats (Stats contain bot tokens)
EXTRA_ARGS=--local # (optional) Pass extra arguments to telegram-bot-api command
This repository already provides pre-configured Workflows for Heroku and fly.io. You only need to setup the following secrets on Settings > Secrets > Actions
.
Caution
Workflows are scheduled to run every day at 12am UTC, and auto-deploy on any updates to the telegram-bot-api submodule. Optionally, can add FORCE_DEPLOY=true
to your repository secrets or _deploy_
to your specific commit message to force the deployment. But remember, these Workflows runs everyday.
Important
For private repositories, please enable read and write permissions in Settings > Actions > General > Workflows permissions
for auto commits, to keep telegram-bot-api submodules updated if you want.
HEROKU_API_KEY=<heroku-api-key>
HEROKU_APP_NAME=<heroku-app-name>
FLY_API_TOKEN=<your-fly-api-token>