feat(mini): add voice recording compatibility logging
This commit is contained in:
@@ -690,7 +690,14 @@ function getUploadErrorMessage(data: any): string {
|
||||
|
||||
export async function sendParentVoiceMessage(
|
||||
childId: number,
|
||||
options: { filePath: string; durationMs: number; transcriptText?: string }
|
||||
options: {
|
||||
filePath: string
|
||||
durationMs: number
|
||||
transcriptText?: string
|
||||
audioFormat?: string
|
||||
mimeType?: string
|
||||
runtime?: Record<string, any>
|
||||
}
|
||||
): Promise<ConversationMessageCreateResponse> {
|
||||
if (!childId) {
|
||||
throw new Error('当前会话不支持留言')
|
||||
@@ -701,6 +708,16 @@ export async function sendParentVoiceMessage(
|
||||
|
||||
const token = getToken()
|
||||
const requestUrl = `${BASE_URL}/banban/children/${childId}/voice-message`
|
||||
console.info('[voice-upload] request', {
|
||||
childId,
|
||||
requestUrl,
|
||||
filePath: options.filePath,
|
||||
durationMs: options.durationMs,
|
||||
audioFormat: options.audioFormat || '',
|
||||
mimeType: options.mimeType || '',
|
||||
runtime: options.runtime || {},
|
||||
hasToken: Boolean(token),
|
||||
})
|
||||
const uploadResponse: any = await new Promise((resolve, reject) => {
|
||||
Taro.uploadFile({
|
||||
url: requestUrl,
|
||||
@@ -715,9 +732,26 @@ export async function sendParentVoiceMessage(
|
||||
duration_ms: `${Math.max(1, Math.round(options.durationMs || 0))}`,
|
||||
client_msg_id: createClientMessageId(),
|
||||
transcript_text: options.transcriptText || '',
|
||||
audio_format: options.audioFormat || '',
|
||||
mime_type: options.mimeType || '',
|
||||
},
|
||||
success: (response) => {
|
||||
console.info('[voice-upload] response', {
|
||||
statusCode: response.statusCode,
|
||||
errMsg: response.errMsg,
|
||||
dataType: typeof response.data,
|
||||
})
|
||||
resolve(response)
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('[voice-upload] fail', {
|
||||
childId,
|
||||
requestUrl,
|
||||
errMsg: error?.errMsg,
|
||||
message: error?.message,
|
||||
})
|
||||
reject(error)
|
||||
},
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
}).catch((error: any) => {
|
||||
const message = String(error?.errMsg || error?.message || 'request:fail')
|
||||
@@ -730,6 +764,10 @@ export async function sendParentVoiceMessage(
|
||||
|
||||
const data = parseUploadResponseData(uploadResponse.data)
|
||||
if (uploadResponse.statusCode >= 400) {
|
||||
console.error('[voice-upload] error response', {
|
||||
statusCode: uploadResponse.statusCode,
|
||||
data,
|
||||
})
|
||||
throw new ApiError(uploadResponse.statusCode, getUploadErrorMessage(data))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user