FredrikOseberg / react-chatbot-kit

MIT License
325 stars 155 forks source link

How to avoid creating new message when user enters null value? #59

Closed VeenaMalali13 closed 3 years ago

VeenaMalali13 commented 3 years ago

When user types nothing in input and hit enter/submit button, it should not create new user message with createChatBotMesage() method. Rather it should not accept null value. Trying to do this, but not getting solution.

FredrikOseberg commented 3 years ago

When user types nothing in input and hit enter/submit button, it should not create new user message with createChatBotMesage() method. Rather it should not accept null value. Trying to do this, but not getting solution.

Hi there!

You can pass a function to the chatbot to check if the client message is valid or not:

const validator = (input) => {
     if (input.length > 3) return true;
     return false
}

<Chatbot messageParser={messageParser} config={config) actionProvider={actionProvider} validator={validator} />
VeenaMalali13 commented 3 years ago

Thank You Fredrik...This helped me