@hanjianchun/turms 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Turms Channel for OpenClaw
2
+
3
+ Turms IM 即时通讯通道插件,用于 OpenClaw 平台。
4
+
5
+ ## 功能特性
6
+
7
+ - 支持 Turms Gateway TCP 连接(端口 11510)
8
+ - 支持用户认证登录
9
+ - 支持私聊消息发送和接收
10
+ - 支持群聊消息发送和接收
11
+ - 自动重连机制
12
+ - 心跳保活
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ # 安装最新版本
18
+ openclaw plugins install openclaw-channel-turms
19
+
20
+ # 安装指定版本
21
+ openclaw plugins install openclaw-channel-turms@0.1.2
22
+ ```
23
+
24
+ ### 本地开发安装
25
+
26
+ ```bash
27
+ cd turms-openclaw-channel
28
+ pnpm install
29
+ openclaw plugins install -l .
30
+ ```
31
+
32
+ ## 配置
33
+
34
+ 在 `~/.openclaw/openclaw.json` 中添加以下配置:
35
+
36
+ ```json5
37
+ {
38
+ "plugins": {
39
+ "entries": {
40
+ "turms": {
41
+ "enabled": true,
42
+ "config": {
43
+ "host": "playground.turms.im",
44
+ "port": 11510,
45
+ "userId": 1,
46
+ "password": "123"
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ > 注意:配置完成后需要重启 Gateway:`openclaw gateway --force` 或重启 OpenClaw 服务。
55
+
56
+ ### 配置项说明
57
+
58
+ | 配置项 | 类型 | 默认值 | 说明 |
59
+ |--------|------|--------|------|
60
+ | `name` | string | - | 通道显示名称 |
61
+ | `enabled` | boolean | true | 启用/禁用通道 |
62
+ | `host` | string | localhost | Turms Gateway 主机地址 |
63
+ | `port` | integer | 11510 | Turms Gateway TCP 端口 |
64
+ | `userId` | integer | - | 用户 ID(必填) |
65
+ | `password` | string | - | 用户密码(必填) |
66
+ | `deviceType` | integer | 1 | 设备类型:1=Android, 2=iOS, 3=PC, 4=Web |
67
+ | `connectTimeout` | integer | 30000 | 连接超时(毫秒) |
68
+ | `requestTimeout` | integer | 60000 | 请求超时(毫秒) |
69
+ | `heartbeatInterval` | integer | 30000 | 心跳间隔(毫秒) |
70
+ | `autoReconnect` | boolean | true | 自动重连 |
71
+ | `maxReconnectAttempts` | integer | 10 | 最大重连次数 |
72
+ | `reconnectDelay` | integer | 5000 | 重连延迟(毫秒) |
73
+ | `debug` | boolean | false | 调试日志 |
74
+
75
+ ## 使用示例
76
+
77
+ ### 发送消息
78
+
79
+ ```bash
80
+ # 发送私聊消息
81
+ openclaw send --channel turms --to 123 "Hello, Turms!"
82
+
83
+ # 发送群聊消息
84
+ openclaw send --channel turms --to 456 --group "Hello, group!"
85
+ ```
86
+
87
+ ### 目标 ID 格式
88
+
89
+ - 私聊:`--to 123` 或 `--to turms:123`
90
+ - 群聊:`--to 456 --group`
91
+
92
+ ## 开发
93
+
94
+ ```bash
95
+ # 安装依赖
96
+ pnpm install
97
+
98
+ # 类型检查
99
+ pnpm type-check
100
+
101
+ # 代码格式化
102
+ pnpm format
103
+
104
+ # Lint 检查
105
+ pnpm lint
106
+ ```
107
+
108
+ ## 架构说明
109
+
110
+ ### 通信协议
111
+
112
+ Turms 使用 WebSocket 协议与 Gateway 通信:
113
+
114
+ 1. **连接建立**: WebSocket 连接到 `ws://host:port`
115
+ 2. **用户认证**: 发送 `createSessionRequest` 进行登录
116
+ 3. **消息发送**: 使用 Protobuf 编码的 `TurmsRequest`
117
+ 4. **消息接收**: 接收 Protobuf 编码的 `TurmsNotification`
118
+
119
+ ### 消息格式
120
+
121
+ 请求和响应使用以下格式:
122
+
123
+ - **WebSocket**: 正文(Protobuf 编码的 `TurmsRequest`/`TurmsNotification`)
124
+ - **纯 TCP**: varint 编码的正文长度 + 正文
125
+
126
+ ### 模块结构
127
+
128
+ ```
129
+ turms-openclaw-channel/
130
+ ├── index.ts # 插件入口
131
+ ├── src/
132
+ │ ├── types.ts # 类型定义
133
+ │ ├── config.ts # 配置解析
134
+ │ ├── config-schema.ts # Zod 配置 Schema
135
+ │ ├── turms-client.ts # Turms TCP 客户端
136
+ │ ├── connection-manager.ts # 连接管理器
137
+ │ ├── gateway/
138
+ │ │ └── channel-gateway.ts # Gateway 实现
139
+ │ ├── messaging/
140
+ │ │ ├── send-service.ts # 消息发送服务
141
+ │ │ ├── inbound-handler.ts # 入站消息处理
142
+ │ │ └── channel-outbound.ts # Outbound 适配器
143
+ │ └── platform/
144
+ │ └── channel-status.ts # 状态检查
145
+ ```
146
+
147
+ ## 故障排查
148
+
149
+ ### 连接失败
150
+
151
+ 1. 检查 `host` 和 `port` 配置是否正确
152
+ 2. 确认网络可达性:`telnet host port`
153
+ 3. 检查用户凭证是否正确
154
+
155
+ ### 认证失败
156
+
157
+ 1. 确认 `userId` 和 `password` 正确
158
+ 2. 检查服务端是否启用了认证
159
+ 3. 查看调试日志:设置 `debug: true`
160
+
161
+ ### 消息发送失败
162
+
163
+ 1. 检查目标用户 ID 是否存在
164
+ 2. 确认是否有发送权限
165
+ 3. 查看服务端日志
166
+
167
+ ## 许可
168
+
169
+ Apache License 2.0
170
+
171
+ ## 相关链接
172
+
173
+ - [Turms GitHub](https://github.com/turms-im/turms)
174
+ - [Turms 文档](https://turms.im/docs)
175
+ - [OpenClaw 文档](https://openclaw.ai)