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

Create config-example.py

Browse files
Files changed (1) hide show
  1. config-example.py +30 -0
config-example.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.