把 AI 客服嵌入你的系统,3 步搞定
上传知识库、设置对话流程、配置高级指令(action_code)
复制几行代码,配置 configId,插入网页即可
监听 chat:action 事件,与你的现有系统打通
在鸣谷智答后台完成客服配置后,系统会生成一个 configId,每个配置独立管理。
⚙️ 高级指令配置格式
在后台的 预先对接指令 字段中,每行一条指令:
描述:获取当前登录用户信息 action code: get_user_info
描述:查询订单状态 action code: query_order
描述:重置密码 action code: reset_password
描述:转接人工客服 action code: transfer_human
描述:获取天气信息 action code: get_weather_info📌 格式说明:
描述:xxx — 用户对话中触发的意图描述,AI 会自动识别匹配action code: xxx — 触发后发送给宿主系统的动作码chat:action 事件,携带对应的 action_code。 configId,用于 SDK 初始化。在你的网页 </body> 前插入以下代码:
<script>
// 1. 动态加载 SDK
const script = document.createElement('script');
const prefix = 'https://bjchatai.xyz'; // 鸣谷智答服务地址
script.type = 'module';
script.src = prefix + '/widget.js';
script.async = true;
script.onload = () => {
window.__CHAT_LOADED = true;
};
document.body.appendChild(script);
// 2. 配置客服参数
window.__CHAT_CONFIG__ = {
apiBase: prefix + '/api',
configId: 2, // ← 替换成你的配置ID
name: '智能客服',
theme: 'light',
primaryColor: '#3a86ff',
position: 'bottom-right',
width: 380,
height: 550,
welcomeMessage: '你好!有什么可以帮您的吗?',
placeholder: '请输入您的问题...',
autoOpen: false,
iconUrl: prefix + '/chat_avatars/default_avatar.png'
};
</script>支持多种接入方式:
action_code 是鸣谷智答与你现有系统之间的通信桥梁。 AI 识别到你在步骤一中配置的指令意图后,会触发对应的 action_code。
🔹 工作原理
🔹 前端监听(在你的系统中添加)
// 监听 action_code 事件
window.addEventListener('chat:action', (e) => {
const { action_code, params, user_id } = e.detail;
// 示例:将 action_code 发送到你的后端
fetch('/api/your-system/action', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action_code, params, user_id })
});
});
// 监听导航事件
window.addEventListener('chat:navigate', (e) => {
const { route_path } = e.detail;
window.open(route_path, '_blank');
});🔹待完善: 服务端处理(你的后端实现)
app.post('/api/your-system/action', (req, res) => {
const { action_code, params, user_id } = req.body;
switch (action_code) {
case 'get_user_info':
const user = db.query('SELECT * FROM users WHERE id = ?', user_id);
return res.json({ result: user });
case 'query_order':
const orders = db.query('SELECT * FROM orders WHERE user_id = ?', user_id);
return res.json({ result: orders });
case 'reset_password':
await sendResetEmail(params.email);
return res.json({ result: '重置链接已发送' });
case 'transfer_human':
await createTransferTicket(user_id);
return res.json({ result: '已转接人工客服,请稍候' });
default:
return res.json({ result: '未知操作' });
}
});SDK 会派发以下事件,你可以监听并响应:
| 事件名 | 触发时机 | 事件参数 |
|---|---|---|
chat:action | 用户触发高级指令(action_code) | { action_code, params, user_id } |
chat:navigate | 点击对话中的导航链接 | { route_path, route_name, route_params } |
chat:transfer | 转接人工客服 | { target, reason } |
chat:link | 点击外部链接 | { url, title } |
📬 如有疑问或需要定制接入方案,欢迎联系
联系我 →