Skip to content

Commit 74e5680

Browse files
authored
docs(docker): add docker.md (#227)
1 parent d7c730d commit 74e5680

5 files changed

Lines changed: 546 additions & 37 deletions

File tree

.goreleaser.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ dockers:
9696
- "ghcr.io/sjzar/chatlog:{{ .Tag }}-amd64"
9797
- "sjzar/chatlog:{{ .Tag }}-amd64"
9898
dockerfile: Dockerfile
99+
extra_files:
100+
- script/docker-entrypoint.sh
99101
use: buildx
100102
goos: linux
101103
goarch: amd64
@@ -114,6 +116,8 @@ dockers:
114116
- "ghcr.io/sjzar/chatlog:{{ .Tag }}-arm64"
115117
- "sjzar/chatlog:{{ .Tag }}-arm64"
116118
dockerfile: Dockerfile
119+
extra_files:
120+
- script/docker-entrypoint.sh
117121
use: buildx
118122
goos: linux
119123
goarch: arm64

Dockerfile

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,31 @@ LABEL maintainer="Sarv <https://github.com/sjzar>"
44

55
ARG DEBIAN_FRONTEND=noninteractive
66

7-
RUN apt-get update && \
8-
apt-get install -y --no-install-recommends ca-certificates tzdata curl && \
9-
rm -rf /var/lib/apt/lists/*
7+
ENV PUID=1000 PGID=1000
8+
ENV GOSU_VERSION=1.17
9+
RUN set -eux; \
10+
apt-get update; \
11+
apt-get install -y --no-install-recommends ca-certificates tzdata curl wget; \
12+
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)"; \
13+
chmod +x /usr/local/bin/gosu; \
14+
gosu --version; \
15+
groupadd -r -g ${PGID} chatlog; \
16+
useradd -r -u ${PUID} -g chatlog -m -d /home/chatlog chatlog; \
17+
mkdir -p /app/data /app/work; \
18+
apt-get purge -y --auto-remove wget; \
19+
rm -rf /var/lib/apt/lists/*
1020

11-
RUN groupadd -r -g 1001 chatlog && \
12-
useradd -r -u 1001 -g chatlog -m -d /home/chatlog chatlog && \
13-
mkdir -p /app/data /app/work && \
14-
chown -R chatlog:chatlog /app
21+
WORKDIR /app
1522

16-
USER chatlog
23+
COPY script/docker-entrypoint.sh /usr/local/bin/entrypoint.sh
1724

18-
WORKDIR /app
25+
COPY --from=mwader/static-ffmpeg:7.1.1 /ffmpeg /usr/local/bin/
1926

20-
COPY --from=mwader/static-ffmpeg:7.1.1 --chown=chatlog:chatlog /ffmpeg /usr/local/bin/
27+
COPY chatlog /usr/local/bin/chatlog
2128

22-
COPY --chown=chatlog:chatlog chatlog /usr/local/bin/chatlog
29+
RUN chmod +x /usr/local/bin/entrypoint.sh \
30+
/usr/local/bin/ffmpeg \
31+
/usr/local/bin/chatlog
2332

2433
EXPOSE 5030
2534

@@ -31,4 +40,6 @@ ENV CHATLOG_DATA_DIR=/app/data \
3140
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
3241
CMD curl -f http://localhost:5030/health || exit 1
3342

43+
ENTRYPOINT ["entrypoint.sh"]
44+
3445
CMD ["chatlog", "server"]

README.md

Lines changed: 143 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
<div align="center">
22

3-
# Chatlog
4-
5-
![chatlog](https://socialify.git.ci/sjzar/chatlog/image?font=Rokkitt&forks=1&issues=1&name=1&pattern=Diagonal+Stripes&stargazers=1&theme=Auto)
3+
![chatlog](https://github.com/user-attachments/assets/e085d3a2-e009-4463-b2fd-8bd7df2b50c3)
64

75
_聊天记录工具,帮助大家轻松使用自己的聊天数据_
86

7+
[![ImgMCP](https://cdn.imgmcp.com/imgmcp-logo-small.png)](https://imgmcp.com)
8+
99
[![Go Report Card](https://goreportcard.com/badge/github.com/sjzar/chatlog)](https://goreportcard.com/report/github.com/sjzar/chatlog)
1010
[![GoDoc](https://godoc.org/github.com/sjzar/chatlog?status.svg)](https://godoc.org/github.com/sjzar/chatlog)
1111
[![GitHub release](https://img.shields.io/github/release/sjzar/chatlog.svg)](https://github.com/sjzar/chatlog/releases)
1212
[![GitHub license](https://img.shields.io/github/license/sjzar/chatlog.svg)](https://github.com/sjzar/chatlog/blob/main/LICENSE)
1313

14-
</div>
1514

16-
![chatlog](https://github.com/user-attachments/assets/e085d3a2-e009-4463-b2fd-8bd7df2b50c3)
15+
</div>
1716

1817
## Feature
1918

20-
- 从本地数据库文件获取聊天数据
21-
- 支持 Windows / macOS 系统
22-
- 支持微信 3.x / 4.0 版本
23-
- 提供 Terminal UI 界面 & 命令行工具
24-
- 提供 HTTP API 服务,支持查询聊天记录、联系人、群聊、最近会话等信息
25-
- 支持 MCP SSE 协议,可与支持 MCP 的 AI 助手无缝集成
26-
- 支持多媒体消息,支持解密图片、语音
27-
- 支持自动解密数据,简化使用流程
19+
- 从本地数据库文件中获取聊天数据
20+
- 支持 Windows / macOS 系统,兼容微信 3.x / 4.x 版本
21+
- 支持获取数据与图片密钥 (Windows < 4.0.3.36 / macOS < 4.0.3.80)
22+
- 支持图片、语音等多媒体数据解密,支持 wxgf 格式解析
23+
- 支持自动解密数据库,并提供新消息 Webhook 回调
24+
- 提供 Terminal UI 界面,同时支持命令行工具和 Docker 镜像部署
25+
- 提供 HTTP API 服务,可轻松查询聊天记录、联系人、群聊、最近会话等信息
26+
- 支持 MCP Streamable HTTP 协议,可与 AI 助手无缝集成
2827
- 支持多账号管理,可在不同账号间切换
2928

30-
31-
## TODO
32-
33-
- 聊天数据全文索引
34-
- 聊天数据统计 & Dashboard
35-
3629
## Quick Start
3730

3831
### 基本步骤
@@ -43,13 +36,14 @@ _聊天记录工具,帮助大家轻松使用自己的聊天数据_
4336
4. **开启 HTTP 服务**:选择 `开启 HTTP 服务` 菜单项
4437
5. **访问数据**:通过 [HTTP API](#http-api)[MCP 集成](#mcp-集成) 访问聊天记录
4538

46-
> 💡 **提示**如果电脑端微信聊天记录不全,可以[从手机端迁移数据](#从手机迁移聊天记录)
39+
> 💡 **提示**: 如果电脑端微信聊天记录不全,可以[从手机端迁移数据](#从手机迁移聊天记录)
4740
4841
### 常见问题快速解决
4942

5043
- **macOS 用户**:获取密钥前需[临时关闭 SIP](#macos-版本说明)
5144
- **Windows 用户**:遇到界面显示问题请[使用 Windows Terminal](#windows-版本说明)
5245
- **集成 AI 助手**:查看 [MCP 集成指南](#mcp-集成)
46+
- **无法获取密钥**:查看 [FAQ](https://github.com/sjzar/chatlog/issues/197)
5347

5448
## 安装指南
5549

@@ -59,6 +53,8 @@ _聊天记录工具,帮助大家轻松使用自己的聊天数据_
5953
go install github.com/sjzar/chatlog@latest
6054
```
6155

56+
> 💡 **提示**: 部分功能有 cgo 依赖,编译前需确认本地有 C 编译环境。
57+
6258
### 下载预编译版本
6359

6460
访问 [Releases](https://github.com/sjzar/chatlog/releases) 页面下载适合您系统的预编译版本。
@@ -94,6 +90,49 @@ chatlog decrypt
9490
chatlog server
9591
```
9692

93+
### Docker 部署
94+
95+
由于 Docker 部署时,程序运行环境与宿主机隔离,所以不支持获取密钥等操作,需要提前获取密钥数据。
96+
97+
一般用于 NAS 等设备部署,详细指南可参考 [Docker 部署指南](docs/docker.md)
98+
99+
**0. 获取密钥信息**
100+
101+
```shell
102+
# 从本机运行 chatlog 获取密钥信息
103+
$ chatlog key
104+
Data Key: [c0163e***ac3dc6]
105+
Image Key: [38636***653361]
106+
```
107+
108+
**1. 拉取镜像**
109+
110+
chatlog 提供了两个镜像源:
111+
112+
**Docker Hub**:
113+
```shell
114+
docker pull sjzar/chatlog:latest
115+
```
116+
117+
**GitHub Container Registry (ghcr)**:
118+
```shell
119+
docker pull ghcr.io/sjzar/chatlog:latest
120+
```
121+
122+
> 💡 **镜像地址**:
123+
> - Docker Hub: https://hub.docker.com/r/sjzar/chatlog
124+
> - GitHub Container Registry: https://ghcr.io/sjzar/chatlog
125+
126+
**2. 运行容器**
127+
128+
```shell
129+
$ docker run -d \
130+
--name chatlog \
131+
-p 5030:5030 \
132+
-v /path/to/your/wechat/data:/app/data \
133+
sjzar/chatlog:latest
134+
```
135+
97136
### 从手机迁移聊天记录
98137

99138
如果电脑端微信聊天记录不全,可以从手机端迁移数据:
@@ -173,23 +212,101 @@ GET /api/v1/chatlog?time=2023-01-01&talker=wxid_xxx
173212
当请求语音内容时,将直接返回语音内容,并对原始 SILK 语音做了实时转码 MP3 处理。
174213
多媒体内容 URL 地址为基于`数据目录`的相对地址,请求多媒体内容将直接返回对应文件,并针对加密图片做了实时解密处理。
175214

215+
## Webhook
216+
217+
需开启自动解密功能,当收到特定新消息时,可以通过 HTTP POST 请求将消息推送到指定的 URL。
218+
219+
#### 0. 回调配置
220+
221+
使用 TUI 模式的话,在 `$HOME/.chatlog/chatlog.json` 配置文件中,新增 `webhook` 配置。
222+
(Windows 用户的配置文件在 `%USERPROFILE%/.chatlog/chatlog.json`)
223+
224+
```json
225+
{
226+
"history": [],
227+
"last_account": "wxuser_x",
228+
"webhook": {
229+
"host": "localhost:5030", # 消息中的图片、文件等 URL host
230+
"items": [
231+
{
232+
"url": "http://localhost:8080/webhook", # 必填,webhook 请求的URL,可配置为 n8n 等 webhook 入口
233+
"talker": "wxid_123", # 必填,需要监控的私聊、群聊名称
234+
"sender": "", # 选填,消息发送者
235+
"keyword": "" # 选填,关键词
236+
}
237+
]
238+
}
239+
}
240+
```
241+
242+
使用 server 模式的话,可以通过 `CHATLOG_WEBHOOK` 环境变量进行设置。
243+
244+
```shell
245+
# 方案 1
246+
CHATLOG_WEBHOOK='{"host":"localhost:5030","items":[{"url":"http://localhost:8080/proxy","talker":"wxid_123","sender":"","keyword":""}]}'
247+
248+
# 方案 2(任选一种)
249+
CHATLOG_WEBHOOK_HOST="localhost:5030"
250+
CHATLOG_WEBHOOK_ITEMS='[{"url":"http://localhost:8080/proxy","talker":"wxid_123","sender":"","keyword":""}]'
251+
```
252+
253+
#### 1. 测试效果
254+
255+
启动 chatlog 并开启自动解密功能,测试回调效果
256+
257+
```shell
258+
POST /webhook HTTP/1.1
259+
Host: localhost:8080
260+
Accept-Encoding: gzip
261+
Content-Length: 386
262+
Content-Type: application/json
263+
User-Agent: Go-http-client/1.1
264+
265+
Body:
266+
{
267+
"keyword": "",
268+
"lastTime": "2025-08-27 00:00:00",
269+
"length": 1,
270+
"messages": [
271+
{
272+
"seq": 1756225000000,
273+
"time": "2025-08-27T00:00:00+08:00",
274+
"talker": "wxid_123",
275+
"talkerName": "",
276+
"isChatRoom": false,
277+
"sender": "wxid_123",
278+
"senderName": "Name",
279+
"isSelf": false,
280+
"type": 1,
281+
"subType": 0,
282+
"content": "测试消息",
283+
"contents": {
284+
"host": "localhost:5030"
285+
}
286+
}
287+
],
288+
"sender": "",
289+
"talker": "wxid_123"
290+
}
291+
```
292+
176293
## MCP 集成
177294

178-
Chatlog 支持 MCP (Model Context Protocol) SSE 协议,可与支持 MCP 的 AI 助手无缝集成。
179-
启动 HTTP 服务后,通过 SSE Endpoint 访问服务:
295+
Chatlog 支持 MCP (Model Context Protocol) 协议,可与支持 MCP 的 AI 助手无缝集成。
296+
启动 HTTP 服务后,通过 Streamable HTTP Endpoint 访问服务:
180297

181298
```
182-
GET /sse
299+
GET /mcp
183300
```
184301

185302
### 快速集成
186303

187304
Chatlog 可以与多种支持 MCP 的 AI 助手集成,包括:
188305

189-
- **ChatWise**: 直接支持 SSE,在工具设置中添加 `http://127.0.0.1:5030/sse`
190-
- **Cherry Studio**: 直接支持 SSE,在 MCP 服务器设置中添加 `http://127.0.0.1:5030/sse`
306+
- **ChatWise**: 直接支持 Streamable HTTP,在工具设置中添加 `http://127.0.0.1:5030/mcp`
307+
- **Cherry Studio**: 直接支持 Streamable HTTP,在 MCP 服务器设置中添加 `http://127.0.0.1:5030/mcp`
191308

192-
对于不直接支持 SSE 的客户端,可以使用 [mcp-proxy](https://github.com/sparfenyuk/mcp-proxy) 工具转发请求:
309+
对于不直接支持 Streamable HTTP 的客户端,可以使用 [mcp-proxy](https://github.com/sparfenyuk/mcp-proxy) 工具转发请求:
193310

194311
- **Claude Desktop**: 通过 mcp-proxy 支持,需要配置 `claude_desktop_config.json`
195312
- **Monica Code**: 通过 mcp-proxy 支持,需要配置 VSCode 插件设置

0 commit comments

Comments
 (0)