Spaces:
Build error
Build error
Create config-example.py
Browse files- 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.
|