-
Notifications
You must be signed in to change notification settings - Fork 4
/
ActionProvider.js
44 lines (34 loc) · 1.34 KB
/
ActionProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class ActionProvider {
constructor(createChatBotMessage, setStateFunc) {
this.createChatBotMessage = createChatBotMessage;
this.setState = setStateFunc;
}
greet() {
const greetingMessage = this.createChatBotMessage("Hello, Greetings from Bot.")
this.updateChatbotState(greetingMessage)
}
noMessage(){
const noMessage = this.createChatBotMessage("I Can't Understand That")
this.updateChatbotState(noMessage)
}
loveMessage(){
const greetingMessage = this.createChatBotMessage("Love You Too!")
this.updateChatbotState(greetingMessage)
};
handleAdmissionsList = () =>{
const message = this.createChatBotMessage(
"Fantastic",
{
widget: "Admissions",
}
);
this.updateChatbotState(message);
}
updateChatbotState(message) {
// NOTE: This function is set in the constructor, and is passed in // from the top level Chatbot component. The setState function here // actually manipulates the top level state of the Chatbot, so it's // important that we make sure that we preserve the previous state.
this.setState(prevState => ({
...prevState, messages: [...prevState.messages, message]
}));
}
}
export default ActionProvider