-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsm.py
217 lines (151 loc) · 5.46 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from transitions.extensions import GraphMachine
from utils import send_text_message, send_carousel_message, send_button_message, send_image_message
from bs4 import BeautifulSoup
import requests
from linebot.models import (ImageCarouselColumn, URITemplateAction, MessageTemplateAction,MessageEvent, TextMessage, TextSendMessage,ImageSendMessage,LocationSendMessage)
from linebot import LineBotApi, WebhookParser
from linebot.exceptions import InvalidSignatureError
import pandas as pd
import random
import os
import sys
from flask import Flask, jsonify, request, abort, send_file
from dotenv import load_dotenv
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', None)
# global variable
hour = 0
minute = 0
part = ''
people = 0
line_bot_api = LineBotApi(channel_access_token)
class TocMachine(GraphMachine):
def __init__(self, **machine_configs):
self.machine = GraphMachine(model=self, **machine_configs)
# user start
def is_going_to_choose(self, event):
text = event.message.text
if text == '蟹堡王':
return True
return False
def on_enter_choose(self, event):
title = '歡迎光臨蟹堡王'
text = '你可以 訂位/查看菜單/查看餐廳位置/餐廳人員介紹'
btn = [
MessageTemplateAction(
label = '訂位',
text ='訂位'
),
MessageTemplateAction(
label = '查看菜單',
text = '查看菜單'
),
MessageTemplateAction(
label = '查看餐廳位置',
text = '查看餐廳位置'
),
MessageTemplateAction(
label = '餐廳人員介紹',
text = '餐廳人員介紹'
),
]
url = 'https://img.onl/pVmoZS'
send_button_message(event.reply_token, title, text, btn, url)
def is_going_to_menu(self, event):
text = event.message.text
if text == '查看菜單':
return True
return False
def on_enter_menu(self, event):
message = [
ImageSendMessage(
original_content_url='https://img.onl/hVRwPJ',
preview_image_url='https://img.onl/hVRwPJ'
),
TextSendMessage(
text = '輸入任意值以返回'
),
]
line_bot_api.reply_message(event.reply_token,message)
def is_going_to_location(self, event):
text = event.message.text
if text == '查看餐廳位置':
return True
return False
def on_enter_location(self, event):
message= [
LocationSendMessage(
title='my location',
address='蟹堡王',
latitude=32.6948660,
longitude=-162.0703120),
TextSendMessage(
text = '輸入任意值以返回'
),
]
line_bot_api.reply_message(event.reply_token,message)
def is_going_to_reserve_people(self, event):
text = event.message.text
if text == '訂位':
return True
return False
def on_enter_reserve_people(self, event):
send_text_message(event.reply_token, '請輸入人數(1~10)')
def is_going_to_reserve_time(self, event):
global people
text = event.message.text
if text.lower().isnumeric():
people = int(text)
if people >=1 and people <=10:
return True
return False
def on_enter_reserve_time(self, event):
send_text_message(event.reply_token, '請輸入時間(格式xx:xx)')
def is_going_to_reserve_result(self, event):
global hour
global minute
text = event.message.text
time = text.split(':')
if time[0].lower().isnumeric():
hour = int(time[0])
else:
return False
if time[1].lower().isnumeric():
minute = int(time[1])
else:
return False
if hour>=0 and hour <24 and minute>=0 and minute <60:
return True
return False
def on_enter_reserve_result(self, event):
global x
x=random.randint(0,1)
if x == 0:
message = [
ImageSendMessage(
original_content_url='https://img.onl/q4QIHO',
preview_image_url='https://img.onl/q4QIHO'
),
TextSendMessage(
text = '輸入任意值以返回'
),
]
else:
message = [
ImageSendMessage(
original_content_url='https://img.onl/rROg7',
preview_image_url='https://img.onl/rROg7'
),
TextSendMessage(
text = '輸入任意值以返回'
),
]
line_bot_api.reply_message(event.reply_token,message)
def is_going_to_employee(self, event):
text = event.message.text
if text == '餐廳人員介紹':
return True
return False
def on_enter_employee(self, event):
send_text_message(event.reply_token, '輸入任意值以返回')
def go_back(self, event):
return True