npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@chihqiang/ccsim-ui

v0.0.6

Published

基于 TypeScript 开发,支持访客/客服双角色即时通信,内置完整开箱即用聊天UI组件。

Readme

ccsim-ui

基于 TypeScript 开发,支持访客/客服双角色即时通信, 内置完整开箱即用聊天 UI 组件(基于 Vue 3 + Vant)。

服务端

本 SDK 需配合后端服务 ccsim-svr 使用。

ccsim-svr 是基于 Go 语言开发的即时通信服务端,提供 WebSocket 长连接管理、会话分配、消息路由、离线推送等能力,支持单机与 Redis 集群部署。

git clone https://github.com/chihqiang/ccsim-svr.git
cd ccsim-svr
go run .

启动后默认监听 0.0.0.0:8080,WebSocket 端点为 /ws

安装

npm install @chihqiang/ccsim-ui

本地开发

npm install
npm run dev

启动后浏览器自动打开 http://localhost:3000/index.html,可访问访客端(visitor-npm.html)与客服端(agent-npm.html)等示例页面。

需先启动后端服务 ccsim-svr,或设置 wsHost 指向已部署的 WebSocket 服务。

CDN 加载

无需 npm,直接通过 CDN 使用:

HTML script(UMD)

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@chihqiang/ccsim-ui@latest/dist/ccsim-ui.css" />
<script src="https://cdn.jsdelivr.net/npm/@chihqiang/ccsim-ui@latest/dist/ccsim-ui.umd.js"></script>
<script>
  const sdk = new CcsimUI.VisitorSDK({
    tenant_no: 'your_tenant',
    wsHost: 'wss://your-server.com/ws',
    nickname: '访客用户',
    platform: 'web',
  })
</script>

ES Module(import map)

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@chihqiang/ccsim-ui@latest/dist/ccsim-ui.css" />
<script type="importmap">
{
  "imports": {
    "@chihqiang/ccsim-ui": "https://cdn.jsdelivr.net/npm/@chihqiang/ccsim-ui@latest/dist/ccsim-ui.es.js"
  }
}
</script>
<script type="module">
  import { VisitorSDK } from '@chihqiang/ccsim-ui'
</script>

快速开始

访客端

import { VisitorSDK } from '@chihqiang/ccsim-ui'
import '@chihqiang/ccsim-ui/style'

const sdk = new VisitorSDK({
  tenant_no: 'your_tenant',
  wsHost: 'wss://your-server.com/ws',
  nickname: '访客用户',
  phone: '13800138000',
  platform: 'web',
})

sdk.on('allSet', () => {
  console.log('连接成功,visitor_id:', sdk.visitorId)
})

sdk.on('startSession', (sessionId) => {
  console.log('会话创建:', sessionId)
})

客服端

import { AgentSDK } from '@chihqiang/ccsim-ui'
import '@chihqiang/ccsim-ui/style'

const sdk = new AgentSDK({
  tenant_no: 'your_tenant',
  wsHost: 'wss://your-server.com/ws',
  account: 'agent_account',
  password: 'agent_password',
  autoOnlineWhenOpen: true,
})

sdk.on('allSet', () => {
  console.log('登录成功,agent_id:', sdk.agentId)
})

sdk.on('newSession', (sessionId) => {
  console.log('新会话:', sessionId)
  sdk.acceptSession(sessionId)
})

API 参考

VisitorSDK

初始化选项

new VisitorSDK(options: VisitorInitOptions)

| 参数 | 类型 | 必填 | 说明 | |------|------|------|------| | tenant_no | string | 是 | 租户标识 | | wsHost | string \| (() => string) | 否 | WebSocket 地址或工厂函数 | | logLevel | 'debug' \| 'info' \| 'warn' \| 'error' \| 'silent' | 否 | 日志级别 | | debug | boolean | 否 | 等同于 logLevel: 'debug' | | locale | 'zh-CN' \| 'en-US' | 否 | UI 语言,默认 zh-CN | | visitor_uuid | string | 否 | 访客持久化标识 | | nickname | string | 否 | 显示名称 | | phone | string | 否 | 手机号 | | platform | string | 是 | 平台标识 | | metadata | Record<string, string> | 否 | 自定义元数据 |

属性

| 属性 | 类型 | 说明 | |------|------|------| | visitorId | number \| null | 服务端分配的访客 ID | | sessionId | number \| null | 当前会话 ID | | messages | ChatMessageItem[] | 当前会话消息列表 |

方法

| 方法 | 签名 | 说明 | |------|------|------| | sendChat | (content: string, msgType?: MsgType) => void | 发送消息,MsgType = 'text' \| 'image' \| 'video' \| 'audio' \| 'file' | | requestSessionHistory | (sessionId, beforeSeq?, limit?) => void | 请求历史消息 | | closeSession | (sessionId) => void | 关闭会话 | | rateSession | (sessionId, rating) => void | 满意度评价 | | sendTyping | (sessionId) => void | 发送正在输入状态 | | sendMessageRead | (sessionId, msgId, seqNum) => void | 标记消息已读 | | updateVisitorInfo | (info) => void | 更新访客信息 | | showPanel | () => void | 显示聊天面板 | | hidePanel | () => void | 隐藏聊天面板 | | registerToolbar | (item: ToolbarItem) => void | 注册工具栏按钮 | | unregisterToolbar | (key: string) => void | 注销工具栏按钮 | | registerPanelSection | (section: PanelSection) => void | 注册面板区块 | | unregisterPanelSection | (key: string) => void | 注销面板区块 | | on | (event, cb) => this | 监听事件 | | off | (event, cb) => this | 取消监听 | | restart | () => Promise<void> | 销毁并重新连接(清空会话) | | destroy | () => Promise<void> | 断开连接并清理 |

事件

| 事件 | 回调参数 | 说明 | |------|----------|------| | allSet | () | SDK 初始化完成 | | disconnected | (code, reason) | 连接断开 | | reconnecting | (attempt, maxAttempts) | 正在重连 | | reconnected | () | 重连成功 | | error | (error) | 错误 | | messageError | (error) | 发送失败 | | startSession | (sessionId) | 会话创建 | | endSession | (sessionId) | 会话关闭 | | sessionAssigned | (sessionId) | 会话分配给客服 | | satisfactionRated | (sessionId, status) | 评价已提交 | | typingPush | (sessionId, senderRole, senderId) | 对方正在输入 | | messageReadPush | (sessionId, readerRole, readerId, msgId, seqNum) | 消息已读回执 | | visitorInfoUpdated | (visitorId, nickname?, phone?, avatar?) | 访客信息已更新 | | agentStatus | (onlineCount, hasOnlineAgent) | 在线客服数量变化 |


AgentSDK

初始化选项

new AgentSDK(options: AgentInitOptions)

| 参数 | 类型 | 必填 | 说明 | |------|------|------|------| | tenant_no | string | 是 | 租户标识 | | wsHost | string \| (() => string) | 否 | WebSocket 地址或工厂函数 | | logLevel | 'debug' \| 'info' \| 'warn' \| 'error' \| 'silent' | 否 | 日志级别 | | debug | boolean | 否 | 等同于 logLevel: 'debug' | | locale | 'zh-CN' \| 'en-US' | 否 | UI 语言 | | account | string | 是 | 客服账号 | | password | string | 是 | 客服密码 | | autoOnlineWhenOpen | boolean | 否 | 页面打开后自动上线 | | activeTimeout | number | 否 | 活跃超时(分钟),0 不检测,默认 15 |

属性

| 属性 | 类型 | 说明 | |------|------|------| | agentId | number \| null | 服务端分配的客服 ID | | agentName | string | 客服显示名称 | | currentSessionId | number \| null | 当前选中的会话 ID | | messages | ChatMessageItem[] | 当前会话消息列表 |

方法

| 方法 | 签名 | 说明 | |------|------|------| | sendChat | (content: string, msgType?: MsgType) => void | 发送消息,MsgType = 'text' \| 'image' \| 'video' \| 'audio' \| 'file' | | setAgentOnline | () => void | 上线 | | setAgentOffline | () => void | 下线 | | acceptSession | (sessionId) => void | 接待会话 | | closeSession | (sessionId) => void | 关闭会话 | | requestSessionList | (page?, limit?, status?) => void | 请求会话列表 | | requestWaitingSessionList | () => void | 请求排队列表 | | requestSessionHistory | (sessionId, beforeSeq?, limit?) => void | 请求历史消息 | | sendTyping | (sessionId) => void | 发送正在输入状态 | | sendMessageRead | (sessionId, msgId, seqNum) => void | 标记消息已读 | | showPanel | () => void | 显示面板 | | hidePanel | () => void | 隐藏面板 | | registerToolbar | (item: ToolbarItem) => void | 注册工具栏按钮 | | unregisterToolbar | (key: string) => void | 注销工具栏按钮 | | registerRightPanelSidebar | (sidebar: RightPanelSidebar) => void | 注册右侧标签页 | | unregisterRightPanelSidebar | (key: string) => void | 注销右侧标签页 | | on | (event, cb) => this | 监听事件 | | off | (event, cb) => this | 取消监听 | | destroy | () => Promise<void> | 下线并断开连接 |

事件

| 事件 | 回调参数 | 说明 | |------|----------|------| | allSet | () | SDK 初始化完成 | | disconnected | (code, reason) | 连接断开 | | reconnecting | (attempt, maxAttempts) | 正在重连 | | reconnected | () | 重连成功 | | error | (error) | 错误 | | messageError | (error) | 发送失败 | | newSession | (sessionId) | 新会话进入排队 | | sessionAccepted | (sessionId) | 会话已接待 | | sessionClosed | (sessionId) | 会话已关闭 | | sessionListUpdated | () | 会话列表已刷新 | | waitingListUpdated | () | 排队列表已刷新 | | agentStatus | (onlineCount, hasOnlineAgent) | 在线客服数量变化 | | typingPush | (sessionId, senderRole, senderId) | 对方正在输入 | | messageReadPush | (sessionId, readerRole, readerId, msgId, seqNum) | 消息已读回执 | | visitorInfoUpdated | (visitorId, nickname?, phone?, avatar?) | 访客信息已更新 | | activeTimeout | () | 活跃超时自动下线 |


插件系统

SDK 提供三套插件注册 API,用于扩展工具栏、面板内容和标签页。

工具栏(Toolbar)

访客端和客服端均支持。工具栏按钮显示在聊天面板底部。

import { VisitorSDK } from '@chihqiang/ccsim-ui'

const sdk = new VisitorSDK({ /* ... */ })

sdk.registerToolbar({
  key: 'my-tool',
  icon: '<svg viewBox="0 0 24 24">...</svg>',
  label: '我的工具',
  order: 100,
  // 是否显示(可选)
  show: (ctx) => ctx.sessionId != null,
  // 按钮是否处于激活态(可选)
  active: (ctx) => myState.isActive,
  // 点击回调,ctx.active 表示当前是否已激活,可做 toggle
  onClick: (ctx) => {
    ctx.active ? close() : open()
  },
  // 关联面板区块(仅访客端,可选)
  panel: {
    component: () => import('./MyPanel.vue').then(m => m.default),
    show: () => myState.isVisible,
  },
})

// 注销(自动清理关联的 panel section)
sdk.unregisterToolbar('my-tool')

ToolbarItem

| 字段 | 类型 | 必填 | 说明 | |------|------|------|------| | key | string | 是 | 唯一标识 | | icon | string | 是 | SVG 图标字符串 | | label | string | 是 | 按钮文案(无障碍用) | | order | number | 否 | 排序,默认 100 | | show | (ctx: ToolbarContext) => boolean | 否 | 是否显示 | | active | (ctx: ToolbarContext) => boolean | 否 | 是否激活态 | | onClick | (ctx: ToolbarContext) => void | 是 | 点击回调 | | panel | { component, show? } | 否 | 关联面板(访客端) |

ToolbarContext

| 字段 | 类型 | 说明 | |------|------|------| | sessionId | number \| null | 当前会话 ID | | visitorId | number \| null | 访客 ID | | agentId | number \| null | 客服 ID | | agentName | string | 客服名称 | | role | Role | 'visitor''agent' | | active | boolean | 当前按钮是否已激活 |


面板区块(PanelSection)

访客端专用,用于在聊天面板中插入自定义内容区块。

sdk.registerPanelSection({
  key: 'my-section',
  component: MyComponent,
  order: 200,
  show: (ctx) => ctx.sessionId != null,
})

sdk.unregisterPanelSection('my-section')

通常通过 registerToolbarpanel 字段自动注册,无需手动调用。

PanelSection

| 字段 | 类型 | 必填 | 说明 | |------|------|------|------| | key | string | 是 | 唯一标识 | | component | Component | 是 | Vue 组件 | | order | number | 否 | 排序,默认 100 | | show | (ctx) => boolean | 否 | 是否显示 |


右侧标签页(RightPanelSidebar)

客服端专用,用于在右侧面板中添加自定义标签页。

import { AgentSDK } from '@chihqiang/ccsim-ui'

const sdk = new AgentSDK({ /* ... */ })

sdk.registerRightPanelSidebar({
  key: 'my-tab',
  label: '我的标签',
  icon: '📊',
  component: MyTabComponent,
  order: 200,
  onActivate: () => { /* 切到此 tab 时 */ },
  onDeactivate: () => { /* 离开此 tab 时 */ },
})

sdk.unregisterRightPanelSidebar('my-tab')

RightPanelSidebar

| 字段 | 类型 | 必填 | 说明 | |------|------|------|------| | key | string | 是 | 唯一标识 | | label | string | 是 | 标签文案 | | icon | string | 否 | 图标 | | component | Component | 是 | Vue 组件 | | order | number | 否 | 排序,默认 100 | | onActivate | () => void | 否 | 切到此 tab 时回调 | | onDeactivate | () => void | 否 | 离开此 tab 时回调 |


工具函数

import {
  SDK_VERSION,
  getVisitorInstance,
  getAgentInstance,
  setLocale,
  CcsimError,
  toCcsimError,
} from '@chihqiang/ccsim-ui'

console.log(SDK_VERSION)

const visitor = getVisitorInstance()
const agent = getAgentInstance()

TypeScript

包自带完整类型声明,无需额外安装 @types 包。

import type {
  VisitorInitOptions,
  AgentInitOptions,
  ToolbarItem,
  RightPanelSidebar,
  PanelSection,
  PanelSectionContext,
  ToolbarContext,
  Role,
  SenderTypeEnum,
  SDKStatusEnum,
  SdkEventName,
  MsgType,
  SessionStatus,
  ChatMessageItem,
} from '@chihqiang/ccsim-ui'

i18n

支持中文(zh-CN)和英文(en-US),通过构造函数 locale 参数设置。

const sdk = new VisitorSDK({
  locale: 'en-US',
})

运行时切换:

import { setLocale } from '@chihqiang/ccsim-ui'
setLocale('en-US')

枚举与常量

Role

| 值 | 说明 | |----|------| | Role.VISITOR | 访客 | | Role.AGENT | 客服 |

SenderTypeEnum

| 值 | 说明 | |----|------| | SenderTypeEnum.VISITOR | 访客 | | SenderTypeEnum.AGENT | 客服 | | SenderTypeEnum.SYSTEM | 系统 |

MessageStatusEnum

| 值 | 说明 | |----|------| | PENDING | 发送中(乐观消息) | | DELIVERED | 已送达 | | FAILED | 发送失败(5 秒超时) |

常量

| 常量 | 值 | 说明 | |------|-----|------| | HEARTBEAT_INTERVAL | 30000 | 心跳发送间隔(ms) | | AUTH_TIMEOUT | 10000 | 认证超时(ms) | | CONNECTION_TIMEOUT | 10000 | 连接超时(ms) | | LOGIN_TIMEOUT | 5000 | 登录超时(ms) | | PAGINATION_TIMEOUT | 10000 | 分页请求超时(ms) | | OPTIMISTIC_TIMEOUT | 5000 | 乐观消息超时(ms) | | MESSAGE_MAX_LENGTH | 2000 | 单条消息最大字符数 | | MAX_MESSAGES_PER_CONVERSATION | 500 | 每会话最大保留消息数 | | MAX_RECONNECT_ATTEMPTS | 10 | 最大重连次数 | | RECONNECT_BASE_DELAY | 1000 | 重连基础延迟(ms) | | MAX_RECONNECT_DELAY | 60000 | 重连最大延迟(ms) |


本地存储键

| 键名 | 用途 | |------|------| | ccsim_visitor_uuid | 访客持久化 UUID | | ccsim_session_id | 访客当前会话 ID | | ccsim_agent_should_online | 客服自动上线状态 |


WebSocket 协议

连接流程

  1. 客户端建立 WebSocket 连接
  2. 客户端发送认证消息 auth
  3. 服务端返回 auth_ok(含 conn_id),认证完成
  4. 超时 10 秒未收到 auth_ok 则断开连接

心跳机制

  • 客户端每 30 秒发送 heartbeat
  • 服务端返回 heartbeat_ack
  • 超过 75 秒未收到 ACK 则判定连接死亡,触发重连

重连策略

  • 指数退避 + 抖动
  • 基础延迟 1 秒,最大延迟 60 秒,最多 10 次

客户端消息(Client → Server)

auth — 认证

访客:

{
  "type": "auth",
  "tenant_no": "string",
  "role": "visitor",
  "external_visitor_id": "string",
  "nickname": "string",
  "phone": "string",
  "platform": "string"
}

客服:

{
  "type": "auth",
  "tenant_no": "string",
  "role": "agent",
  "agent_account": "string",
  "agent_password": "string"
}

chat_send — 发送消息

{
  "type": "chat_send",
  "session_id": 123,
  "content": "消息内容",
  "msg_type": "text",
  "temp_id": "uuid-v4"
}

heartbeat — 心跳

{ "type": "heartbeat" }

typing — 正在输入

{
  "type": "typing",
  "session_id": 123
}

message_read — 消息已读

{
  "type": "message_read",
  "session_id": 123,
  "msg_id": 456,
  "seq_num": 789
}

agent_online — 客服上线

{ "type": "agent_online" }

agent_offline — 客服下线

{ "type": "agent_offline" }

session_accept — 接待会话

{
  "type": "session_accept",
  "session_id": 123
}

session_close — 关闭会话

{
  "type": "session_close",
  "session_id": 123
}

session_history — 请求历史消息

{
  "type": "session_history",
  "session_id": 123,
  "before_seq": 100,
  "limit": 20
}

session_list — 请求会话列表

{
  "type": "session_list",
  "page": 1,
  "limit": 20,
  "status": "active"
}

waiting_session_list — 请求排队列表

{ "type": "waiting_session_list" }

satisfaction_rate — 满意度评价

{
  "type": "satisfaction_rate",
  "session_id": 123,
  "rating": 1
}

visitor_update — 更新访客信息

{
  "type": "visitor_update",
  "nickname": "新昵称",
  "phone": "13800138000",
  "avatar": "https://...",
  "metadata": { "key": "value" }
}

服务端消息(Server → Client)

auth_ok — 认证成功

{
  "type": "auth_ok",
  "conn_id": "string",
  "agent_id": 123,
  "visitor_id": 456
}

heartbeat_ack — 心跳响应

{ "type": "heartbeat_ack" }

chat_ack — 消息发送确认

{
  "type": "chat_ack",
  "temp_id": "uuid-v4",
  "msg_id": 789,
  "session_id": 123,
  "seq_num": 1,
  "created_at": 1700000000000
}

chat_push — 消息推送

{
  "type": "chat_push",
  "msg_id": 789,
  "session_id": 123,
  "sender_role": "visitor",
  "sender_id": 456,
  "nickname": "访客",
  "content": "消息内容",
  "msg_type": "text",
  "seq_num": 1,
  "created_at": 1700000000000
}

offline_push — 离线消息推送

{
  "type": "offline_push",
  "messages": [
    {
      "msg_id": 789,
      "session_id": 123,
      "sender_role": "agent",
      "sender_id": 100,
      "nickname": "客服",
      "content": "你好",
      "msg_type": "text",
      "seq_num": 1,
      "created_at": 1700000000000
    }
  ]
}

history_batch — 历史消息

{
  "type": "history_batch",
  "session_id": 123,
  "count": 20,
  "data": [
    {
      "msg_id": 789,
      "session_id": 123,
      "sender_role": "visitor",
      "sender_id": 456,
      "nickname": "访客",
      "content": "消息内容",
      "msg_type": "text",
      "seq_num": 1,
      "created_at": 1700000000000
    }
  ]
}

session_created — 会话创建

{
  "type": "session_created",
  "session_id": 123,
  "status": "waiting",
  "created_at": 1700000000000
}

session_assigned — 会话分配

{
  "type": "session_assigned",
  "session_id": 123,
  "agent_id": 100,
  "agent_nickname": "客服A",
  "agent_avatar": "https://..."
}

session_closed — 会话关闭

{
  "type": "session_closed",
  "session_id": 123,
  "close_reason": "agent_close"
}

session_list_res — 会话列表

{
  "type": "session_list_res",
  "items": [
    {
      "session_id": 123,
      "visitor_id": 456,
      "visitor_nickname": "访客",
      "visitor_phone": "13800138000",
      "visitor_external_id": "ext_001",
      "agent_id": 100,
      "agent_nickname": "客服A",
      "status": "active",
      "source": "web",
      "ip": "127.0.0.1",
      "country": "中国",
      "province": "广东",
      "city": "深圳",
      "user_agent": "Mozilla/5.0...",
      "platform": "web",
      "last_msg_content": "你好",
      "last_msg_time": 1700000000000,
      "unread_count": 2,
      "created_at": 1700000000000
    }
  ],
  "total": 50,
  "page": 1,
  "limit": 20
}

waiting_session_list_res — 排队列表

{
  "type": "waiting_session_list_res",
  "items": [
    {
      "session_id": 123,
      "visitor_id": 456,
      "visitor_nickname": "访客",
      "visitor_avatar": "https://...",
      "visitor_phone": "13800138000",
      "visitor_external_id": "ext_001",
      "source": "web",
      "ip": "127.0.0.1",
      "country": "中国",
      "province": "广东",
      "city": "深圳",
      "user_agent": "Mozilla/5.0...",
      "platform": "web",
      "last_msg_content": "你好",
      "created_at": 1700000000000,
      "waiting_seconds": 30
    }
  ]
}

new_session — 新会话通知

{
  "type": "new_session",
  "session_id": 123,
  "visitor_id": 456,
  "visitor_nickname": "访客",
  "visitor_phone": "13800138000",
  "visitor_external_id": "ext_001",
  "source": "web",
  "ip": "127.0.0.1",
  "platform": "web",
  "last_msg_content": "你好",
  "created_at": 1700000000000
}

agent_status — 在线客服状态

{
  "type": "agent_status",
  "online_count": 3,
  "has_online_agent": true
}

typing_push — 正在输入推送

{
  "type": "typing_push",
  "session_id": 123,
  "sender_role": "visitor",
  "sender_id": 456
}

message_read_push — 已读回执

{
  "type": "message_read_push",
  "session_id": 123,
  "reader_role": "agent",
  "reader_id": 100,
  "msg_id": 789,
  "seq_num": 1
}

satisfaction_rate — 评价确认

{
  "type": "satisfaction_rate",
  "session_id": 123,
  "status": "ok"
}

visitor_update_ok — 访客信息更新确认

{ "type": "visitor_update_ok" }

visitor_info_updated — 访客信息变更通知

{
  "type": "visitor_info_updated",
  "session_id": 123,
  "visitor_id": 456,
  "nickname": "新昵称",
  "phone": "13900139000",
  "avatar": "https://..."
}

error — 错误

{
  "type": "error",
  "code": "AUTH_FAILED",
  "err_msg": "invalid credentials",
  "message": "认证失败"
}

ClientMessageTypeEnum

| 值 | 字符串 | 说明 | |----|--------|------| | AUTH | auth | 认证 | | HEARTBEAT | heartbeat | 心跳 | | CHAT_SEND | chat_send | 发送消息 | | AGENT_ONLINE | agent_online | 客服上线 | | AGENT_OFFLINE | agent_offline | 客服下线 | | SESSION_ACCEPT | session_accept | 接待会话 | | SESSION_CLOSE | session_close | 关闭会话 | | SESSION_LIST | session_list | 会话列表 | | SESSION_HISTORY | session_history | 历史消息 | | WAITING_SESSION_LIST | waiting_session_list | 排队列表 | | SATISFACTION_RATE | satisfaction_rate | 满意度评价 | | USER_UPDATE | visitor_update | 更新访客信息 | | TYPING | typing | 正在输入 | | MESSAGE_READ | message_read | 消息已读 |

ServerMessageTypeEnum

| 值 | 字符串 | 说明 | |----|--------|------| | AUTH_OK | auth_ok | 认证成功 | | HEARTBEAT_ACK | heartbeat_ack | 心跳响应 | | CHAT_ACK | chat_ack | 消息确认 | | CHAT_PUSH | chat_push | 消息推送 | | OFFLINE_PUSH | offline_push | 离线消息 | | HISTORY_BATCH | history_batch | 历史消息 | | SESSION_CREATED | session_created | 会话创建 | | SESSION_ASSIGNED | session_assigned | 会话分配 | | SESSION_CLOSED | session_closed | 会话关闭 | | SESSION_LIST_RES | session_list_res | 会话列表 | | WAITING_SESSION_LIST_RES | waiting_session_list_res | 排队列表 | | NEW_SESSION | new_session | 新会话 | | AGENT_STATUS | agent_status | 在线状态 | | AGENT_ONLINE | agent_online | 客服上线 | | AGENT_OFFLINE | agent_offline | 客服下线 | | TYPING_PUSH | typing_push | 正在输入 | | MESSAGE_READ_PUSH | message_read_push | 已读回执 | | ERROR | error | 错误 | | VISITOR_INFO_UPDATED | visitor_info_updated | 访客信息更新 | | SATISFACTION_RATE | satisfaction_rate | 评价确认 | | VISITOR_UPDATE_OK | visitor_update_ok | 更新确认 |