diff --git a/src/hooks/internal/useMessagesInternal.ts b/src/hooks/internal/useMessagesInternal.ts index c508042f..d4ac62be 100644 --- a/src/hooks/internal/useMessagesInternal.ts +++ b/src/hooks/internal/useMessagesInternal.ts @@ -81,7 +81,7 @@ export const useMessagesInternal = () => { /** * Removes a message with the given id. */ - const removeMessage = useCallback((messageId: string): string | null => { + const removeMessage = useCallback(async (messageId: string): Promise => { const message = messages.find(msg => msg.id === messageId); // nothing to remove if no such message @@ -211,7 +211,7 @@ export const useMessagesInternal = () => { return updatedMessages; }); return streamMessageMap.current.get(sender) || null; - },[]); + }, []); /** * Sets the streaming mode of the chatbot. @@ -227,7 +227,7 @@ export const useMessagesInternal = () => { * be made mandatory. Another key implication of not using `endStreamMessage` in v2 is that the stop stream * message event will not be emitted, which may be problematic for logic (or plugins) that rely on this event. */ - const endStreamMessage = (sender = "bot"): boolean => { + const endStreamMessage = useCallback(async (sender = "bot"): Promise => { // nothing to end if not streaming if (!streamMessageMap.current.has(sender)) { return true; @@ -245,7 +245,7 @@ export const useMessagesInternal = () => { streamMessageMap.current.delete(sender); saveChatHistory(messages); return true; - } + }, [messages]); return { endStreamMessage, diff --git a/src/types/Params.ts b/src/types/Params.ts index f25653dc..f81a9c19 100644 --- a/src/types/Params.ts +++ b/src/types/Params.ts @@ -10,8 +10,8 @@ export type Params = { setTextAreaValue: (value: string) => void; injectMessage: (content: string | JSX.Element, sender?: string) => Promise; streamMessage: (content: string | JSX.Element, sender?: string) => Promise; - removeMessage: (id: string) => string | null; - endStreamMessage: (sender: string) => boolean; + removeMessage: (id: string) => Promise; + endStreamMessage: (sender: string) => Promise; showToast: (content: string | JSX.Element, timeout?: number) => void; dismissToast: (id: string) => string | null; openChat: (isOpen: boolean) => void;