Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/guides/solution/openclaw.assets/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/guides/solution/openclaw.assets/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/guides/solution/openclaw.assets/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions docs/guides/solution/openclaw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: '如何接入OpenClaw'
sidebar_position: 8

---

# 如何接入OpenClaw

本文面向使用 OpenIM 的用户,说明如何通过 OpenClaw Gateway 接入 OpenIM,并完成“发送第一条消息”的验证。

## 1. 前置条件

- 你已部署并启动 OpenClaw Gateway,并能在运行 Gateway 的机器上执行 `openclaw` 命令。
- 你已从管理员/运维/业务系统获取以下 OpenIM 连接信息:
- `userID`:OpenClaw 在 OpenIM 中使用的用户 ID
- `wsAddr`:OpenIM SDK WebSocket 地址(例如:`ws://127.0.0.1:10001`)
- `apiAddr`:OpenIM REST API 地址(例如:`http://127.0.0.1:10002`)
- `platformID`:平台 ID(需与签发该 Token 时使用的 platformID 一致)

## 2. 准备用户 Token

### 1.注册用户

登陆管理后台,默认地址为`http://server_ip:11002`,`server_ip`为`open-im-server`部署地址ip。

选择 用户管理->用户列表,点击右边**创建新用户**:
![image-20260310115043272](./openclaw.assets/1.png)

输入账号相关信息:

![image-20260311110212683](./openclaw.assets/2.png)





### 获取管理员token

参考 [获取管理员 Token](../../restapi/apis/authenticationManagement/getAdminToken) 文档获取管理员 token。

### 获取用户token

拿到管理员 token 后,参考 [获取用户 Token](../../restapi/apis/authenticationManagement/getUserToken) 文档为指定用户签发登录 token。userID填写刚刚注册的用户的userID,platformID建议填写12。

## 3. 安装 OpenIM Channel 插件

```bash
openclaw plugins install @openim/openclaw-channel
```

插件地址:https://www.npmjs.com/package/@openim/openclaw-channel

## 4. 启用插件并配置 OpenIM Channel

### 方式 A:交互式配置(推荐)

```bash
openclaw openim setup
```

按提示填入 `token`、`wsAddr`、`apiAddr` 等信息。

### 方式 B:直接编辑配置文件

编辑:`~/.openclaw/openclaw.json`

示例:

```json
{
"channels": {
"openim": {
"accounts": {
"default": {
"enabled": true,
"token": "your_token",
"wsAddr": "ws://127.0.0.1:10001",
"apiAddr": "http://127.0.0.1:10002"
}
}
}
}
}
```

## 5. 验证:发送第一条消息

使用 OpenIM 通过userID搜索对应的机器人账号,对机器人账号发送一条消息,验证是否能够自动回复。

若对方成功收到消息,则说明 OpenClaw 已完成 OpenIM 接入。

![image-20260311115813414](./openclaw.assets/3.png)

## 6. 常见问题

- **提示 OpenIM is not connected**:通常由 `token`、`wsAddr`、`apiAddr` 配置错误或网络不可达导致。请先核对配置,然后结合 OpenClaw Gateway 日志定位原因。
2 changes: 1 addition & 1 deletion docs/restapi/commonFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: 常用字段说明
| 字段名 | 类型 | 字符串长度限制 | 说明 | 取值说明 |
| -------------- | ------ | -------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| secret | string | 32 | 服务端秘钥 | 字符串 |
| platformID | int | | 用户登录时的终端类型 | 1:iOS, 2:Android, 3:Windows, 4:OSX, 5:Web, 6:MiniWeb, 7:Linux, 8:APad, 9:IPad, 10:Admin, 11:HarmonyOS|
| platformID | int | | 用户登录时的终端类型 | 1:iOS, 2:Android, 3:Windows, 4:OSX, 5:Web, 6:MiniWeb, 7:Linux, 8:APad, 9:IPad, 10:Admin, 11:HarmonyOS,12:Bot|
| userID | string | 64 | 用户ID,保证唯一,不能包含特殊字符 | 字符串 |
| nickname | string | 255 | 昵称 | 字符串 |
| faceURL | string | 255 | 头像URL | URL 链接 |
Expand Down
Loading