Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Local Bot API support #504

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add Local Bot API support #504

wants to merge 6 commits into from

Conversation

k3it
Copy link
Contributor

@k3it k3it commented Dec 17, 2023

a slightly advanced configuration option to overcome the 20MB file upload limit. e.g. as mentioned here:
#440

more info:
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Local-Bot-API-Server
https://github.com/tdlib/telegram-bot-api
tdlib/telegram-bot-api#381

Instructions for setting up local bot api and nginx dockers:

  1. create telegram-bot-api-data volume (it is going to be shared between the bot api and nginx containers:
docker volume create telegram-bot-api-data
  1. create and start the Bot API container (courtesy of https://github.com/aiogram/telegram-bot-api). docker-compose.yml the Bot API , eg:
version: '3.8'

services:
  telegram-bot-api:
    image: aiogram/telegram-bot-api:latest
    environment:
      TELEGRAM_API_ID: "your api id"
      TELEGRAM_API_HASH: "your api hash"
      TELEGRAM_LOCAL: Yes
      TELEGRAM_STAT: Yes

    volumes:
      - telegram-bot-api-data:/var/lib/telegram-bot-api
    ports:
      - "8081:8081"
      - "8082:8082"
    restart: unless-stopped

volumes:
  telegram-bot-api-data:
    external: true
  1. create the nginx container docker-compose.yml:
version: '3.8'

services:
  nginx:
    image: nginx:latest  # Use the latest Nginx image
    volumes:
      - telegram-bot-api-data:/telegram-bot-api-data  # Mount the external volume
      - ./nginx.conf:/etc/nginx/conf.d/default.conf  # Mount the Nginx configuration file
    ports:
      - "8080:8080"  # Map port 8080 of the host to port 8080 of the container
    restart: unless-stopped

volumes:
  telegram-bot-api-data:  # Define the external volume
    external: true

and nginx.conf file:

server {
    listen 8080;

    server_name localhost;

    location / {
        rewrite ^.*telegram-bot-api(.*)$ /$1 last;
        root /telegram-bot-api-data/;  
        index index.html;
        try_files $uri $uri/ =404;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    # More configuration if necessary...
}

(Adjust the configs above to taste)

  1. configure chatgpt-telegram-bot variables (replace docker.lan with your docker host IP or dns name:
TELEGRAM_BOT_API_URL=http://docker.lan:8081/bot
TELEGRAM_BOT_API_BASE_FILE_URL=http://docker.lan:8080
TELEGRAM_BOT_API_LOCAL_MODE=true

Enjoy unlimited file uploads to the bot!

The commit adds support for running the bot with a local instance of the Telegram Bot API which allows >20MB file uploads. Three new environment variables have been added to configure this mode. Also, related instructions and error messages have been updated to reflect these changes.
@k3it
Copy link
Contributor Author

k3it commented Dec 20, 2023

I noticed a interesting side benefit. the streaming messages work faster - the content in the responses is filled at a very good pace compared to the cloud API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant