← Back to Plugins
Channels

Pinsonbot Connector

pinsonchen By pinsonchen 👁 21 views ▲ 0 votes

PinsonBots Channel Plugin for OpenClaw - Connect to PinsonBots WebSocket and use Gateway AI

GitHub

Install

npm install
npm

README

# PinsonBot Connector Plugin

[![GitHub stars](https://img.shields.io/github/stars/pinsonchen/pinsonbot-connector?style=social)](https://github.com/pinsonchen/pinsonbot-connector)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![OpenClaw Plugin](https://img.shields.io/badge/OpenClaw-Plugin-blue)](https://openclaw.ai)

PinsonBots Channel Plugin for OpenClaw - 连接 PinsonBots WebSocket 并使用 OpenClaw Gateway 的 AI 能力。

## 特性

- ✅ **真实 AI 对话** - 使用 OpenClaw Gateway 的 AI 能力
- ✅ **会话持久化** - 同一用户的多轮对话共享上下文
- ✅ **超时自动新会话** - 默认 30 分钟无活动自动开启新对话
- ✅ **手动新会话** - 发送 `/new` 或 `新会话` 清空对话历史
- ✅ **自动重连** - WebSocket 断开自动重连
- ✅ **Typing 指示** - 发送正在输入状态

## 架构

```
OpenClaw Gateway (18789)
  └─ PinsonBot Plugin
      ├─ PinsonBots WebSocket 客户端
      ├─ 消息处理器
      └─ Session 管理
           ↕
      PinsonBots (8002)
```

## 安装

### 1. 编译 TypeScript

```bash
cd /usr/local/projects/pinsonbot-connector/plugin
npm install
npm run build
```

### 2. 安装插件

```bash
# 本地安装
openclaw plugins install -l /usr/local/projects/pinsonbot-connector/plugin

# 或通过 npm (发布后)
openclaw plugins install @pinsonbot/connector
```

### 3. 配置

在 `~/.openclaw/openclaw.json` 中添加:

```json5
{
  "channels": {
    "pinsonbot-connector": {
      "enabled": true,
      "lobsterId": "4",
      "appkey": "aXF6JfFJ3HdViCLB0muxv8iRvaVWCqS0B707zQ-fWhA",
      "wsUrl": "ws://127.0.0.1:8002",  // 可选,默认 ws://127.0.0.1:8002
      "sessionTimeout": 1800000  // 可选,默认 30 分钟 (毫秒)
    }
  }
}
```

### 4. 重启 Gateway

```bash
openclaw gateway restart
```

验证:

```bash
openclaw plugins list  # 确认 pinsonbot-connector 已加载
```

## 配置参考

| 配置项 | 必填 | 默认值 | 说明 |
|--------|------|--------|------|
| `lobsterId` | ✅ | - | PinsonBots 龙虾 ID |
| `appkey` | ✅ | - | PinsonBots AppKey |
| `wsUrl` | ❌ | `ws://127.0.0.1:8002` | PinsonBots WebSocket URL |
| `sessionTimeout` | ❌ | `1800000` | 会话超时时间 (毫秒) |

## 会话命令

用户可以发送以下命令开启新会话(清空对话历史):

- `/new`、`/reset`、`/clear`
- `新会话`、`重新开始`、`清空对话`

## 项目结构

```
plugin/
├── package.json              # npm 依赖
├── openclaw.plugin.json      # 插件清单
├── tsconfig.json             # TypeScript 配置
├── plugin.ts                 # 插件入口
└── README.md                 # 本文档
```

## 开发

### 本地开发模式

```bash
# 1. 克隆项目
git clone <repo-url>
cd pinsonbot-connector/plugin

# 2. 安装依赖
npm install

# 3. 编译
npm run build

# 4. 本地安装
openclaw plugins install -l .

# 5. 修改代码后重新编译和安装
npm run build
openclaw plugins install -l .
```

### 调试

查看 Gateway 日志:

```bash
openclaw logs --follow | grep PinsonBot
```

## 故障排查

### Q: 插件加载失败

检查 TypeScript 编译:

```bash
npm run build
```

确认编译后的 `plugin.js` 文件存在。

### Q: WebSocket 连接失败

1. 确认 PinsonBots 后端运行中:
   ```bash
   curl http://127.0.0.1:8002/health
   ```

2. 确认 lobsterId 和 appkey 正确

3. 检查防火墙设置

### Q: Gateway API 调用失败

1. 确认 Gateway 运行中:
   ```bash
   curl http://127.0.0.1:18789/health
   ```

2. 确认 Gateway 启用了 chatCompletions 端点:
   ```json5
   {
     "gateway": {
       "http": {
         "endpoints": {
           "chatCompletions": {
             "enabled": true
           }
         }
       }
     }
   }
   ```

### Q: 会话不持久

检查 `sessionTimeout` 配置,确保不是太短(默认 30 分钟)。

## 依赖

| 包 | 用途 |
|----|------|
| `ws` | WebSocket 客户端 |
| `axios` | HTTP 客户端 |

## License

MIT
channels

Comments

Sign in to leave a comment

Loading comments...