Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hypernova7/tg-server
:rocket: Deploy your own Telegram Bot API
https://github.com/hypernova7/tg-server
docker heroku telegram telegram-bot
Last synced: 10 days ago
JSON representation
:rocket: Deploy your own Telegram Bot API
- Host: GitHub
- URL: https://github.com/hypernova7/tg-server
- Owner: hypernova7
- License: mit
- Created: 2022-04-30T02:03:48.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-07T02:14:42.000Z (2 months ago)
- Last Synced: 2024-10-12T18:07:25.871Z (25 days ago)
- Topics: docker, heroku, telegram, telegram-bot
- Language: Python
- Homepage:
- Size: 104 KB
- Stars: 7
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Deploy your own Telegram Bot API
Inspired on aiogram
----
## :sparkles: Features
- Zero config
- Restricted mode (`Only your bots will be able to use your bot API`)
- Easy build of [telegram-bot-api](https://github.com/tdlib/telegram-bot-api)
- Continuous Deployment with Github Actions
- Increase bot API [limits](https://core.telegram.org/bots/api#using-a-local-bot-api-server)
- Your own API endpoint(`https://yourdomain.com/bot/getMe`)
- Deploy your bot API to [Heroku](https://heroku.com) or [fly.io](https://fly.io)## :point_down: Steps
> [!IMPORTANT]
> Need to install [Docker Engine](https://docs.docker.com/engine/install/), [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) or [fly.io CLI](https://fly.io/docs/hands-on/install-flyctl/).> [!NOTE]
> Before deploying, please read [this](https://github.com/tdlib/telegram-bot-api/#moving-a-bot-from-one-local-server-to-another)### Clone this repository
```bash
git clone https://github.com/hypernova7/tg-server.git
cd tg-server
git submodule update --init --recursive
```### Create a Heroku app
```bash
# Sign In on heroku
heroku auth:login
heroku apps:create
```**or**
### Create a fly.io app
```bash
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)
```### Add these environment vars to your app
#### Using Heroku CLI
```bash
# List your bot-ids seprate by commas so that
# only your bots can use the API `:AABBCdfghijklmopqrstuvwxyz1234567890`
heroku config:add ALLOWED_BOT_IDS=,, -a
heroku config:add TELEGRAM_API_ID= TELEGRAM_API_HASH= -a
# NOTE: To pass extra arguments to telegram-bot-api, you can add the environment var EXTRA_ARGS
heroku config:add EXTRA_ARGS="--proxy= --local" -a
```#### Using fly.io CLI
```bash
# List your bot-ids seprate by commas so that
# only your bots can use the API `:AABBCdfghijklmopqrstuvwxyz1234567890`
flyctl secrets set ALLOWED_BOT_IDS=,, -a
flyctl secrets set TELEGRAM_API_ID= TELEGRAM_API_HASH= -a
# NOTE: To pass extra arguments to telegram-bot-api, you can add the environment var EXTRA_ARGS
flyctl secrets set EXTRA_ARGS="--proxy= --local" -a
```> [!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=,:,`### Deploy to Heroku
```bash
# Sign In into Container Registry
heroku container:login
# Push and deploy Container
heroku container:push web -a
heroku container:release web -a
```### Deploy to fly.io
```bash
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
```____
## Environments
```
PORT=8080 # (required) Default port
TELEGRAM_API_ID= # (required) API ID
TELEGRAM_API_HASH= # (required) API HASH
ALLOWED_BOT_IDS= # (required) List of your bot tokens separated by comma
STATS_PATH_NAME= # (optional) Secret path for bot API stats (Stats contain bot tokens)
EXTRA_ARGS=--local # (optional) Pass extra arguments to telegram-bot-api command
```----
## :zap: Continuous Deployment with Github Actions.
### Setup secrets
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.#### For heroku:
```
HEROKU_API_KEY=
HEROKU_APP_NAME=
```#### For fly.io:
```
FLY_API_TOKEN=
```## :sparkling_heart: Special thanks to
[![@sayyid5416](https://github.com/sayyid5416.png?size=50)](https://github.com/sayyid5416)
## :bug: Any issue?
### Please [open a new issue](https://github.com/hypernova7/tg-server/issues)