mirror of
https://github.com/Funkoala14/knowledgebase_law.git
synced 2025-06-08 05:28:15 +08:00
27 lines
812 B
JavaScript
27 lines
812 B
JavaScript
import { createAsyncThunk } from '@reduxjs/toolkit';
|
|
import { get, post } from '../../services/api';
|
|
|
|
/**
|
|
* 发送聊天消息
|
|
* @param {Object} params - 消息参数
|
|
* @param {string} params.chatId - 聊天ID
|
|
* @param {string} params.content - 消息内容
|
|
*/
|
|
export const sendMessage = createAsyncThunk('chat/sendMessage', async ({ chatId, content }, { rejectWithValue }) => {
|
|
try {
|
|
const response = await post(`/chat-history/${chatId}/messages/`, {
|
|
content,
|
|
type: 'text',
|
|
});
|
|
|
|
// 处理返回格式
|
|
if (response && response.code === 200) {
|
|
return response.data;
|
|
}
|
|
|
|
return response.data || {};
|
|
} catch (error) {
|
|
return rejectWithValue(error.response?.data?.message || 'Failed to send message');
|
|
}
|
|
});
|