Skip to content

Commit 5390750

Browse files
committed
Updated docs
1 parent ca7d973 commit 5390750

10 files changed

Lines changed: 703 additions & 183 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Customizing Bot Reply Text
2+
3+
TG-FileStream uses a translation registry system to manage reply texts.
4+
5+
All default messages are defined in:
6+
7+
tgfs/utils/translation.py
8+
9+
Messages are loaded using a registry-based system.
10+
11+
This allows overriding text without modifying core files.
12+
13+
---
14+
15+
# How It Works
16+
17+
The core project defines:
18+
19+
- A base language class (`en`)
20+
- A registry dictionary
21+
- Messages fetched dynamically via registry
22+
23+
Example (simplified):
24+
25+
```python
26+
registry = {}
27+
registry["en"] = en
28+
```
29+
30+
When the bot needs a message, it fetches it from the active language class in the registry.
31+
32+
---
33+
34+
# Overriding Reply Text Using a Patch
35+
36+
To override messages, you create a patch that:
37+
38+
1. Inherits from the base language class
39+
2. Overrides specific text variables
40+
3. Registers your custom class into the registry
41+
42+
---
43+
44+
# Official CustomReply Patch
45+
46+
You can use the official template:
47+
48+
https://github.com/SpringsFern/CustomReply
49+
50+
---
51+
52+
# Step-by-Step Guide
53+
54+
## 1. Fork the Repository
55+
56+
Fork:
57+
58+
https://github.com/SpringsFern/CustomReply
59+
60+
Modify the code inside:
61+
62+
```
63+
CustomReply/__init__.py
64+
```
65+
66+
---
67+
68+
## 2. Example Customization
69+
70+
```python
71+
from tgfs.utils.translation import registry, en
72+
73+
class CustomText(en):
74+
START_TEXT = "Hey there how are you\nYou can send me any file and I will generate a link for that file."
75+
76+
registry["en"] = CustomText
77+
```
78+
79+
This overrides the default `START_TEXT`.
80+
81+
You can override any variable defined in:
82+
83+
https://github.com/SpringsFern/TG-FileStream/blob/main/tgfs/utils/translation.py
84+
85+
---
86+
87+
## 3. Install the Patch
88+
89+
Clone your fork inside:
90+
91+
```
92+
<TG-FileStream base folder>/tgfs/patches/
93+
```
94+
95+
Example:
96+
97+
```bash
98+
cd tgfs/patches
99+
git clone https://github.com/<your-username>/CustomReply
100+
```
101+
102+
---
103+
104+
## 4. Restart TG-FileStream
105+
106+
```bash
107+
sudo systemctl restart tgfs
108+
```
109+
110+
Or if running manually:
111+
112+
```bash
113+
python -m tgfs
114+
```
115+
116+
---
117+
118+
# Adding New Language Support
119+
120+
You can:
121+
122+
1. Submit pull request to:
123+
https://github.com/SpringsFern/tgfs_translation
124+
125+
OR
126+
127+
2. Add new language class inside your patch:
128+
129+
```python
130+
class CustomSpanish(en):
131+
START_TEXT = "Hola!"
132+
133+
registry["es"] = CustomSpanish
134+
```
135+
136+
---
137+
138+
# Best Practices
139+
140+
- Do not modify `translation.py` directly.
141+
- Always use patches.
142+
- Only override variables you need.
143+
- Keep your patch repository separate for easier upgrades.

docs/customization/index.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Customization Overview
2+
3+
TG-FileStream supports modular customization without modifying core logic.
4+
5+
The project is structured to allow:
6+
7+
- External feature injection
8+
- Patch-based enhancements
9+
- Optional components
10+
11+
---
12+
13+
## Architecture Overview
14+
15+
Core
16+
17+
18+
19+
Extension Loader
20+
21+
22+
23+
Patches
24+
25+
26+
27+
Runtime Behavior
28+
29+
---
30+
31+
## Customization Methods
32+
33+
### 1. Configuration-based
34+
35+
Modify `.env` variables to change behavior.
36+
37+
[Environment Variables](../setup/environment-variables/)
38+
39+
### 2. Patch-Based
40+
41+
Inject behavior into specific lifecycle hooks.
42+
43+
---
44+
45+
## Recommended Workflow
46+
47+
1. Do NOT modify core files.
48+
2. Create a patch.
49+
3. Test locally.
50+
4. Deploy.

docs/customization/patches.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Official Patches
2+
3+
This page lists patches officially maintained for TG-FileStream.
4+
5+
Patches extend functionality without modifying core files.
6+
7+
---
8+
9+
## Available Patches
10+
### 1. Custom Reply Templates
11+
[GitHub](https://github.com/SpringsFern/CustomReply)
12+
13+
Allows overriding default bot reply messages.
14+
See:
15+
[/customization/customize-replies.md](./customize-replies.md)
16+
17+
### 2. WebPlayer
18+
[GitHub](https://github.com/SpringsFern/tgfs_webplayer)
19+
20+
Simple HTML5 Player
21+
22+
### 3. Translation
23+
[GitHub](https://github.com/SpringsFern/tgfs_translation)
24+
25+
Translation of Bot Reply text to additional languages
26+
27+
## How Patches Work
28+
29+
Patches are loaded during application startup.
30+
31+
They:
32+
33+
- Hook into lifecycle events
34+
- Override default behavior
35+
- Extend functionality
36+
37+
---
38+
39+
⚠ Always verify compatibility before upgrading core version.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Architecture
2+
3+
This page explains how TG-FileStream works internally.
4+
5+
---
6+
7+
## High-Level Architecture
8+
9+
User → Cloudflare (Optional) → Nginx Reverse Proxy → TGFS Workers → Telegram API
10+
11+
---
12+
13+
## Core Components
14+
15+
### 1. Telegram Client Layer
16+
17+
Handles:
18+
19+
- Receiving files
20+
- Sending files to bin channel
21+
- Generating file metadata
22+
- Managing flood waits
23+
24+
---
25+
26+
### 2. HTTP Streaming Layer
27+
28+
Built using:
29+
30+
- aiohttp
31+
32+
Responsible for:
33+
34+
- Handling incoming HTTP requests
35+
- Serving file streams
36+
- Managing chunked downloads
37+
38+
---
39+
40+
### 3. Worker Layer
41+
42+
Each worker:
43+
44+
- Runs on a separate port
45+
- Maintains its own session
46+
- Handles HTTP requests independently
47+
48+
Nginx distributes traffic across workers.
49+
50+
---
51+
52+
### 4. Reverse Proxy (Nginx)
53+
54+
Responsible for:
55+
56+
- Load balancing
57+
- HTTPS termination
58+
- Client buffering control
59+
- Connection management
60+
61+
---
62+
63+
### 5. Patch System
64+
65+
During startup:
66+
67+
- TGFS loads patches from `tgfs/patches/`
68+
- Extensions modify behavior
69+
- Translation overrides are registered
70+
71+
This enables safe customization.
72+
73+
---
74+
75+
## Data Flow Example
76+
77+
1. User sends file to bot
78+
2. File and Metadata is stored in Database
79+
3. Download link generated
80+
4. User accesses link
81+
5. Nginx forwards request to worker
82+
6. Worker fetches file from Telegram
83+
7. File streamed to user
84+
85+
---
86+
87+
## Scaling Model
88+
89+
Scaling is achieved by:
90+
91+
- Running multiple worker services
92+
- Using Nginx upstream with `least_conn`
93+
- Optionally using multiple bot tokens

0 commit comments

Comments
 (0)