FredrikOseberg / react-chatbot-kit

MIT License
301 stars 141 forks source link

It is possible to load the questions and answers from an API #4

Closed 88hichem88 closed 3 years ago

88hichem88 commented 3 years ago

Is it possible to load message parser and config from an API :

I want to develop a backend that save all the messages sent by clients and from the backend type a reply for each of these questions .

FredrikOseberg commented 3 years ago

Sure. You can provide the message parser and config through an API. If you want the backend to be able to handle responding to client messages I think the easiest way to do that would be to call on your API inside of the actionprovider, with the client message as payload, then receive a response and set a new state in the bot.

// In action provider
const handleSomeAction = async (message) => {
     const response = await callAPI(message)
     const data = await response.json()

     const botMessage = this.createChatBotMessage(data.botResponse)
     // Insert your update state function name here
     this.updateMessages(botMessage)
}
ryanpome commented 1 year ago

Is it possible to use the loading state more effectively with async/await? if the request takes some time, the chatbot is left without a loading state while the request happens