Last active
June 22, 2021 15:48
-
-
Save FredrikOseberg/9c994790c6dd76f3d1d9dffac59ef2bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActionProvider { | |
// The action provider receives createChatBotMessage which you can use to define the bots response, and | |
// the setState function that allows for manipulating the bots internal state. | |
constructor(createChatBotMessage, setStateFunc, createClientMessage) { | |
this.createChatBotMessage = createChatBotMessage; | |
this.setState = setStateFunc; | |
this.createClientMessage = createClientMessage | |
} | |
handleMessageParser = () => { | |
const messages = this.createChatBotMessage( | |
"The message parser controls how the bot reads input and decides which action to invoke.", | |
{ widget: "messageParser", withAvatar: true } | |
); | |
this.addMessageToBotState(messages); | |
}; | |
handleDefault = () => { | |
const message = this.createChatBotMessage("How can I help?", { | |
withAvatar: true, | |
}); | |
this.addMessageToBotState(message) | |
}; | |
addMessageToBotState = (messages) => { | |
if (Array.isArray(messages)) { | |
this.setState((state) => ({ | |
...state, | |
messages: [...state.messages, ...messages], | |
})); | |
} else { | |
this.setState((state) => ({ | |
...state, | |
messages: [...state.messages, messages], | |
})); | |
} | |
}; | |
} | |
export default ActionProvider; |
How to handle a validations for suppose i have a emaild and i want to check that it is valid or not , so how can we deal with it
is there a way to handle several updateChatbotState in a function ?........it glitches whenever I try to update after createChatBotMessage.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it. Now, it works, Thank You