|
@@ -84,7 +84,7 @@ export function useStreamChat() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const sendMessage = (message, agentId, agentGender, ttsVcnList, isGreeting = false) => {
|
|
|
|
|
|
|
+ const sendMessage = (message, agentId, agentGender, ttsVcnList, isGreeting = false, customerPhone = null, type = null) => {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
// 发送新消息前,停止当前播放的音频
|
|
// 发送新消息前,停止当前播放的音频
|
|
|
stopAudio()
|
|
stopAudio()
|
|
@@ -105,7 +105,9 @@ export function useStreamChat() {
|
|
|
ttsVcnList,
|
|
ttsVcnList,
|
|
|
conversationId: conversationId.value,
|
|
conversationId: conversationId.value,
|
|
|
isGreeting,
|
|
isGreeting,
|
|
|
- requestId: thisRequestId // 发送requestId到后端
|
|
|
|
|
|
|
+ requestId: thisRequestId, // 发送requestId到后端
|
|
|
|
|
+ customerPhone,
|
|
|
|
|
+ type
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fetch(API_ENDPOINTS.messageStream, {
|
|
fetch(API_ENDPOINTS.messageStream, {
|
|
@@ -113,10 +115,26 @@ export function useStreamChat() {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Content-Type': 'application/json',
|
|
'Content-Type': 'application/json',
|
|
|
'Authorization': token ? `Bearer ${token}` : '',
|
|
'Authorization': token ? `Bearer ${token}` : '',
|
|
|
- 'clientid': 'talk-web'
|
|
|
|
|
|
|
+ 'clientid': '812b745b34558590c92e6f13fe8b716b'
|
|
|
},
|
|
},
|
|
|
body: JSON.stringify(requestBody)
|
|
body: JSON.stringify(requestBody)
|
|
|
- }).then(response => {
|
|
|
|
|
|
|
+ }).then(async response => {
|
|
|
|
|
+ // 检查Content-Type,如果是JSON说明是错误响应
|
|
|
|
|
+ const contentType = response.headers.get('content-type')
|
|
|
|
|
+ if (contentType && contentType.includes('application/json')) {
|
|
|
|
|
+ const errorData = await response.json()
|
|
|
|
|
+ if (errorData.code === 401) {
|
|
|
|
|
+ console.error('Token已过期,请重新登录')
|
|
|
|
|
+ localStorage.removeItem('talk_token')
|
|
|
|
|
+ localStorage.removeItem('talk_user')
|
|
|
|
|
+ window.location.reload()
|
|
|
|
|
+ reject(new Error('Token已过期'))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ reject(new Error(errorData.msg || '请求失败'))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const reader = response.body.getReader()
|
|
const reader = response.body.getReader()
|
|
|
const decoder = new TextDecoder()
|
|
const decoder = new TextDecoder()
|
|
|
let buffer = '' // 累积未处理的数据
|
|
let buffer = '' // 累积未处理的数据
|