|
| 1 | +# Telegram Search 入门指南 |
| 2 | + |
| 3 | +欢迎使用 Telegram Search !这个工具可以帮助你更智能地搜索和检索 Telegram 聊天记录。本指南将帮助你快速上手并开始使用。 |
| 4 | + |
| 5 | +## 功能概述 |
| 6 | + |
| 7 | +Telegram Search提供以下核心功能: |
| 8 | + |
| 9 | +- **语义搜索**:不仅可以搜索关键词,还能理解消息的上下文和含义 |
| 10 | +- **向量匹配**:基于OpenAI的嵌入向量技术,实现相似度搜索 |
| 11 | +- **高效检索**:比Telegram原生搜索更精准、更智能的检索体验 |
| 12 | +- **多平台支持**:提供Web界面和桌面应用程序 |
| 13 | + |
| 14 | +## 系统要求 |
| 15 | + |
| 16 | +- **操作系统**:Windows、macOS 或 Linux |
| 17 | +- **Node.js**:20.0 或更高版本 |
| 18 | +- **Docker**:用于运行数据库(可选,也可使用本地数据库) |
| 19 | + |
| 20 | +## 快速入门流程 |
| 21 | + |
| 22 | +使用Telegram Search的基本流程如下: |
| 23 | + |
| 24 | +1. **安装与配置**:安装应用程序并配置必要的API |
| 25 | +2. **连接Telegram账号**:登录你的Telegram账号 |
| 26 | +3. **同步聊天记录**:选择需要搜索的聊天记录进行同步 |
| 27 | +4. **开始搜索**:使用语义搜索功能查找消息 |
| 28 | + |
| 29 | +## 下一步 |
| 30 | + |
| 31 | +- 查看[安装指南](#安装指南)了解详细的安装步骤 |
| 32 | +- 参考[配置指南](#配置指南)了解如何配置API密钥 |
| 33 | +- 阅读[使用指南](#使用指南)学习如何使用各项功能 |
| 34 | + |
| 35 | +如果你在使用过程中遇到任何问题,请查看[故障排除](#故障排除)章节。 |
| 36 | + |
| 37 | +## 安装指南 |
| 38 | + |
| 39 | +本文档提供了在不同操作系统上安装Telegram Search的详细步骤。 |
| 40 | + |
| 41 | +### 安装步骤 |
| 42 | + |
| 43 | +<details> |
| 44 | + <summary> |
| 45 | + 安装 Node.js 和 pnpm |
| 46 | + </summary> |
| 47 | + |
| 48 | +1. 安装 NodeJS |
| 49 | + |
| 50 | + #### Windows |
| 51 | + |
| 52 | + 访问 [Node.js官网](https://nodejs.org/) 下载并安装最新的LTS版本 |
| 53 | + |
| 54 | + #### macOS |
| 55 | + |
| 56 | + ```bash |
| 57 | + brew install node |
| 58 | + ``` |
| 59 | + |
| 60 | + ### Linux |
| 61 | + |
| 62 | + 使用 `nvm` 或者 `asdf` 来安装 |
| 63 | + |
| 64 | +2. 安装 pnpm |
| 65 | + |
| 66 | + ```bash |
| 67 | + corepack enable |
| 68 | + ``` |
| 69 | + |
| 70 | +3. 安装Docker |
| 71 | + [Docker Desktop](https://www.docker.com/products/docker-desktop) |
| 72 | + |
| 73 | +</details> |
| 74 | + |
| 75 | +1. **克隆仓库**: |
| 76 | + |
| 77 | + ```sh |
| 78 | + git clone https://github.com/GramSearch/telegram-search.git |
| 79 | + cd telegram-search |
| 80 | + ``` |
| 81 | + |
| 82 | +2. **安装依赖**: |
| 83 | + |
| 84 | + ```sh |
| 85 | + pnpm install |
| 86 | + ``` |
| 87 | + |
| 88 | +3. **配置环境**: |
| 89 | + |
| 90 | + ```sh |
| 91 | + copy config\config.example.yaml config\config.yaml |
| 92 | + ``` |
| 93 | + |
| 94 | + 然后使用文本编辑器编辑 `config\config.yaml` 文件 |
| 95 | + |
| 96 | +#### 启动应用 |
| 97 | + |
| 98 | +完成安装和配置后,按照以下步骤启动应用: |
| 99 | + |
| 100 | +1. **启动数据库**: |
| 101 | + |
| 102 | + ```bash |
| 103 | + docker compose up -d |
| 104 | + ``` |
| 105 | + |
| 106 | +2. **同步数据库表结构**: |
| 107 | + |
| 108 | + ```bash |
| 109 | + pnpm run db:migrate |
| 110 | + ``` |
| 111 | + |
| 112 | +3. **启动服务**: |
| 113 | + |
| 114 | + ```bash |
| 115 | + # 启动后端服务 |
| 116 | + pnpm run dev:server |
| 117 | + |
| 118 | + # 另一个终端窗口中启动前端界面 |
| 119 | + pnpm run dev:frontend |
| 120 | + ``` |
| 121 | + |
| 122 | +4. 打开浏览器访问 `http://localhost:3333` 即可使用应用程序 |
| 123 | + |
| 124 | +## 配置指南 |
| 125 | + |
| 126 | +### Telegram API配置 |
| 127 | + |
| 128 | +要使用Telegram Search,你需要获取Telegram API凭证: |
| 129 | + |
| 130 | +1. 访问 [https://my.telegram.org/apps](https://my.telegram.org/apps) |
| 131 | +2. 登录你的Telegram账号 |
| 132 | +3. 点击"API development tools" |
| 133 | +4. 填写应用信息(应用标题和简短名称可以自定义) |
| 134 | +5. 创建应用后,你将获得`api_id`和`api_hash` |
| 135 | + |
| 136 | +将获取的API ID和哈希填入配置文件: |
| 137 | + |
| 138 | +```yaml |
| 139 | +api: |
| 140 | + telegram: |
| 141 | + apiId: '你的API ID' |
| 142 | + apiHash: '你的API Hash' |
| 143 | +``` |
| 144 | +
|
| 145 | +### OpenAI API配置 |
| 146 | +
|
| 147 | +语义搜索功能需要使用OpenAI API: |
| 148 | +
|
| 149 | +1. 访问 [OpenAI平台](https://platform.openai.com/) |
| 150 | +2. 注册或登录账号 |
| 151 | +3. 进入API Keys页面: [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys) |
| 152 | +4. 创建新的API密钥 |
| 153 | +
|
| 154 | +将OpenAI API密钥填入配置文件: |
| 155 | +
|
| 156 | +```yaml |
| 157 | +api: |
| 158 | + embedding: |
| 159 | + provider: openai |
| 160 | + model: text-embedding-3-small |
| 161 | + apiKey: '你的OpenAI API密钥' |
| 162 | + dimension: 1536 |
| 163 | +``` |
| 164 | +
|
| 165 | +### 使用Ollama作为替代 |
| 166 | +
|
| 167 | +如果你不想使用OpenAI API,也可以使用Ollama作为替代: |
| 168 | +
|
| 169 | +1. 安装Ollama: [https://ollama.ai/download](https://ollama.ai/download) |
| 170 | +2. 启动Ollama服务 |
| 171 | +3. 配置Telegram Search使用Ollama: |
| 172 | +
|
| 173 | +```yaml |
| 174 | +api: |
| 175 | + embedding: |
| 176 | + provider: ollama |
| 177 | + model: '你选择的模型' # 例如 llama2 或 nomic-embed-text |
| 178 | + dimension: 1536 # 取决于你的模型的维度 |
| 179 | +``` |
| 180 | +
|
| 181 | +### 数据库配置 |
| 182 | +
|
| 183 | +Telegram Search支持PostgreSQL和PGLite作为数据库: |
| 184 | +
|
| 185 | +```yaml |
| 186 | +database: |
| 187 | + type: postgres |
| 188 | + # 使用URL |
| 189 | + url: postgres://username:password@localhost:5432/database_name |
| 190 | + |
| 191 | + # 或者使用分离字段配置 |
| 192 | + host: localhost |
| 193 | + port: 5433 |
| 194 | + user: postgres |
| 195 | + password: '123456' |
| 196 | + database: postgres |
| 197 | +``` |
| 198 | +
|
| 199 | +### 存储路径配置 |
| 200 | +
|
| 201 | +你可以自定义Telegram Search的存储路径: |
| 202 | +
|
| 203 | +```yaml |
| 204 | +path: |
| 205 | + storage: ~/.telegram-search # 默认路径 |
| 206 | +``` |
| 207 | +
|
| 208 | +### 消息导出设置 |
| 209 | +
|
| 210 | +调整消息导出的性能参数: |
| 211 | +
|
| 212 | +```yaml |
| 213 | +message: |
| 214 | + export: |
| 215 | + batchSize: 200 # 每次请求获取的消息数量 |
| 216 | + concurrent: 3 # 并发请求数 |
| 217 | + retryTimes: 3 # 重试次数 |
| 218 | +``` |
| 219 | +
|
| 220 | +### 配置文件示例 |
| 221 | +
|
| 222 | +完整的配置文件示例: |
| 223 | +
|
| 224 | +```yaml |
| 225 | +# 数据库设置 |
| 226 | +database: |
| 227 | + type: postgres |
| 228 | + host: localhost |
| 229 | + port: 5433 |
| 230 | + user: postgres |
| 231 | + password: '123456' |
| 232 | + database: postgres |
| 233 | + |
| 234 | +# 消息设置 |
| 235 | +message: |
| 236 | + export: |
| 237 | + batchSize: 200 |
| 238 | + concurrent: 3 |
| 239 | + retryTimes: 3 |
| 240 | + maxTakeoutRetries: 3 |
| 241 | + batch: |
| 242 | + size: 100 |
| 243 | + |
| 244 | +# 路径设置 |
| 245 | +path: |
| 246 | + storage: ~/.telegram-search |
| 247 | + |
| 248 | +# API设置 |
| 249 | +api: |
| 250 | + telegram: |
| 251 | + apiId: '你的API ID' |
| 252 | + apiHash: '你的API哈希' |
| 253 | + embedding: |
| 254 | + provider: openai |
| 255 | + model: text-embedding-3-small |
| 256 | + apiKey: '你的OpenAI API密钥' |
| 257 | + dimension: 1536 |
| 258 | +``` |
| 259 | +
|
| 260 | +## 使用指南 |
| 261 | +
|
| 262 | +### 首次登录 |
| 263 | +
|
| 264 | +1. 启动应用后,访问 `http://localhost:3333` |
| 265 | +2. 点击登录按钮,输入你的 Telegram 手机号码 |
| 266 | +3. 输入 Telegram 发送给你的验证码 |
| 267 | +4. 如果你的账号启用了两步验证,还需要输入密码 |
| 268 | + |
| 269 | +### 同步聊天记录 |
| 270 | + |
| 271 | +1. 登录成功后,在左侧边栏可以看到你的 Telegram 对话列表 |
| 272 | +2. 打开同步页面,选择你需要同步的会话 |
| 273 | +3. 等待同步完成,这可能需要一些时间,取决于聊天记录的数量 |
| 274 | + |
| 275 | +### 搜索聊天记录 |
| 276 | + |
| 277 | +1. 在侧边栏选择你想要搜索的会话 |
| 278 | +2. 进入之后,点击右上角的搜索按钮 |
| 279 | +3. 输入关键词即可搜索 |
| 280 | + |
| 281 | +## 故障排除 |
| 282 | + |
| 283 | +### 常见问题 |
| 284 | + |
| 285 | +#### 无法连接到 Telegram |
| 286 | + |
| 287 | +- 如果你的网络环境需要配置代理,去配置文件里面设置代理 |
| 288 | +- 检查 App ID 和 App Hash 是否正确 |
| 289 | + |
| 290 | +#### 数据库连接失败 |
| 291 | + |
| 292 | +- 确保Docker服务正在运行 |
| 293 | +- 检查数据库配置是否正确 |
| 294 | + |
| 295 | +#### 搜索结果太少 |
| 296 | + |
| 297 | +如果你没有同步聊天记录到本地,是无法建立索引的,这样也自然无法搜索到 |
| 298 | + |
| 299 | +你可以在 同步 页面里面,把你想搜索的对话的聊天记录拉下来,这样可以建立索引 |
| 300 | + |
| 301 | +之所以这么做,是因为 Telegram 官方客户端本身是在云端搜索的,所以要做额外的处理只能把聊天记录都拉下来 |
| 302 | + |
| 303 | +#### 应用崩溃或无响应 |
| 304 | + |
| 305 | +**解决方案**: |
| 306 | + |
| 307 | +- 检查控制台日志以获取错误信息 |
| 308 | +- 尝试重新启动应用 |
| 309 | +- 如果问题持续存在,可以尝试清除数据:删除 `~/.telegram-search` 目录 |
| 310 | + |
| 311 | +### 日志查看 |
| 312 | + |
| 313 | +如果你遇到问题,查看日志可能会有所帮助: |
| 314 | + |
| 315 | +- **后端日志**:在运行 `pnpm run dev:server` 的终端窗口中 |
| 316 | +- **前端日志**:在浏览器开发者工具的控制台中 |
| 317 | +- **数据库日志**:使用 `docker compose logs -f` 查看 |
| 318 | + |
| 319 | +## 开发者指南 |
| 320 | + |
| 321 | +### 项目结构 |
| 322 | + |
| 323 | +``` |
| 324 | +/telegram-search |
| 325 | +├── apps/ # 应用程序代码 |
| 326 | +│ ├── electron/ # 桌面应用程序 |
| 327 | +│ ├── frontend/ # 前端界面 |
| 328 | +│ └── server/ # 后端服务 |
| 329 | +├── assets/ # 静态资源 |
| 330 | +├── config/ # 配置文件 |
| 331 | +├── drizzle/ # 数据库迁移和管理 |
| 332 | +├── packages/ # 共享包和模块 |
| 333 | +├── scripts/ # 脚本工具 |
| 334 | +└── sql/ # SQL相关文件 |
| 335 | +``` |
| 336 | +
|
| 337 | +### 开发环境设置 |
| 338 | +
|
| 339 | +1. 按照安装步骤设置基本环境 |
| 340 | +2. 启用开发模式: |
| 341 | +
|
| 342 | +```bash |
| 343 | +# 启动后端服务(开发模式) |
| 344 | +LOG_LEVEL=debug pnpm run dev:server |
| 345 | +
|
| 346 | +# 启动前端界面(开发模式) |
| 347 | +pnpm run dev:frontend |
| 348 | +``` |
| 349 | + |
| 350 | +### 代码风格 |
| 351 | + |
| 352 | +项目使用ESLint和Prettier来保持代码风格一致。在提交代码前,请确保运行: |
| 353 | + |
| 354 | +```bash |
| 355 | +pnpm run lint |
| 356 | +``` |
| 357 | + |
| 358 | +## 结语 |
| 359 | + |
| 360 | +恭喜!你现在已经了解了如何安装、配置和使用Telegram Search。如果你有任何问题或建议,欢迎在 [Telegram Search GitHub](https://github.com/GramSearch/telegram-search) 上提交 Issue 或 Pull Request。 |
0 commit comments