diff --git a/Touchkebao/src/api/ai.ts b/Touchkebao/src/api/ai.ts index 35625ecb..6dca8751 100644 --- a/Touchkebao/src/api/ai.ts +++ b/Touchkebao/src/api/ai.ts @@ -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: '...公告内容...' } diff --git a/Touchkebao/src/store/module/weChat/weChat.ts b/Touchkebao/src/store/module/weChat/weChat.ts index 58ee18c1..5068f3c0 100644 --- a/Touchkebao/src/store/module/weChat/weChat.ts +++ b/Touchkebao/src/store/module/weChat/weChat.ts @@ -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()( 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;