telebot-mtproto 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- telebot_mtproto-1.0.0/LICENSE +21 -0
- telebot_mtproto-1.0.0/PKG-INFO +104 -0
- telebot_mtproto-1.0.0/README.md +88 -0
- telebot_mtproto-1.0.0/pyproject.toml +26 -0
- telebot_mtproto-1.0.0/setup.cfg +4 -0
- telebot_mtproto-1.0.0/telebot_mtproto/__init__.py +4 -0
- telebot_mtproto-1.0.0/telebot_mtproto/bot.py +164 -0
- telebot_mtproto-1.0.0/telebot_mtproto.egg-info/PKG-INFO +104 -0
- telebot_mtproto-1.0.0/telebot_mtproto.egg-info/SOURCES.txt +10 -0
- telebot_mtproto-1.0.0/telebot_mtproto.egg-info/dependency_links.txt +1 -0
- telebot_mtproto-1.0.0/telebot_mtproto.egg-info/requires.txt +1 -0
- telebot_mtproto-1.0.0/telebot_mtproto.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Telebot MTProto Developer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: telebot-mtproto
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight wrapper that brings pyTelegramBotAPI (Telebot) syntax to the powerful MTProto protocol using Telethon under the hood
|
|
5
|
+
Author-email: Telebot MTProto Developer <developer@tenmiencuaban.com>
|
|
6
|
+
Keywords: telegram,bot,userbot,mtproto,telebot,pytelegrambotapi,telethon
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Topic :: Communications :: Chat
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: Telethon>=1.24.0
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Telebot MTProto for Python
|
|
18
|
+
|
|
19
|
+
A lightweight wrapper that brings the simple and familiar decorator-based syntax of `pyTelegramBotAPI` (Telebot) to the high-performance **MTProto** protocol (using Telethon under the hood).
|
|
20
|
+
|
|
21
|
+
## Why Telebot MTProto?
|
|
22
|
+
|
|
23
|
+
When building Telegram bots with `pyTelegramBotAPI` (`telebot`), you are limited by the HTTP-based Bot API:
|
|
24
|
+
- Cannot download files larger than **20MB**.
|
|
25
|
+
- Cannot upload files larger than **50MB**.
|
|
26
|
+
- HTTP overhead slows down responses.
|
|
27
|
+
|
|
28
|
+
**Telebot MTProto** solves this! By running directly over MTProto (TCP):
|
|
29
|
+
- **Send & Download files up to 2GB** (or 4GB with Telegram Premium).
|
|
30
|
+
- **Run as a Bot** (using bot token) or as a **Userbot** (using phone login session).
|
|
31
|
+
- Enjoy direct TCP speed with zero-change friendly Telebot syntax.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
Install using pip:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install telebot-mtproto
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
### 1. Run as a Bot Account (with Token)
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from telebot_mtproto import MTProtoTeleBot
|
|
47
|
+
|
|
48
|
+
# Get api_id and api_hash from https://my.telegram.org
|
|
49
|
+
bot = MTProtoTeleBot(
|
|
50
|
+
api_id=123456,
|
|
51
|
+
api_hash="your_api_hash",
|
|
52
|
+
bot_token="your_bot_token_from_botfather"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
@bot.message_handler(commands=['start', 'help'])
|
|
56
|
+
def send_welcome(message):
|
|
57
|
+
bot.reply_to(message, "Hello! I am running on MTProto protocol.")
|
|
58
|
+
|
|
59
|
+
@bot.message_handler(func=lambda message: True)
|
|
60
|
+
def echo_all(message):
|
|
61
|
+
bot.reply_to(message, f"You said: {message.text}")
|
|
62
|
+
|
|
63
|
+
# Start the bot
|
|
64
|
+
bot.run()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Run as a Userbot Account (with Phone Login)
|
|
68
|
+
|
|
69
|
+
If you don't provide a `bot_token`, it will act as a Userbot. During the first run, it will prompt you in the terminal to enter your phone number and the OTP code sent by Telegram.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from telebot_mtproto import MTProtoTeleBot
|
|
73
|
+
|
|
74
|
+
bot = MTProtoTeleBot(
|
|
75
|
+
api_id=123456,
|
|
76
|
+
api_hash="your_api_hash",
|
|
77
|
+
session_name="my_userbot_session"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
@bot.message_handler(commands=['ping'])
|
|
81
|
+
def ping(message):
|
|
82
|
+
bot.reply_to(message, "Pong from userbot!")
|
|
83
|
+
|
|
84
|
+
bot.run()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 3. Send and Download Large Files (> 20MB)
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
@bot.message_handler(commands=['download'])
|
|
91
|
+
def get_large_file(message):
|
|
92
|
+
if message.reply_to_message:
|
|
93
|
+
bot.reply_to(message, "Downloading large file... (up to 2GB supported)")
|
|
94
|
+
|
|
95
|
+
# Download file directly over MTProto TCP
|
|
96
|
+
dest = "./downloads/large_file.zip"
|
|
97
|
+
bot.download_file(message.reply_to_message, dest)
|
|
98
|
+
|
|
99
|
+
bot.reply_to(message, f"File saved to {dest}")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT License.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Telebot MTProto for Python
|
|
2
|
+
|
|
3
|
+
A lightweight wrapper that brings the simple and familiar decorator-based syntax of `pyTelegramBotAPI` (Telebot) to the high-performance **MTProto** protocol (using Telethon under the hood).
|
|
4
|
+
|
|
5
|
+
## Why Telebot MTProto?
|
|
6
|
+
|
|
7
|
+
When building Telegram bots with `pyTelegramBotAPI` (`telebot`), you are limited by the HTTP-based Bot API:
|
|
8
|
+
- Cannot download files larger than **20MB**.
|
|
9
|
+
- Cannot upload files larger than **50MB**.
|
|
10
|
+
- HTTP overhead slows down responses.
|
|
11
|
+
|
|
12
|
+
**Telebot MTProto** solves this! By running directly over MTProto (TCP):
|
|
13
|
+
- **Send & Download files up to 2GB** (or 4GB with Telegram Premium).
|
|
14
|
+
- **Run as a Bot** (using bot token) or as a **Userbot** (using phone login session).
|
|
15
|
+
- Enjoy direct TCP speed with zero-change friendly Telebot syntax.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Install using pip:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install telebot-mtproto
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### 1. Run as a Bot Account (with Token)
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from telebot_mtproto import MTProtoTeleBot
|
|
31
|
+
|
|
32
|
+
# Get api_id and api_hash from https://my.telegram.org
|
|
33
|
+
bot = MTProtoTeleBot(
|
|
34
|
+
api_id=123456,
|
|
35
|
+
api_hash="your_api_hash",
|
|
36
|
+
bot_token="your_bot_token_from_botfather"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
@bot.message_handler(commands=['start', 'help'])
|
|
40
|
+
def send_welcome(message):
|
|
41
|
+
bot.reply_to(message, "Hello! I am running on MTProto protocol.")
|
|
42
|
+
|
|
43
|
+
@bot.message_handler(func=lambda message: True)
|
|
44
|
+
def echo_all(message):
|
|
45
|
+
bot.reply_to(message, f"You said: {message.text}")
|
|
46
|
+
|
|
47
|
+
# Start the bot
|
|
48
|
+
bot.run()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 2. Run as a Userbot Account (with Phone Login)
|
|
52
|
+
|
|
53
|
+
If you don't provide a `bot_token`, it will act as a Userbot. During the first run, it will prompt you in the terminal to enter your phone number and the OTP code sent by Telegram.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from telebot_mtproto import MTProtoTeleBot
|
|
57
|
+
|
|
58
|
+
bot = MTProtoTeleBot(
|
|
59
|
+
api_id=123456,
|
|
60
|
+
api_hash="your_api_hash",
|
|
61
|
+
session_name="my_userbot_session"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
@bot.message_handler(commands=['ping'])
|
|
65
|
+
def ping(message):
|
|
66
|
+
bot.reply_to(message, "Pong from userbot!")
|
|
67
|
+
|
|
68
|
+
bot.run()
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3. Send and Download Large Files (> 20MB)
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
@bot.message_handler(commands=['download'])
|
|
75
|
+
def get_large_file(message):
|
|
76
|
+
if message.reply_to_message:
|
|
77
|
+
bot.reply_to(message, "Downloading large file... (up to 2GB supported)")
|
|
78
|
+
|
|
79
|
+
# Download file directly over MTProto TCP
|
|
80
|
+
dest = "./downloads/large_file.zip"
|
|
81
|
+
bot.download_file(message.reply_to_message, dest)
|
|
82
|
+
|
|
83
|
+
bot.reply_to(message, f"File saved to {dest}")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT License.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "telebot-mtproto"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Telebot MTProto Developer", email = "developer@tenmiencuaban.com" }
|
|
10
|
+
]
|
|
11
|
+
description = "A lightweight wrapper that brings pyTelegramBotAPI (Telebot) syntax to the powerful MTProto protocol using Telethon under the hood"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
keywords = ["telegram", "bot", "userbot", "mtproto", "telebot", "pytelegrambotapi", "telethon"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Topic :: Communications :: Chat",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"Telethon>=1.24.0"
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
include = ["telebot_mtproto*"]
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Core Telebot MTProto implementation (bot.py)
|
|
3
|
+
# Một wrapper dựa trên Telethon giúp lập trình viên viết code với cú pháp đơn giản của pyTelegramBotAPI
|
|
4
|
+
# nhưng chạy trực tiếp trên giao thức MTProto (TCP) tốc độ cao và không giới hạn kích thước file gửi/nhận (hỗ trợ tới 2GB).
|
|
5
|
+
|
|
6
|
+
import asyncio
|
|
7
|
+
from typing import List, Callable, Any, Optional, Union
|
|
8
|
+
from telethon import TelegramClient, events
|
|
9
|
+
from telethon.tl.types import Message as TelethonMessage, User as TelethonUser
|
|
10
|
+
|
|
11
|
+
class ChatAdapter:
|
|
12
|
+
"""Giả lập đối tượng Chat của pyTelegramBotAPI"""
|
|
13
|
+
def __init__(self, chat_id: int):
|
|
14
|
+
self.id = chat_id
|
|
15
|
+
|
|
16
|
+
class UserAdapter:
|
|
17
|
+
"""Giả lập đối tượng User của pyTelegramBotAPI"""
|
|
18
|
+
def __init__(self, user: TelethonUser):
|
|
19
|
+
self.id = getattr(user, 'id', None)
|
|
20
|
+
self.first_name = getattr(user, 'first_name', '')
|
|
21
|
+
self.last_name = getattr(user, 'last_name', '')
|
|
22
|
+
self.username = getattr(user, 'username', '')
|
|
23
|
+
|
|
24
|
+
class MessageAdapter:
|
|
25
|
+
"""Giả lập đối tượng Message của pyTelegramBotAPI từ đối tượng Event/Message của Telethon"""
|
|
26
|
+
def __init__(self, event_message: TelethonMessage, sender: Optional[TelethonUser] = None):
|
|
27
|
+
self.raw = event_message
|
|
28
|
+
self.message_id = event_message.id
|
|
29
|
+
self.text = event_message.message or ""
|
|
30
|
+
self.caption = event_message.message or ""
|
|
31
|
+
self.chat = ChatAdapter(event_message.chat_id)
|
|
32
|
+
self.from_user = UserAdapter(sender) if sender else None
|
|
33
|
+
|
|
34
|
+
# Xử lý tin nhắn reply
|
|
35
|
+
self.reply_to_message = None
|
|
36
|
+
if event_message.is_reply:
|
|
37
|
+
# Lưu ID của tin nhắn được reply
|
|
38
|
+
self.reply_to_message_id = event_message.reply_to.reply_to_msg_id
|
|
39
|
+
|
|
40
|
+
class MTProtoTeleBot:
|
|
41
|
+
"""Lớp điều khiển chính giả lập pyTelegramBotAPI chạy trên nền thức MTProto"""
|
|
42
|
+
|
|
43
|
+
def __init__(self, api_id: int, api_hash: str, bot_token: Optional[str] = None, session_name: str = "telebot_mtproto"):
|
|
44
|
+
"""
|
|
45
|
+
Khởi tạo MTProto Bot
|
|
46
|
+
:param api_id: Telegram API ID (lấy từ my.telegram.org)
|
|
47
|
+
:param api_hash: Telegram API HASH (lấy từ my.telegram.org)
|
|
48
|
+
:param bot_token: Bot token (nếu chạy dưới quyền Bot @BotFather). Để trống nếu chạy chế độ Userbot.
|
|
49
|
+
:param session_name: Tên tệp tin phiên làm việc session
|
|
50
|
+
"""
|
|
51
|
+
self.api_id = api_id
|
|
52
|
+
self.api_hash = api_hash
|
|
53
|
+
self.bot_token = bot_token
|
|
54
|
+
self.client = TelegramClient(session_name, api_id, api_hash)
|
|
55
|
+
self.handlers = []
|
|
56
|
+
|
|
57
|
+
def message_handler(self, commands: Optional[List[str]] = None, regexp: Optional[str] = None, func: Optional[Callable[[Any], bool]] = None):
|
|
58
|
+
"""
|
|
59
|
+
Decorator đăng ký hàm xử lý tin nhắn tương tự pyTelegramBotAPI
|
|
60
|
+
"""
|
|
61
|
+
def decorator(handler_func: Callable[[MessageAdapter], Any]):
|
|
62
|
+
self.handlers.append({
|
|
63
|
+
"func": handler_func,
|
|
64
|
+
"commands": [c.lower() for c in commands] if commands else None,
|
|
65
|
+
"regexp": regexp,
|
|
66
|
+
"filter_func": func
|
|
67
|
+
})
|
|
68
|
+
return handler_func
|
|
69
|
+
return decorator
|
|
70
|
+
|
|
71
|
+
async def _handle_update(self, event):
|
|
72
|
+
"""Hàm xử lý và lọc sự kiện tin nhắn nội bộ"""
|
|
73
|
+
msg = event.message
|
|
74
|
+
if not msg:
|
|
75
|
+
return
|
|
76
|
+
|
|
77
|
+
# Lấy thông tin người gửi
|
|
78
|
+
sender = await event.get_sender()
|
|
79
|
+
adapted_msg = MessageAdapter(msg, sender)
|
|
80
|
+
|
|
81
|
+
# Trích xuất command nếu có
|
|
82
|
+
text_lower = adapted_msg.text.strip().lower()
|
|
83
|
+
is_command = text_lower.startswith("/")
|
|
84
|
+
command_name = text_lower.split()[0][1:] if is_command else ""
|
|
85
|
+
|
|
86
|
+
for handler in self.handlers:
|
|
87
|
+
# Lọc theo commands
|
|
88
|
+
if handler["commands"] is not None:
|
|
89
|
+
if not is_command or command_name not in handler["commands"]:
|
|
90
|
+
continue
|
|
91
|
+
|
|
92
|
+
# Lọc theo regexp
|
|
93
|
+
if handler["regexp"] is not None:
|
|
94
|
+
import re
|
|
95
|
+
if not re.search(handler["regexp"], adapted_msg.text):
|
|
96
|
+
continue
|
|
97
|
+
|
|
98
|
+
# Lọc theo hàm filter_func tùy biến
|
|
99
|
+
if handler["filter_func"] is not None:
|
|
100
|
+
try:
|
|
101
|
+
if not handler["filter_func"](adapted_msg):
|
|
102
|
+
continue
|
|
103
|
+
except Exception:
|
|
104
|
+
continue
|
|
105
|
+
|
|
106
|
+
# Gọi handler (hỗ trợ cả hàm đồng bộ và không đồng bộ)
|
|
107
|
+
if asyncio.iscoroutinefunction(handler["func"]):
|
|
108
|
+
await handler["func"](adapted_msg)
|
|
109
|
+
else:
|
|
110
|
+
# Chạy hàm đồng bộ trong threadpool để tránh chặn vòng lặp sự kiện
|
|
111
|
+
loop = asyncio.get_running_loop()
|
|
112
|
+
await loop.run_in_executor(None, handler["func"], adapted_msg)
|
|
113
|
+
|
|
114
|
+
def start(self):
|
|
115
|
+
"""Khởi động client và đăng ký sự kiện"""
|
|
116
|
+
# Đăng ký sự kiện nhận tin nhắn mới trong Telethon
|
|
117
|
+
self.client.add_event_handler(self._handle_update, events.NewMessage(incoming=True))
|
|
118
|
+
|
|
119
|
+
if self.bot_token:
|
|
120
|
+
self.client.start(bot_token=self.bot_token)
|
|
121
|
+
else:
|
|
122
|
+
self.client.start()
|
|
123
|
+
|
|
124
|
+
def run(self):
|
|
125
|
+
"""Bắt đầu chạy bot (blocking)"""
|
|
126
|
+
self.start()
|
|
127
|
+
print("Bot is running over MTProto...")
|
|
128
|
+
self.client.run_until_disconnected()
|
|
129
|
+
|
|
130
|
+
def send_message(self, chat_id: Union[int, str], text: str, reply_to_message_id: Optional[int] = None) -> TelethonMessage:
|
|
131
|
+
"""Gửi tin nhắn văn bản"""
|
|
132
|
+
loop = asyncio.get_event_loop()
|
|
133
|
+
coro = self.client.send_message(chat_id, text, reply_to=reply_to_message_id)
|
|
134
|
+
if loop.is_running():
|
|
135
|
+
return asyncio.ensure_future(coro)
|
|
136
|
+
return loop.run_until_complete(coro)
|
|
137
|
+
|
|
138
|
+
def reply_to(self, message: MessageAdapter, text: str) -> TelethonMessage:
|
|
139
|
+
"""Trả lời trực tiếp một tin nhắn"""
|
|
140
|
+
return self.send_message(message.chat.id, text, reply_to_message_id=message.message_id)
|
|
141
|
+
|
|
142
|
+
def send_document(self, chat_id: Union[int, str], file_path: str, caption: Optional[str] = None) -> TelethonMessage:
|
|
143
|
+
"""Gửi tài liệu/tệp tin (Hỗ trợ file cực lớn lên tới 2GB)"""
|
|
144
|
+
loop = asyncio.get_event_loop()
|
|
145
|
+
coro = self.client.send_file(chat_id, file_path, caption=caption, force_document=True)
|
|
146
|
+
if loop.is_running():
|
|
147
|
+
return asyncio.ensure_future(coro)
|
|
148
|
+
return loop.run_until_complete(coro)
|
|
149
|
+
|
|
150
|
+
def send_photo(self, chat_id: Union[int, str], file_path: str, caption: Optional[str] = None) -> TelethonMessage:
|
|
151
|
+
"""Gửi ảnh"""
|
|
152
|
+
loop = asyncio.get_event_loop()
|
|
153
|
+
coro = self.client.send_file(chat_id, file_path, caption=caption)
|
|
154
|
+
if loop.is_running():
|
|
155
|
+
return asyncio.ensure_future(coro)
|
|
156
|
+
return loop.run_until_complete(coro)
|
|
157
|
+
|
|
158
|
+
def download_file(self, message: MessageAdapter, dest_path: str) -> str:
|
|
159
|
+
"""Tải tệp đính kèm trong tin nhắn về máy (Không giới hạn 20MB của HTTP Bot API)"""
|
|
160
|
+
loop = asyncio.get_event_loop()
|
|
161
|
+
coro = self.client.download_media(message.raw, file=dest_path)
|
|
162
|
+
if loop.is_running():
|
|
163
|
+
return asyncio.ensure_future(coro)
|
|
164
|
+
return loop.run_until_complete(coro)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: telebot-mtproto
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight wrapper that brings pyTelegramBotAPI (Telebot) syntax to the powerful MTProto protocol using Telethon under the hood
|
|
5
|
+
Author-email: Telebot MTProto Developer <developer@tenmiencuaban.com>
|
|
6
|
+
Keywords: telegram,bot,userbot,mtproto,telebot,pytelegrambotapi,telethon
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Topic :: Communications :: Chat
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: Telethon>=1.24.0
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Telebot MTProto for Python
|
|
18
|
+
|
|
19
|
+
A lightweight wrapper that brings the simple and familiar decorator-based syntax of `pyTelegramBotAPI` (Telebot) to the high-performance **MTProto** protocol (using Telethon under the hood).
|
|
20
|
+
|
|
21
|
+
## Why Telebot MTProto?
|
|
22
|
+
|
|
23
|
+
When building Telegram bots with `pyTelegramBotAPI` (`telebot`), you are limited by the HTTP-based Bot API:
|
|
24
|
+
- Cannot download files larger than **20MB**.
|
|
25
|
+
- Cannot upload files larger than **50MB**.
|
|
26
|
+
- HTTP overhead slows down responses.
|
|
27
|
+
|
|
28
|
+
**Telebot MTProto** solves this! By running directly over MTProto (TCP):
|
|
29
|
+
- **Send & Download files up to 2GB** (or 4GB with Telegram Premium).
|
|
30
|
+
- **Run as a Bot** (using bot token) or as a **Userbot** (using phone login session).
|
|
31
|
+
- Enjoy direct TCP speed with zero-change friendly Telebot syntax.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
Install using pip:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install telebot-mtproto
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
### 1. Run as a Bot Account (with Token)
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from telebot_mtproto import MTProtoTeleBot
|
|
47
|
+
|
|
48
|
+
# Get api_id and api_hash from https://my.telegram.org
|
|
49
|
+
bot = MTProtoTeleBot(
|
|
50
|
+
api_id=123456,
|
|
51
|
+
api_hash="your_api_hash",
|
|
52
|
+
bot_token="your_bot_token_from_botfather"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
@bot.message_handler(commands=['start', 'help'])
|
|
56
|
+
def send_welcome(message):
|
|
57
|
+
bot.reply_to(message, "Hello! I am running on MTProto protocol.")
|
|
58
|
+
|
|
59
|
+
@bot.message_handler(func=lambda message: True)
|
|
60
|
+
def echo_all(message):
|
|
61
|
+
bot.reply_to(message, f"You said: {message.text}")
|
|
62
|
+
|
|
63
|
+
# Start the bot
|
|
64
|
+
bot.run()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Run as a Userbot Account (with Phone Login)
|
|
68
|
+
|
|
69
|
+
If you don't provide a `bot_token`, it will act as a Userbot. During the first run, it will prompt you in the terminal to enter your phone number and the OTP code sent by Telegram.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from telebot_mtproto import MTProtoTeleBot
|
|
73
|
+
|
|
74
|
+
bot = MTProtoTeleBot(
|
|
75
|
+
api_id=123456,
|
|
76
|
+
api_hash="your_api_hash",
|
|
77
|
+
session_name="my_userbot_session"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
@bot.message_handler(commands=['ping'])
|
|
81
|
+
def ping(message):
|
|
82
|
+
bot.reply_to(message, "Pong from userbot!")
|
|
83
|
+
|
|
84
|
+
bot.run()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 3. Send and Download Large Files (> 20MB)
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
@bot.message_handler(commands=['download'])
|
|
91
|
+
def get_large_file(message):
|
|
92
|
+
if message.reply_to_message:
|
|
93
|
+
bot.reply_to(message, "Downloading large file... (up to 2GB supported)")
|
|
94
|
+
|
|
95
|
+
# Download file directly over MTProto TCP
|
|
96
|
+
dest = "./downloads/large_file.zip"
|
|
97
|
+
bot.download_file(message.reply_to_message, dest)
|
|
98
|
+
|
|
99
|
+
bot.reply_to(message, f"File saved to {dest}")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT License.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
telebot_mtproto/__init__.py
|
|
5
|
+
telebot_mtproto/bot.py
|
|
6
|
+
telebot_mtproto.egg-info/PKG-INFO
|
|
7
|
+
telebot_mtproto.egg-info/SOURCES.txt
|
|
8
|
+
telebot_mtproto.egg-info/dependency_links.txt
|
|
9
|
+
telebot_mtproto.egg-info/requires.txt
|
|
10
|
+
telebot_mtproto.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Telethon>=1.24.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
telebot_mtproto
|