From 5096c75de86b84f3143f7c8358ea37c843428ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9F=E8=B4=A4?= Date: Tue, 11 Jun 2024 18:09:24 +0800 Subject: [PATCH] feat: send message support ChatMessage --- src/hooks/useChatList.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hooks/useChatList.ts b/src/hooks/useChatList.ts index 2ab2f4a..5a7a942 100644 --- a/src/hooks/useChatList.ts +++ b/src/hooks/useChatList.ts @@ -196,9 +196,19 @@ export const useChatList = (props: ProChatUIUseListChatProps) => { * @param {string} message - The message to send. * @returns {Promise} - A promise that resolves when the message is sent. */ - const sendMessage = useRefFunction(async (message: string) => { + const sendMessage = useRefFunction(async (message: string | Partial) => { controller.current = new AbortController(); - chatList.push(genMessageRecord({ content: message }, 'user')); + chatList.push( + genMessageRecord( + typeof message === 'string' + ? { content: message } + : { + ...message, + content: message.content, + }, + 'user', + ), + ); setChatList([...chatList]); if (!props?.sendMessageRequest) return; setLoadingMessage(