@rowger_go/chatu 0.1.3

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.
Files changed (77) hide show
  1. package/.github/workflows/ci.yml +30 -0
  2. package/.github/workflows/publish.yml +55 -0
  3. package/INSTALL.md +285 -0
  4. package/INSTALL.zh.md +285 -0
  5. package/LICENSE +21 -0
  6. package/README.md +293 -0
  7. package/README.zh.md +293 -0
  8. package/dist/index.d.ts +96 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +1381 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/index.test.d.ts +5 -0
  13. package/dist/index.test.d.ts.map +1 -0
  14. package/dist/index.test.js +334 -0
  15. package/dist/index.test.js.map +1 -0
  16. package/dist/sdk/adapters/cache.d.ts +94 -0
  17. package/dist/sdk/adapters/cache.d.ts.map +1 -0
  18. package/dist/sdk/adapters/cache.js +158 -0
  19. package/dist/sdk/adapters/cache.js.map +1 -0
  20. package/dist/sdk/adapters/cache.test.d.ts +14 -0
  21. package/dist/sdk/adapters/cache.test.d.ts.map +1 -0
  22. package/dist/sdk/adapters/cache.test.js +178 -0
  23. package/dist/sdk/adapters/cache.test.js.map +1 -0
  24. package/dist/sdk/adapters/default.d.ts +24 -0
  25. package/dist/sdk/adapters/default.d.ts.map +1 -0
  26. package/dist/sdk/adapters/default.js +151 -0
  27. package/dist/sdk/adapters/default.js.map +1 -0
  28. package/dist/sdk/adapters/webhub.d.ts +336 -0
  29. package/dist/sdk/adapters/webhub.d.ts.map +1 -0
  30. package/dist/sdk/adapters/webhub.js +663 -0
  31. package/dist/sdk/adapters/webhub.js.map +1 -0
  32. package/dist/sdk/adapters/websocket.d.ts +133 -0
  33. package/dist/sdk/adapters/websocket.d.ts.map +1 -0
  34. package/dist/sdk/adapters/websocket.js +314 -0
  35. package/dist/sdk/adapters/websocket.js.map +1 -0
  36. package/dist/sdk/core/channel.d.ts +104 -0
  37. package/dist/sdk/core/channel.d.ts.map +1 -0
  38. package/dist/sdk/core/channel.js +158 -0
  39. package/dist/sdk/core/channel.js.map +1 -0
  40. package/dist/sdk/index.d.ts +27 -0
  41. package/dist/sdk/index.d.ts.map +1 -0
  42. package/dist/sdk/index.js +33 -0
  43. package/dist/sdk/index.js.map +1 -0
  44. package/dist/sdk/types/adapters.d.ts +128 -0
  45. package/dist/sdk/types/adapters.d.ts.map +1 -0
  46. package/dist/sdk/types/adapters.js +10 -0
  47. package/dist/sdk/types/adapters.js.map +1 -0
  48. package/dist/sdk/types/channel.d.ts +270 -0
  49. package/dist/sdk/types/channel.d.ts.map +1 -0
  50. package/dist/sdk/types/channel.js +36 -0
  51. package/dist/sdk/types/channel.js.map +1 -0
  52. package/docs/channel/01-overview.md +117 -0
  53. package/docs/channel/02-configuration.md +138 -0
  54. package/docs/channel/03-capabilities.md +86 -0
  55. package/docs/channel/04-api-reference.md +394 -0
  56. package/docs/channel/05-message-protocol.md +194 -0
  57. package/docs/channel/06-security.md +83 -0
  58. package/docs/channel/README.md +30 -0
  59. package/docs/sdk/README.md +13 -0
  60. package/docs/sdk/v2026.1.29-v2026.2.19.md +630 -0
  61. package/jest.config.js +19 -0
  62. package/openclaw.plugin.json +113 -0
  63. package/package.json +74 -0
  64. package/run-poll.mjs +209 -0
  65. package/scripts/reload-plugin.sh +78 -0
  66. package/src/index.test.ts +432 -0
  67. package/src/index.ts +1638 -0
  68. package/src/sdk/adapters/cache.test.ts +205 -0
  69. package/src/sdk/adapters/cache.ts +193 -0
  70. package/src/sdk/adapters/default.ts +196 -0
  71. package/src/sdk/adapters/webhub.ts +857 -0
  72. package/src/sdk/adapters/websocket.ts +378 -0
  73. package/src/sdk/core/channel.ts +230 -0
  74. package/src/sdk/index.ts +36 -0
  75. package/src/sdk/types/adapters.ts +169 -0
  76. package/src/sdk/types/channel.ts +346 -0
  77. package/tsconfig.json +31 -0
package/README.md ADDED
@@ -0,0 +1,293 @@
1
+ # OpenClaw Chatu Channel Plugin
2
+
3
+ [![CI](https://github.com/chatu-ai/openclaw-web-hub-channel/actions/workflows/ci.yml/badge.svg)](https://github.com/chatu-ai/openclaw-web-hub-channel/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@rowger_go/chatu)](https://www.npmjs.com/package/@rowger_go/chatu)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@rowger_go/chatu)](https://www.npmjs.com/package/@rowger_go/chatu)
6
+ [![License: MIT](https://img.shields.io/github/license/chatu-ai/openclaw-web-hub-channel)](./LICENSE)
7
+ [![Node.js](https://img.shields.io/node/v/@rowger_go/chatu?label=Node.js)](https://nodejs.org/)
8
+
9
+ **English | [中文](README.zh.md)**
10
+
11
+ Official OpenClaw channel plugin for connecting to any website via HTTP/WebSocket.
12
+
13
+ ## What is Chatu Channel?
14
+
15
+ Chatu is a flexible channel plugin that enables OpenClaw to communicate with any HTTP/WebSocket-based messaging service. It provides a universal interface for connecting OpenClaw to custom web applications.
16
+
17
+ ## Quick Start
18
+
19
+ ### 1. Install
20
+
21
+ ```bash
22
+ # From npm (recommended)
23
+ openclaw plugins install @rowger_go/chatu
24
+
25
+ # Or from source (for development)
26
+ git clone https://github.com/chatu-ai/webhub.git
27
+ cd webhub
28
+ npm install
29
+ npm run build
30
+ openclaw plugins install -l .
31
+ ```
32
+
33
+ ### 2. Configure
34
+
35
+ ```bash
36
+ # Enable and configure the channel
37
+ openclaw config set channels.chatu.enabled true
38
+ openclaw config set channels.chatu.apiUrl "https://your-api.example.com"
39
+ openclaw config set channels.chatu.channelId "wh_ch_xxxxxx"
40
+ openclaw config set channels.chatu.accessToken "your-access-token"
41
+
42
+ # Restart gateway to apply changes
43
+ openclaw gateway restart
44
+ ```
45
+
46
+ ### 3. Verify
47
+
48
+ ```bash
49
+ # Check plugin status
50
+ openclaw plugins list | grep chatu
51
+
52
+ # View logs
53
+ openclaw logs
54
+ ```
55
+
56
+ > 📖 For detailed setup instructions, see the [Setup & Configuration Guide](#setup--configuration-guide) below.
57
+
58
+ ## Features
59
+
60
+ - 🔌 Universal HTTP/WebSocket connectivity
61
+ - 🔐 Secure token-based authentication
62
+ - 📝 Support for text, images, and file attachments
63
+ - 👥 Direct messages and group chat support
64
+ - 🔄 Message editing and deletion
65
+ - 💬 Reply threading
66
+
67
+ ## Configuration Options
68
+
69
+ ### Basic Configuration
70
+
71
+ | Option | Type | Required | Default | Description |
72
+ |--------|------|----------|---------|-------------|
73
+ | `enabled` | boolean | No | `true` | Enable/disable the channel |
74
+ | `apiUrl` | string | Yes | — | WebHub service base URL |
75
+ | `channelId` | string | Yes | — | Channel ID from WebHub (e.g. `wh_ch_xxxxx`) |
76
+ | `secret` | string | Either/Or | — | Channel secret (`wh_secret_xxx`) for registration |
77
+ | `accessToken` | string | Either/Or | — | Access token (`wh_xxxxxxx`) |
78
+ | `timeout` | number | No | `30000` | Request timeout in milliseconds |
79
+
80
+ ### Example Configurations
81
+
82
+ **Single Account:**
83
+ ```json
84
+ {
85
+ "channels": {
86
+ "chatu": {
87
+ "enabled": true,
88
+ "apiUrl": "https://api.example.com",
89
+ "channelId": "wh_ch_xxxxxx",
90
+ "accessToken": "your-token",
91
+ "timeout": 30000
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ **Multiple Accounts:**
98
+ ```json
99
+ {
100
+ "channels": {
101
+ "chatu": {
102
+ "accounts": {
103
+ "work": {
104
+ "accountId": "work",
105
+ "apiUrl": "https://work-api.example.com",
106
+ "channelId": "wh_ch_aaaaaa",
107
+ "accessToken": "work-token"
108
+ },
109
+ "personal": {
110
+ "accountId": "personal",
111
+ "apiUrl": "https://personal-api.example.com",
112
+ "channelId": "wh_ch_bbbbbb",
113
+ "accessToken": "personal-token"
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ ```
120
+
121
+ > 💡 See the [Setup & Configuration Guide](#setup--configuration-guide) for step-by-step instructions.
122
+
123
+ ## Setup & Configuration Guide
124
+
125
+ ### Step 1: Verify Plugin Status
126
+
127
+ After installation, verify the plugin is loaded:
128
+
129
+ ```bash
130
+ # Check plugin status
131
+ openclaw plugins list | grep chatu
132
+ ```
133
+
134
+ Expected output:
135
+ ```
136
+ │ Chatu │ chatu │ loaded │ ~/path/to/webhub/dist/index.js │ 0.1.0 │
137
+ ```
138
+
139
+ ### Step 2: Configure the Channel
140
+
141
+ #### Option A: Using CLI Commands (Recommended)
142
+
143
+ ```bash
144
+ # Enable the channel
145
+ openclaw config set channels.chatu.enabled true
146
+
147
+ # Set API URL
148
+ openclaw config set channels.chatu.apiUrl "https://your-api.example.com"
149
+
150
+ # Set channel ID (from WebHub admin panel)
151
+ openclaw config set channels.chatu.channelId "wh_ch_xxxxxx"
152
+
153
+ # Set access token
154
+ openclaw config set channels.chatu.accessToken "your-access-token"
155
+
156
+ # Set timeout (optional, default: 30000ms)
157
+ openclaw config set channels.chatu.timeout 30000
158
+ ```
159
+
160
+ #### Option B: Edit Configuration File Directly
161
+
162
+ Edit `~/.openclaw/openclaw.json`:
163
+
164
+ ```json
165
+ {
166
+ "channels": {
167
+ "chatu": {
168
+ "enabled": true,
169
+ "apiUrl": "https://your-api.example.com",
170
+ "channelId": "wh_ch_xxxxxx",
171
+ "accessToken": "your-access-token",
172
+ "timeout": 30000
173
+ }
174
+ }
175
+ }
176
+ ```
177
+
178
+ #### Option C: Multi-Account Configuration
179
+
180
+ For managing multiple accounts:
181
+
182
+ ```bash
183
+ # Configure work account
184
+ openclaw config set channels.chatu.accounts.work.accountId "work"
185
+ openclaw config set channels.chatu.accounts.work.apiUrl "https://work-api.example.com"
186
+ openclaw config set channels.chatu.accounts.work.accessToken "work-token"
187
+
188
+ # Configure personal account
189
+ openclaw config set channels.chatu.accounts.personal.accountId "personal"
190
+ openclaw config set channels.chatu.accounts.personal.apiUrl "https://personal-api.example.com"
191
+ openclaw config set channels.chatu.accounts.personal.accessToken "personal-token"
192
+ ```
193
+
194
+ ### Step 3: Restart Gateway
195
+
196
+ After configuration, restart the OpenClaw gateway to load changes:
197
+
198
+ ```bash
199
+ # Restart gateway
200
+ openclaw gateway restart
201
+
202
+ # Or stop and start manually
203
+ openclaw gateway stop
204
+ openclaw gateway start
205
+ ```
206
+
207
+ ### Step 4: Verify Configuration
208
+
209
+ ```bash
210
+ # Check channel configuration
211
+ openclaw config get channels.chatu
212
+
213
+ # View gateway logs
214
+ openclaw logs | tail -50
215
+
216
+ # Check OpenClaw health status
217
+ openclaw health
218
+ ```
219
+
220
+ ### Development Mode Setup
221
+
222
+ For plugin development with hot-reload:
223
+
224
+ ```bash
225
+ # 1. Install in development mode
226
+ cd /path/to/webhub
227
+ openclaw plugins install -l .
228
+
229
+ # 2. Start TypeScript watch mode (auto-compile on changes)
230
+ npm run watch
231
+
232
+ # 3. Configure as normal (see Step 2)
233
+
234
+ # 4. After code changes, restart gateway
235
+ openclaw gateway restart
236
+
237
+ # 5. View logs for debugging
238
+ openclaw logs
239
+ ```
240
+
241
+ ### Troubleshooting
242
+
243
+ **Plugin not loading?**
244
+ - Check if plugin is installed: `openclaw plugins list`
245
+ - Verify dist/ directory exists and contains compiled files
246
+ - Restart gateway after installation: `openclaw gateway restart`
247
+
248
+ **Configuration not taking effect?**
249
+ - Verify configuration: `openclaw config get channels.chatu`
250
+ - Check for syntax errors in `~/.openclaw/openclaw.json`
251
+ - View gateway logs for errors: `openclaw logs`
252
+
253
+ **Connection issues?**
254
+ - Verify apiUrl is accessible
255
+ - Check accessToken is valid
256
+ - Increase timeout if needed: `openclaw config set channels.chatu.timeout 60000`
257
+ - Check logs for detailed error messages
258
+
259
+ ## Documentation
260
+
261
+ For detailed documentation, see:
262
+ - [Installation Guide](INSTALL.md) | [安装指南](INSTALL.zh.md)
263
+ - [Channel Documentation](docs/channel/README.md)
264
+ - [OpenClaw Plugin Docs](https://docs.openclaw.ai/plugin)
265
+
266
+ ## Publishing to npm
267
+
268
+ This project uses GitHub Actions to automatically publish to npm. See the [publish workflow](.github/workflows/publish.yml) for details.
269
+
270
+ **Setting up the required npm Secret:**
271
+
272
+ 1. Log in to [npmjs.com](https://www.npmjs.com) and generate an **Automation** Access Token
273
+ 2. Add a Secret in your GitHub repository: `Settings → Secrets and variables → Actions → New repository secret`
274
+ 3. Secret name: `NPM_TOKEN`, value: your npm Access Token
275
+
276
+ **How to publish a new version:**
277
+
278
+ ```bash
279
+ # Bump patch version and publish (e.g. 0.1.0 → 0.1.1)
280
+ npm run release:patch
281
+
282
+ # Bump minor version and publish (e.g. 0.1.0 → 0.2.0)
283
+ npm run release:minor
284
+
285
+ # Bump major version and publish (e.g. 0.1.0 → 1.0.0)
286
+ npm run release:major
287
+ ```
288
+
289
+ Running a `release:*` script bumps the version in `package.json`, creates a git tag, and pushes it — which triggers the GitHub Actions workflow to build and publish to npm.
290
+
291
+ ## License
292
+
293
+ MIT
package/README.zh.md ADDED
@@ -0,0 +1,293 @@
1
+ # OpenClaw Chatu 频道插件
2
+
3
+ [![CI](https://github.com/chatu-ai/openclaw-web-hub-channel/actions/workflows/ci.yml/badge.svg)](https://github.com/chatu-ai/openclaw-web-hub-channel/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@rowger_go/chatu)](https://www.npmjs.com/package/@rowger_go/chatu)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@rowger_go/chatu)](https://www.npmjs.com/package/@rowger_go/chatu)
6
+ [![License: MIT](https://img.shields.io/github/license/chatu-ai/openclaw-web-hub-channel)](./LICENSE)
7
+ [![Node.js](https://img.shields.io/node/v/@rowger_go/chatu?label=Node.js)](https://nodejs.org/)
8
+
9
+ **[English](README.md) | 中文**
10
+
11
+ 官方 OpenClaw 频道插件,通过 HTTP/WebSocket 连接任意网站。
12
+
13
+ ## 什么是 Chatu 频道?
14
+
15
+ Chatu 是一个灵活的频道插件,让 OpenClaw 能与任意基于 HTTP/WebSocket 的消息服务通信。它提供了一个通用接口,将 OpenClaw 接入自定义 Web 应用。
16
+
17
+ ## 快速开始
18
+
19
+ ### 1. 安装
20
+
21
+ ```bash
22
+ # 从 npm 安装(推荐)
23
+ openclaw plugins install @rowger_go/chatu
24
+
25
+ # 或从源码安装(用于开发)
26
+ git clone https://github.com/chatu-ai/webhub.git
27
+ cd webhub
28
+ npm install
29
+ npm run build
30
+ openclaw plugins install -l .
31
+ ```
32
+
33
+ ### 2. 配置
34
+
35
+ ```bash
36
+ # 启用并配置频道
37
+ openclaw config set channels.chatu.enabled true
38
+ openclaw config set channels.chatu.apiUrl "https://your-api.example.com"
39
+ openclaw config set channels.chatu.channelId "wh_ch_xxxxxx"
40
+ openclaw config set channels.chatu.accessToken "your-access-token"
41
+
42
+ # 重启网关以应用更改
43
+ openclaw gateway restart
44
+ ```
45
+
46
+ ### 3. 验证
47
+
48
+ ```bash
49
+ # 检查插件状态
50
+ openclaw plugins list | grep chatu
51
+
52
+ # 查看日志
53
+ openclaw logs
54
+ ```
55
+
56
+ > 📖 详细配置说明请参见下方的[配置指南](#配置指南)。
57
+
58
+ ## 功能特性
59
+
60
+ - 🔌 通用 HTTP/WebSocket 连接
61
+ - 🔐 基于 Token 的安全认证
62
+ - 📝 支持文本、图片和文件附件
63
+ - 👥 私信和群聊支持
64
+ - 🔄 消息编辑和撤回
65
+ - 💬 回复线程
66
+
67
+ ## 配置选项
68
+
69
+ ### 基础配置
70
+
71
+ | 选项 | 类型 | 必填 | 默认值 | 说明 |
72
+ |------|------|------|--------|------|
73
+ | `enabled` | boolean | 否 | `true` | 启用/禁用频道 |
74
+ | `apiUrl` | string | **是** | — | WebHub 服务基础 URL |
75
+ | `channelId` | string | **是** | — | WebHub 频道 ID(如 `wh_ch_xxxxx`) |
76
+ | `secret` | string | 二选一 | — | 频道密钥(`wh_secret_xxx`),用于注册 |
77
+ | `accessToken` | string | 二选一 | — | 访问凭证(`wh_xxxxxxx`) |
78
+ | `timeout` | number | 否 | `30000` | 请求超时时间(毫秒) |
79
+
80
+ ### 配置示例
81
+
82
+ **单账户:**
83
+ ```json
84
+ {
85
+ "channels": {
86
+ "chatu": {
87
+ "enabled": true,
88
+ "apiUrl": "https://api.example.com",
89
+ "channelId": "wh_ch_xxxxxx",
90
+ "accessToken": "your-token",
91
+ "timeout": 30000
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ **多账户:**
98
+ ```json
99
+ {
100
+ "channels": {
101
+ "chatu": {
102
+ "accounts": {
103
+ "work": {
104
+ "accountId": "work",
105
+ "apiUrl": "https://work-api.example.com",
106
+ "channelId": "wh_ch_aaaaaa",
107
+ "accessToken": "work-token"
108
+ },
109
+ "personal": {
110
+ "accountId": "personal",
111
+ "apiUrl": "https://personal-api.example.com",
112
+ "channelId": "wh_ch_bbbbbb",
113
+ "accessToken": "personal-token"
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ ```
120
+
121
+ > 💡 分步配置说明请参见[配置指南](#配置指南)。
122
+
123
+ ## 配置指南
124
+
125
+ ### 第一步:验证插件状态
126
+
127
+ 安装后,验证插件已加载:
128
+
129
+ ```bash
130
+ # 检查插件状态
131
+ openclaw plugins list | grep chatu
132
+ ```
133
+
134
+ 预期输出:
135
+ ```
136
+ │ Chatu │ chatu │ loaded │ ~/path/to/webhub/dist/index.js │ 0.1.0 │
137
+ ```
138
+
139
+ ### 第二步:配置频道
140
+
141
+ #### 方式 A:使用 CLI 命令(推荐)
142
+
143
+ ```bash
144
+ # 启用频道
145
+ openclaw config set channels.chatu.enabled true
146
+
147
+ # 设置 API URL
148
+ openclaw config set channels.chatu.apiUrl "https://your-api.example.com"
149
+
150
+ # 设置频道 ID(从 WebHub 管理界面获取)
151
+ openclaw config set channels.chatu.channelId "wh_ch_xxxxxx"
152
+
153
+ # 设置访问凭证
154
+ openclaw config set channels.chatu.accessToken "your-access-token"
155
+
156
+ # 设置超时时间(可选,默认 30000ms)
157
+ openclaw config set channels.chatu.timeout 30000
158
+ ```
159
+
160
+ #### 方式 B:直接编辑配置文件
161
+
162
+ 编辑 `~/.openclaw/openclaw.json`:
163
+
164
+ ```json
165
+ {
166
+ "channels": {
167
+ "chatu": {
168
+ "enabled": true,
169
+ "apiUrl": "https://your-api.example.com",
170
+ "channelId": "wh_ch_xxxxxx",
171
+ "accessToken": "your-access-token",
172
+ "timeout": 30000
173
+ }
174
+ }
175
+ }
176
+ ```
177
+
178
+ #### 方式 C:多账户配置
179
+
180
+ 管理多个账户:
181
+
182
+ ```bash
183
+ # 配置工作账户
184
+ openclaw config set channels.chatu.accounts.work.accountId "work"
185
+ openclaw config set channels.chatu.accounts.work.apiUrl "https://work-api.example.com"
186
+ openclaw config set channels.chatu.accounts.work.accessToken "work-token"
187
+
188
+ # 配置个人账户
189
+ openclaw config set channels.chatu.accounts.personal.accountId "personal"
190
+ openclaw config set channels.chatu.accounts.personal.apiUrl "https://personal-api.example.com"
191
+ openclaw config set channels.chatu.accounts.personal.accessToken "personal-token"
192
+ ```
193
+
194
+ ### 第三步:重启网关
195
+
196
+ 配置完成后,重启 OpenClaw 网关以加载更改:
197
+
198
+ ```bash
199
+ # 重启网关
200
+ openclaw gateway restart
201
+
202
+ # 或手动停止后启动
203
+ openclaw gateway stop
204
+ openclaw gateway start
205
+ ```
206
+
207
+ ### 第四步:验证配置
208
+
209
+ ```bash
210
+ # 检查频道配置
211
+ openclaw config get channels.chatu
212
+
213
+ # 查看网关日志
214
+ openclaw logs | tail -50
215
+
216
+ # 检查 OpenClaw 健康状态
217
+ openclaw health
218
+ ```
219
+
220
+ ### 开发模式
221
+
222
+ 使用热重载进行插件开发:
223
+
224
+ ```bash
225
+ # 1. 以开发模式安装
226
+ cd /path/to/webhub
227
+ openclaw plugins install -l .
228
+
229
+ # 2. 启动 TypeScript 监听模式(修改时自动编译)
230
+ npm run watch
231
+
232
+ # 3. 正常配置(参见第二步)
233
+
234
+ # 4. 代码更改后,重启网关
235
+ openclaw gateway restart
236
+
237
+ # 5. 查看调试日志
238
+ openclaw logs
239
+ ```
240
+
241
+ ### 故障排除
242
+
243
+ **插件未加载?**
244
+ - 检查插件是否已安装:`openclaw plugins list`
245
+ - 确认 dist/ 目录存在且包含编译后的文件
246
+ - 安装后重启网关:`openclaw gateway restart`
247
+
248
+ **配置未生效?**
249
+ - 验证配置:`openclaw config get channels.chatu`
250
+ - 检查 `~/.openclaw/openclaw.json` 中的语法错误
251
+ - 查看网关日志中的错误:`openclaw logs`
252
+
253
+ **连接问题?**
254
+ - 确认 apiUrl 可访问
255
+ - 检查 accessToken 是否有效
256
+ - 如需要可增加超时时间:`openclaw config set channels.chatu.timeout 60000`
257
+ - 查看日志获取详细错误信息
258
+
259
+ ## 文档
260
+
261
+ 详细文档请参见:
262
+ - [安装指南](INSTALL.zh.md)
263
+ - [频道文档](docs/channel/README.md)
264
+ - [OpenClaw 插件文档](https://docs.openclaw.ai/plugin)
265
+
266
+ ## 发布到 npm
267
+
268
+ 本项目使用 GitHub Actions 自动发布到 npm。详见[发布工作流说明](.github/workflows/publish.yml)。
269
+
270
+ **设置 npm 发布所需的 Secret:**
271
+
272
+ 1. 登录 [npmjs.com](https://www.npmjs.com) 并生成一个 **Automation** 类型的 Access Token
273
+ 2. 在 GitHub 仓库设置中添加 Secret:`Settings → Secrets and variables → Actions → New repository secret`
274
+ 3. Secret 名称:`NPM_TOKEN`,值填入你的 npm Access Token
275
+
276
+ **发布方式:**
277
+
278
+ ```bash
279
+ # 升级补丁版本并发布(如 0.1.0 → 0.1.1)
280
+ npm run release:patch
281
+
282
+ # 升级次要版本并发布(如 0.1.0 → 0.2.0)
283
+ npm run release:minor
284
+
285
+ # 升级主版本并发布(如 0.1.0 → 1.0.0)
286
+ npm run release:major
287
+ ```
288
+
289
+ 运行 `release:*` 脚本会自动更新 `package.json` 版本号、创建 git tag,并触发 GitHub Actions 发布到 npm。
290
+
291
+ ## 许可证
292
+
293
+ MIT
@@ -0,0 +1,96 @@
1
+ /**
2
+ * OpenClaw Chatu Channel Plugin
3
+ *
4
+ * This plugin enables OpenClaw to communicate with Chatu/WebHub services
5
+ * via HTTP polling (inbound) and HTTP POST (outbound).
6
+ *
7
+ * Architecture:
8
+ * User (browser) → WebHub service (POST /api/webhub/channels/:id/messages)
9
+ * Plugin polls → GET /api/channel/messages/pending
10
+ * Plugin dispatches → OpenClaw AI
11
+ * AI responds → plugin outbound.sendText → POST /api/channel/messages
12
+ * WebHub service → WebSocket push → browser
13
+ *
14
+ * @see https://docs.openclaw.ai/channels/chatu
15
+ * @see https://github.com/chatu-ai/openclaw-web-hub-channel
16
+ */
17
+ import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
18
+ /** Resolved per-account configuration for the Chatu channel. */
19
+ export interface ChatuAccount {
20
+ accountId: string;
21
+ apiUrl: string;
22
+ channelId: string;
23
+ secret?: string;
24
+ accessToken?: string;
25
+ timeout: number;
26
+ }
27
+ export default function (api: OpenClawPluginApi): {
28
+ name: string;
29
+ dispose(): Promise<void>;
30
+ };
31
+ /**
32
+ * Computes the exponential back-off wait time in milliseconds.
33
+ * On each consecutive error the wait doubles starting from baseMs, capped at maxMs.
34
+ *
35
+ * consecutiveErrors=0 → baseMs (normal interval, no back-off)
36
+ * consecutiveErrors=1 → baseMs * 2
37
+ * consecutiveErrors=2 → baseMs * 4
38
+ * ...
39
+ *
40
+ * @param consecutiveErrors - Number of consecutive failures so far
41
+ * @param baseMs - Base interval in milliseconds (default 2000)
42
+ * @param maxMs - Maximum allowed wait in milliseconds (default 30000)
43
+ */
44
+ export declare function computeBackoffMs(consecutiveErrors: number, baseMs?: number, maxMs?: number): number;
45
+ /**
46
+ * T011 US3 testable export: forward a cross-channel message to the ChatU WebHub
47
+ * service so it appears in the frontend with a source-channel badge.
48
+ *
49
+ * Can be called from OpenClaw pipeline hooks (e.g. `before_message_write`) or
50
+ * from standalone relay scripts that have access to the channel credentials.
51
+ *
52
+ * @param apiUrl - WebHub service base URL
53
+ * @param accessToken - Channel access token (`X-Access-Token`)
54
+ * @param sourceChannel - Originating channel id (e.g. 'tui', 'whatsapp')
55
+ * @param direction - 'inbound' (AI reply) or 'outbound' (user message)
56
+ * @param sender - Sender object: name required, id optional (cross-channel may lack user ID)
57
+ * @param content - Text content of the message
58
+ * @param sessionKey - Session key in the originating channel
59
+ * @param timeoutMs - Fetch timeout in milliseconds (default 30 s)
60
+ */
61
+ export declare function relayCrossChannelMessage(apiUrl: string, accessToken: string, sourceChannel: string, direction: 'inbound' | 'outbound', sender: {
62
+ id?: string;
63
+ name: string;
64
+ }, content: string, sessionKey: string, timeoutMs?: number): Promise<{
65
+ ok: boolean;
66
+ id?: string;
67
+ error?: string;
68
+ }>;
69
+ /**
70
+ * T042 testable export: relay a streaming AI chunk to the WebHub API.
71
+ *
72
+ * @param apiUrl - WebHub service base URL
73
+ * @param accessToken - Channel access token (Bearer)
74
+ * @param messageId - Unique ID for the streaming message
75
+ * @param seq - 0-based sequential chunk index
76
+ * @param delta - Text delta for this chunk
77
+ * @param timeoutMs - Fetch timeout in milliseconds
78
+ */
79
+ export declare function relayStreamChunk(apiUrl: string, accessToken: string, messageId: string, seq: number, delta: string, timeoutMs?: number): Promise<{
80
+ ok: boolean;
81
+ error?: string;
82
+ }>;
83
+ /**
84
+ * T042 testable export: signal streaming completion to the WebHub API.
85
+ *
86
+ * @param apiUrl - WebHub service base URL
87
+ * @param accessToken - Channel access token (Bearer)
88
+ * @param messageId - Unique ID for the streaming message
89
+ * @param totalSeq - Total number of chunks sent
90
+ * @param timeoutMs - Fetch timeout in milliseconds
91
+ */
92
+ export declare function relayStreamDone(apiUrl: string, accessToken: string, messageId: string, totalSeq: number, timeoutMs?: number): Promise<{
93
+ ok: boolean;
94
+ error?: string;
95
+ }>;
96
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EACV,iBAAiB,EAQlB,MAAM,qBAAqB,CAAC;AAS7B,gEAAgE;AAChE,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAmBD,MAAM,CAAC,OAAO,WAAW,GAAG,EAAE,iBAAiB;;;EA24C9C;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,iBAAiB,EAAE,MAAM,EACzB,MAAM,GAAE,MAAyB,EACjC,KAAK,GAAE,MAAuB,GAC7B,MAAM,CAER;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,SAAS,GAAG,UAAU,EACjC,MAAM,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACrC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,MAAe,GACzB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAwBvD;AAED;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAe,GACzB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAuB1C;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAAe,GACzB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAuB1C"}