-
-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-chatbotify with Signal R #300
Comments
Hey @div3791! To preface, real-time messaging requires significant custom code currently. This is because there are inherent assumptions made within the core library (such as turn-based conversations) that must be addressed for live chat to work. There are plans to make a live chat plugin, but the plugins for LLM are taking priority at the moment so until those are completed, live chat plugin is still a while away. That said, you can go ahead and implement live chat by adopting the following approach. Note that I have yet to properly validate this approach but it is what comes to mind (my intention was to validate it when I start work on the live chat plugin but here goes):
Overall a significant amount of code additions but what I've shared is the tentative approach I intend to use for the live chat plugin as well. Things may and will likely change when I get down to actual implementation but this is currently it. If this is urgent for you and you'd like to hack away at it, feel free to reach out on discord. I don't mind exploring solutions with you since this is a task I'll get to eventually as well :) Though note that even if we bounce ideas currently, you'll have to do most of the coding and testing because my hands are tied on other areas of work such as the LLM plugins 🥹 |
Thanks a lot @tjtanjin for prompt reply!!!!! When I tried to add custom component in injectMessage( it added to the chat window. but when I received signal r message, and tried to delete last message which is typing indicator component by message id it doesnt remove the typing indicator. I tried to check local storage where all the chats are being stored, Some times I can see typing indicator is not geeting deleted. and some times I got different message Id when I saved result of
Removal logic of typing indicator written in different file
As a thanks and gratitude gesture, I will contribute to make this library more robust which can support signal r and other sockets once my current project is completed!!! Thanks & Best Regards, |
Hey @div3791, unfortunately I'm overseas at the moment and don't have my PC/laptop with me 🥹 I'll only be back in the middle of march so until then, I don't have a conducive setup for development-related work. With that said, I can provide you with a couple of links I believe will come in useful:
From the brief implementation you shared above, I suggest you store the id of the typing indicator and pass it directly into Appreciate your interest to help, happy to have you around as work for the live chat plugin kicks in 😊 |
Thanks @tjtanjin I will go through the links given by you and will back to you!! |
here typingId is string message id. This is not removing message from chat window as well as local storage @tjtanjin |
Have you checked if your id passed in is actually correct? Here's what works on the playground (formatting might be off, was trying it from my mobile):
|
Yes @tjtanjin I re-verified I tried with setTimeout also but didnt worked Sir. I am in trouble now. If possible, please help me @tjtanjin Thanks & Best Regards, |
Hey @div3791, are you able to recreate the issue on the playground and paste it here for me to reproduce and debug? 🥹 |
@tjtanjin Observed one thing. |
It should work 🥹 Where are you placing this specific line? If possible, can you share the full code for ease of reference? |
I am placing const let me explain scenario. When user send any message, I am manually injecting message into chat window using When signal r receives any message, before calling I cross verified messageIds into local storage and saved message id in zustand store. Please suggest me something @tjtanjin . My boss is now anticipating complete the project within 2 days |
So what I'd do is to add a |
Okay @tjtanjin could you please tell me where should I prepare sample code?? suggest playground link from where i can share you a implementation becasue my react app project is very large. it will be too difficult to extract perticular code. |
You can try to reproduce the issue here on the playground then paste the code below once you're done 😀 To make things easier, can I suggest you work off this example shared here to edit (paste the snippet in the playground): #300 (comment) |
Or else you can explain below things in your prefered way. how getChatHistory() and setChatHistory() works from useChatHistory() hook in react-chatbotify 2.0.0-beta.28?? and how messages property from useMessages() hook?? and what is the difference between messages from useMessages() hook and getChatHistory() from useChatHistory() hook?? I want to inject typing indicator after user submits or sends any message everytime. and remove typing indicator when i am getting any message from server actually sometimes I am getting getChatHistory() and messages from useMessages() as blank array. sometimes it has some messages. cant understand behaviour of these hooks and methods. which messages will it return from getChatHistory() and messages object? and will setChatHistory() trigger the UI update or not? how it behaves in case of page hard reload or tab reopen etc. I am using vite+react+typescript I tried to tweak the flow by using getChatHistory() and setChatHistory() and messages object. I tried to remove last message which is of course typing indicator message. but its not working. Below is my chatbot code.
|
For your use case, you should stick with I see your code snippet, but it doesn't contain the part where it's using Edit: On a side note, beta.31 is the latest version so it might help to bump the package while you're at this. |
Okay I will prepare code on playground Till than could you please provide any resource from where I can understand how messages object works and when it triggers UI update and local storage messages?? Sometimes I noticed even there are chats in local storage, messages object shows blank array How can I manipulate messages object?? Which actually remove message from local storage as well as chat window? Thanks and Best Regards |
You are strongly discouraged from modifying or referring to the local storage as it's handled internally by the library. The local storage basically stores chat history and is refreshed/updated whenever there are message changes. The messages array in the chatbot on the other hand represents what is being shown in the chat window itself. As such, your messages array in the chatbot may or may not match what is in local storage depending on whether the chat history has been loaded by the user. If the above sounds confusing to you, that is because these are internal behaviors handled within the chatbot. Users such as yourself shouldn't have to dig into such behaviors and should only interact with messages via the provided utility functions. The resources for these functions are on the documentation website which you've probably been referring to. There are currently no resources for understanding the chat history implementation (there's a developer guide in the repository, but regrettably the chat history implementation hasn't been updated). Regardless, this is not a behavior you should have to dig into. |
Okay so messages object contains those messages which is present in chat window right? So how can I update messages object? Basically i want to remove last message from chat window |
Circles back to |
Hi @tjtanjin , I reproduced the issue. I tried using playground and there also Here is playground code:
Here is console logs screenshot: |
Hey @div3791, noticed you're using setTimeout. It's likely the callback inside is capturing the state (and function) values at the time that it was created. Instead of using
Then add an effect to update it:
Inside your callback, use this ref instead. This should resolve your issue, let me know! |
Thank you so much @tjtanjin It worked now. Thank you for saving me ❤️ I want to add signal r support to this library. How can I start my contribution? |
Happy to hear it works! For signal r support, it's probably best to introduce it in the form of a plugin. You can make references to existing plugins as well as a provided template here: https://github.com/React-ChatBotify-Plugins |
Help Description:
I want to integrate Signal R for real time messaging with react-chatbotify. I also want to show typing indicator immedietly after user sends a message and typing indicator should be displayed untill any message doesnt come through Signal R event.
Library version:
2.0.0-beta.28.
Additional context:
I am using Vite + React + Signal R (Through Background Service Worker). When user opens chat window for first time, it should show welcome message. and after user sends first message, REST API is being called to send message to server and my chatbot is waiting for response from server through Signal R. I am using background service worker to manage signal connections and events
The text was updated successfully, but these errors were encountered: