react-chat-widget
react-chat-widget copied to clipboard
Render messages from a database
Hi!
Thanks for this awesome module.
Just wanted to ask if there was a way to have the chat window render messages that are saved in a database?
I'm saving messages in Firebase, and need the messages that were previously sent to render in the chat window when they are opened.
Is there a way to specify a source for these messages?
Hi @davidbaek92! What you can do is use either the addResponseMessage
and addUserMessage
when the component that's using the widget is going to be rendered. You can use whatever source you need since that will be handled by the component using the widget. For example:
import { addResponseMessage } from 'react-chat-widget';
...
export default MyComponent extends React.Component {
handleUserMessage = message => {
doSomethingWithTheUserMessage(message).then(response => {
addResponseMessage(response);
});
}
render() {
return ...
}
}
Hi Martin!
It seems like the above code is sending a response message in the Widget every time a user sends a message? This isn't exactly what I'm looking for.
What I have is an array of messages being held in state within a React component. What I need is for the chat widget to show all the old messages that are held in state once the Widget button is clicked and the chat view is opened.
Is there any way for me to do this?
On Sun, May 13, 2018 at 5:30 PM, Martín Callegari [email protected] wrote:
Hi @davidbaek92 https://github.com/davidbaek92! What you can do is use either the addResponseMessage and addUserMessage when the component that's using the widget is going to be rendered. You can use whatever source you need since that will be handled by the component using the widget. For example:
import { addResponseMessage } from 'react-chat-widget';... export default MyComponent extends React.Component { handleUserMessage = message => { doSomethingWithTheUserMessage(message).then(response => { addResponseMessage(response); }); }
render() { return ... }
}
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Wolox/react-chat-widget/issues/56#issuecomment-388657399, or mute the thread https://github.com/notifications/unsubscribe-auth/Abuo__KxC-POG02tkFN7RqBlp3iIMp7Bks5tyKXxgaJpZM4T8ehi .
@davidbaek92 you can fetch / pre-load these messages from your database at your componentDidMount()
is called, just append these data using addResponseMessage
, addUserMessage
, addLinkSnippet
to the component as soon as the previous messages were received.
@davidbaek92 Did we answer your question or you need more help? :slightly_smiling_face:
@davidbaek92 you can fetch / pre-load these messages from your database at your
componentDidMount()
is called, just append these data usingaddResponseMessage
,addUserMessage
,addLinkSnippet
to the component as soon as the previous messages were received.
But it is appending all previous Chat messages too. Can you help me on this??