聊天室支持自定义机器人。注册机器人后,可通过 WebSocket 连接登录机器人。
1. 在聊天室侧边栏注册机器人
2. 使用以下接口登录:
POST /bot/login
Content-Type: application/json
{
"name": "你的用户名",
"password": "你的密码",
"bot": "机器人名称"
}
3. 返回:
{
"msg": "登录成功",
"token": "bot-token-uuid"
}
使用返回的 token 连接:
ws://host:8765?token=bot-token-uuid
发送 JSON 格式消息:
{
"type": "message",
"message": "你好,我是机器人!"
}
实时接收 JSON 格式消息:
{
"name": "用户1",
"message": "你好",
"time": 1712345678.123,
"group": "user",
"file_list": null,
"message_id": 42
}
type: "message" - 发送/接收消息
type: "user_list" - 获取在线用户列表
type: "image_data" - 获取图片数据