-
Notifications
You must be signed in to change notification settings - Fork 113
/
fsm.py
43 lines (32 loc) · 1.22 KB
/
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
37
38
39
40
41
42
43
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):
if event.get("message") and event['message'].get("text"):
text = event['message']['text']
return text.lower() == 'go to state1'
return False
def is_going_to_state2(self, event):
if event.get("message") and event['message'].get("text"):
text = event['message']['text']
return text.lower() == 'go to state2'
return False
def on_enter_state1(self, event):
print("I'm entering state1")
sender_id = event['sender']['id']
responese = send_text_message(sender_id, "I'm entering state1")
self.go_back()
def on_exit_state1(self):
print('Leaving state1')
def on_enter_state2(self, event):
print("I'm entering state2")
sender_id = event['sender']['id']
send_text_message(sender_id, "I'm entering state2")
self.go_back()
def on_exit_state2(self):
print('Leaving state2')