saveMessages doesn't work
jhonatan-dev opened this issue · comments
Jhonatan commented
Thanks for this great kit for making easy to build chatbot.
This is great one. But, I think, this has also some gaps. For example, to save dialogue, I tried to use saveMessages. But, it doesn't work.
And the loading component shows after getting server response. Sometimes, the server response could be 1 or even 2 secs. So, it's critical.
I hope these gaps are get rid of asap
Jhonatan commented
Hi @FredrikOseberg,
I found saveMessage solution by adding few lines on useChatbot.ts script.
const [messageContainer, setMessageContainer] = useState<any>({});
const setMessageContainerRef = (containerRef: any) => {
setMessageContainer(containerRef)
}
useEffect(() => {
return () => {
if (saveMessages && typeof saveMessages === 'function') {
const HTML = messageContainer?.current?.innerHTML.toString();
if (!messageContainer) return;
saveMessages(messagesRef.current, HTML);
}
};
}, [messageContainer.current]);
That works fine.
May I send PR with this change?
Thanks.
Captain commented
Thanks @jhonatan-dev
That really works well. I solved the saving messages issue.