forked from winonecheng/TOC-Project-2019
-
Notifications
You must be signed in to change notification settings - Fork 96
/
fsm.py
36 lines (25 loc) · 993 Bytes
/
fsm.py
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
from transitions.extensions import GraphMachine
from utils import send_text_message
class TocMachine(GraphMachine):
def __init__(self, **machine_configs):
self.machine = GraphMachine(model=self, **machine_configs)
def is_going_to_state1(self, event):
text = event.message.text
return text.lower() == "go to state1"
def is_going_to_state2(self, event):
text = event.message.text
return text.lower() == "go to state2"
def on_enter_state1(self, event):
print("I'm entering state1")
reply_token = event.reply_token
send_text_message(reply_token, "Trigger state1")
self.go_back()
def on_exit_state1(self):
print("Leaving state1")
def on_enter_state2(self, event):
print("I'm entering state2")
reply_token = event.reply_token
send_text_message(reply_token, "Trigger state2")
self.go_back()
def on_exit_state2(self):
print("Leaving state2")