Skip to content

Instantly share code, notes, and snippets.

@FredrikOseberg
Last active June 22, 2021 15:48
Show Gist options
  • Save FredrikOseberg/9c994790c6dd76f3d1d9dffac59ef2bb to your computer and use it in GitHub Desktop.
Save FredrikOseberg/9c994790c6dd76f3d1d9dffac59ef2bb to your computer and use it in GitHub Desktop.
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;
@susmitha01
Copy link

susmitha01 commented May 20, 2021

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

@VSevagen
Copy link

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