This project exports Telegram chats using the tdl command line tool and presents them through a small Flask web interface. Messages are saved in SQLite databases, attachments can be downloaded automatically and the viewer fetches Open Graph data for link previews.
- Export history via
update_messages.pyandtdl chat export. - Optional attachment download with
tdl dl. - Parse and store messages in per chat SQLite databases.
- Basic authenticated web server to manage chats and browse them.
- Background workers periodically update chats based on saved settings.
- Searchable HTML viewer with inline media display and link previews.
update_messages.py– runtdlto export messages and files.main.py– coordinates export, parses JSON and saves messages to the database.server.py– Flask server providing the management interface and chat pages.db_utils.py– SQLite helper utilities.message_utils.py– message parsing helpers.og_utils.py– fetch Open Graph metadata for links.- Frontend assets:
chat.js,chat.css,index.html,template.html. - Example startup scripts:
run.sh/run.batandtelegrambot.service.
- Install Python 3 and the
tdltool. - Install dependencies:
pip install -r requirements.txt
- Log in with
tdl:tdl login -T qr
- Start the server:
The server listens on
BOT_PASSWORD=yourpassword python server.py
127.0.0.1:8000and uses basic authentication. Visithttp://localhost:8000/to add a chat and start its worker. Open/chat/<chat_id>to browse messages.
- Ensure you have permission to archive the desired Telegram chats.
本项目借助 tdl 工具导出 Telegram 聊天记录,将消息保存到 SQLite 数据库,并提供可搜索的网页界面。可以自动下载附件并抓取链接的 Open Graph 预览信息。
- 通过
update_messages.py调用tdl chat export导出聊天记录。 - 可选地使用
tdl dl下载聊天中的文件。 - 解析 JSON 数据并写入各聊天对应的 SQLite 数据库。
- Flask 服务器提供基本认证和管理界面,可启动后台线程定期更新聊天。
- 浏览聊天时支持搜索、无限滚动、媒体展示以及链接预览。
- 所有数据存放在
data/与downloads/目录下。
update_messages.py:封装tdl导出聊天和附件。main.py:协调导出、解析 JSON 并写入数据库。server.py:Flask 服务器,提供管理界面及聊天页面。db_utils.py:SQLite 操作辅助函数。message_utils.py:消息解析工具。og_utils.py:抓取链接的 Open Graph 数据。- 前端资源:
chat.js、chat.css、index.html、template.html。 - 启动脚本示例:
run.sh、run.bat、telegrambot.service。
- 安装 Python 3 与
tdl工具。 - 安装依赖:
pip install -r requirements.txt
- 使用
tdl登录:tdl login -T qr
- 启动服务器:
服务器默认在
BOT_PASSWORD=你的密码 python server.py
127.0.0.1:8000监听,并启用基本认证。访问http://localhost:8000/添加聊天后启动后台线程,再在/chat/<chat_id>查看聊天记录。
- 请确保有权限访问并归档相应的 Telegram 聊天。