no-name-here commited on
Commit
a01d897
Β·
verified Β·
1 Parent(s): 0310c2c

Update config-example.py

Browse files
Files changed (1) hide show
  1. config-example.py +51 -30
config-example.py CHANGED
@@ -1,30 +1,51 @@
1
- # ─── How to connect your bot to the self-hosted Telegram Bot API server ───────
2
- #
3
- # Replace YOUR-SPACE-URL with your actual HF Space URL, e.g.:
4
- # https://akshay-telegram-bot-api.hf.space
5
- #
6
- # Set this BEFORE creating the bot instance.
7
- # ─────────────────────────────────────────────────────────────────────────────
8
-
9
- import os
10
- import telebot
11
- from telebot import apihelper
12
-
13
- # ── Option A: hardcoded (simplest) ───────────────────────────────────────────
14
- apihelper.API_URL = "https://YOUR-SPACE-URL.hf.space/bot{0}/{1}"
15
-
16
- # ── Option B: via environment variable (recommended) ─────────────────────────
17
- # Set BOT_API_SERVER=https://YOUR-SPACE-URL.hf.space in your env
18
- # Falls back to official api.telegram.org if not set
19
-
20
- BOT_API_SERVER = os.getenv("BOT_API_SERVER")
21
- if BOT_API_SERVER:
22
- apihelper.API_URL = f"{BOT_API_SERVER.rstrip('/')}/bot{{0}}/{{1}}"
23
- # if not set, telebot uses api.telegram.org by default β€” no change needed
24
-
25
- # ── Create bot as normal ──────────────────────────────────────────────────────
26
- TOKEN = os.environ["BOT_TOKEN"]
27
- bot = telebot.TeleBot(TOKEN)
28
-
29
- # Everything else in your bot stays exactly the same.
30
- # @bot.message_handler, bot.send_message, bot.infinity_polling β€” all unchanged.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:22.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+
5
+ # ── Build dependencies ────────────────────────────────────────────────────────
6
+ RUN apt-get update && apt-get install -y \
7
+ cmake \
8
+ g++ \
9
+ git \
10
+ libssl-dev \
11
+ zlib1g-dev \
12
+ gperf \
13
+ make \
14
+ curl \
15
+ ca-certificates \
16
+ && rm -rf /var/lib/apt/lists/*
17
+
18
+ # ── Clone and build the official Telegram Bot API server ─────────────────────
19
+ # Pin to a specific commit for reproducibility
20
+ RUN git clone --recursive https://github.com/tdlib/telegram-bot-api.git /tmp/telegram-bot-api
21
+
22
+ WORKDIR /tmp/telegram-bot-api
23
+
24
+ RUN mkdir build && cd build && \
25
+ cmake -DCMAKE_BUILD_TYPE=Release \
26
+ -DCMAKE_INSTALL_PREFIX:PATH=/usr/local \
27
+ .. && \
28
+ cmake --build . --target install -j$(nproc)
29
+
30
+ # ── Runtime setup ─────────────────────────────────────────────────────────────
31
+ RUN mkdir -p /data /var/log/telegram-bot-api
32
+
33
+ # HuggingFace Spaces requires the app to run as a non-root user
34
+ RUN useradd -m -u 1000 botapi && \
35
+ chown -R botapi:botapi /data /var/log/telegram-bot-api
36
+
37
+ USER botapi
38
+
39
+ # HF Spaces exposes port 7860
40
+ EXPOSE 7860
41
+
42
+ # ── Entrypoint ────────────────────────────────────────────────────────────────
43
+ # API_ID and API_HASH must be set as HF Space secrets
44
+ CMD telegram-bot-api \
45
+ --api-id=${API_ID} \
46
+ --api-hash=${API_HASH} \
47
+ --http-port=7860 \
48
+ --dir=/data \
49
+ --temp-dir=/data/temp \
50
+ --log=/var/log/telegram-bot-api/server.log \
51
+ --verbosity=1