fix: AI客服回复内容格式化(换行+加粗+列表)

This commit is contained in:
2026-10-12 17:12:19 +08:00
parent ca7d179d1b
commit 5039968316
58 changed files with 3551 additions and 905 deletions
@@ -3,9 +3,9 @@ module.exports = {
let { data = {}, userInfo } = event;
const COZE_TOKEN = 'sat_OiXlI4Da5Q99fxmul6pNfExmA6hR898UbxBDwrvjZ638APxRSlFnXbz6zyFedKNG';
const BOT_ID = '7680345813062680618';
// 从前端传入 bot_id,不同项目用不同智能体
const BOT_ID = data.bot_id || '7680345813062680618';
// 使用流式接口,直接从 SSE 事件中提取回答
const res = await uniCloud.httpclient.request('https://api.coze.cn/v3/chat', {
method: 'POST',
dataType: 'text',
@@ -25,11 +25,9 @@ module.exports = {
}
});
// 从 SSE 文本中提取 type=answer 的内容
let answer = '暂时无法回复,请拨打 400-686-5559 咨询';
let conversationId = '';
const text = res.data || '';
const lines = text.split('\n');
for (const line of lines) {
if (!line.startsWith('data:')) continue;
@@ -41,7 +39,7 @@ module.exports = {
if (p.type === 'answer' && p.content) {
answer = p.content;
}
} catch (e) { /* 跳过非 JSON 行 */ }
} catch (e) { /* 跳过 */ }
}
return {