新增AI对话和数据处理接口,优化消息发送逻辑以支持群组和个人消息的处理,提升聊天功能的灵活性和用户体验。
This commit is contained in:
@@ -1,5 +1,42 @@
|
||||
import axios from "axios";
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
import { request } from "@/api/request";
|
||||
|
||||
//ai对话接口
|
||||
export interface AiChatParams {
|
||||
friendId: number;
|
||||
wechatAccountId: number;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export function aiChat(params: AiChatParams) {
|
||||
return request("/v1/kefu/ai/chat", params, "POST");
|
||||
}
|
||||
|
||||
//soket消息传入数据中心
|
||||
export interface DataProcessingParams {
|
||||
/**
|
||||
* 群消息
|
||||
*/
|
||||
chatroomMessage?: string[];
|
||||
/**
|
||||
* 个人信息
|
||||
*/
|
||||
friendMessage?: string[];
|
||||
/**
|
||||
* 类型固定值
|
||||
*/
|
||||
type?: string;
|
||||
/**
|
||||
* 公共
|
||||
*/
|
||||
wechatAccountId?: string;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export function dataProcessing(params: DataProcessingParams) {
|
||||
return request("/v1/kefu/dataProcessing", params, "POST");
|
||||
}
|
||||
|
||||
/**
|
||||
* AI文本生成接口
|
||||
@@ -32,7 +69,7 @@ export async function generateAiText(
|
||||
Authorization: token ? `Bearer ${token}` : undefined,
|
||||
},
|
||||
timeout: 30000, // AI生成可能需要更长时间
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 新接口返回:{ code: 200, msg: 'success', data: '...公告内容...' }
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
getGroupMembers,
|
||||
} from "@/pages/pc/ckbox/api";
|
||||
import { WeChatState } from "./weChat.data";
|
||||
|
||||
import { dataProcessing, aiChat } from "@/api/ai";
|
||||
import {
|
||||
likeListItem,
|
||||
CommentItem,
|
||||
@@ -312,6 +312,26 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
set(state => ({
|
||||
currentMessages: [...state.currentMessages, message],
|
||||
}));
|
||||
//把数据传到存客宝
|
||||
const params: any = {
|
||||
type: "CmdNewMessage",
|
||||
wechatAccountId: currentContract.wechatAccountId,
|
||||
};
|
||||
if (isWechatGroup) {
|
||||
params.chatroomMessage = [message];
|
||||
} else {
|
||||
params.friendMessage = [message];
|
||||
}
|
||||
const dataProcessingResult = await dataProcessing(params);
|
||||
//如果成功,就请求ai对话接口
|
||||
if (dataProcessingResult) {
|
||||
const messageContent = await aiChat({
|
||||
friendId: getMessageId,
|
||||
wechatAccountId: currentContract.wechatAccountId,
|
||||
message: message,
|
||||
});
|
||||
console.log("ai对话接口返回", messageContent);
|
||||
}
|
||||
} else {
|
||||
// 更新其他聊天的未读消息数
|
||||
const chatSessions = useCkChatStore.getState().chatSessions;
|
||||
|
||||
Reference in New Issue
Block a user