Spaces:
Build error
Build error
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,10 +1,97 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
-
pinned:
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Telegram Bot API Server
|
| 3 |
+
emoji: π€
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: docker
|
| 7 |
+
pinned: true
|
| 8 |
+
app_port: 7860
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Telegram Bot API Server
|
| 12 |
+
|
| 13 |
+
A self-hosted instance of the [official Telegram Bot API server](https://github.com/tdlib/telegram-bot-api) running on HuggingFace Spaces.
|
| 14 |
+
|
| 15 |
+
It speaks **MTProto** internally to Telegram's DCs (port 443), so it works even where `api.telegram.org` HTTP is blocked β including HuggingFace Spaces.
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## Setup
|
| 20 |
+
|
| 21 |
+
### 1. Get API credentials
|
| 22 |
+
|
| 23 |
+
Go to [my.telegram.org](https://my.telegram.org), log in, and create an app.
|
| 24 |
+
You'll get an **API ID** (number) and **API Hash** (string).
|
| 25 |
+
|
| 26 |
+
### 2. Set Space secrets
|
| 27 |
+
|
| 28 |
+
In your HF Space β **Settings** β **Repository secrets**, add:
|
| 29 |
+
|
| 30 |
+
| Name | Value |
|
| 31 |
+
|------|-------|
|
| 32 |
+
| `API_ID` | your numeric API ID |
|
| 33 |
+
| `API_HASH` | your API hash string |
|
| 34 |
+
|
| 35 |
+
### 3. Use in your bot
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
from telebot import apihelper
|
| 39 |
+
|
| 40 |
+
apihelper.API_URL = "https://YOUR-SPACE-NAME.hf.space/bot{0}/{1}"
|
| 41 |
+
|
| 42 |
+
bot = telebot.TeleBot(os.environ["BOT_TOKEN"])
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
Replace `YOUR-SPACE-NAME` with your actual HF Space URL slug
|
| 46 |
+
(e.g. `yourusername-telegram-bot-api-server`).
|
| 47 |
+
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
## How it works
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
your bot (HTTP)
|
| 54 |
+
β
|
| 55 |
+
this HF Space (Bot API server)
|
| 56 |
+
β MTProto on port 443
|
| 57 |
+
Telegram Data Centers
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
The Bot API server translates standard HTTP Bot API calls into MTProto,
|
| 61 |
+
which HuggingFace does not block.
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
|
| 65 |
+
## Supported by all pyTelegramBotAPI / python-telegram-bot bots
|
| 66 |
+
|
| 67 |
+
**pyTelegramBotAPI:**
|
| 68 |
+
```python
|
| 69 |
+
from telebot import apihelper
|
| 70 |
+
apihelper.API_URL = "https://YOUR-SPACE.hf.space/bot{0}/{1}"
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
**python-telegram-bot:**
|
| 74 |
+
```python
|
| 75 |
+
from telegram.constants import BOT_API_URL
|
| 76 |
+
application = Application.builder() \
|
| 77 |
+
.token(TOKEN) \
|
| 78 |
+
.base_url("https://YOUR-SPACE.hf.space/bot") \
|
| 79 |
+
.build()
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
**aiogram:**
|
| 83 |
+
```python
|
| 84 |
+
from aiogram.client.session.aiohttp import AiohttpSession
|
| 85 |
+
session = AiohttpSession(api=TelegramAPIServer.from_base("https://YOUR-SPACE.hf.space"))
|
| 86 |
+
bot = Bot(token=TOKEN, session=session)
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
## Notes
|
| 92 |
+
|
| 93 |
+
- This space is meant to be **private** β set it to private in HF settings
|
| 94 |
+
so only you can use it
|
| 95 |
+
- All your bots can share this single space
|
| 96 |
+
- The `/data` directory stores temporary files (file downloads etc.)
|
| 97 |
+
- Logs are written to `/var/log/telegram-bot-api/server.log`
|