-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_function.py
84 lines (62 loc) · 2.27 KB
/
lambda_function.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
import logging
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session, request
from search_wirelesschecker import search_wirelesschecker, search_busy_building, search_most_connection
app = Flask(__name__)
ask = Ask(app, '/')
logging.getLogger("flask_ask").setLevel(logging.DEBUG)
def lambda_handler(event, _context):
return ask.run_aws_lambda(event)
@ask.launch
def welcome():
welcome_msg = render_template('welcome')
return question(welcome_msg)
@ask.intent("AMAZON.HelpIntent")
def help():
help_msg = render_template('help')
return question(help_msg)
@ask.intent("AMAZON.FallbackIntent")
def fallback():
fallback_msg = render_template('error-not-understand')
return question(fallback_msg)
@ask.intent('AMAZON.CancelIntent')
@ask.intent("AMAZON.StopIntent")
def stop():
goodbye_msg = render_template('goodbye')
return statement(goodbye_msg)
@ask.intent('AnswerBuildingBusy')
def answer_busybuildingname():
results = search_busy_building()
answer_busy_msg = render_template("answer-busy-results", result = results)
return question(answer_busy_msg)
@ask.intent('AnswerMostlyConnection')
def answer_mostly_connection():
results = search_most_connection()
answer_busy_msg = render_template("answer-mostly-connection", result = results)
return question(answer_busy_msg)
@ask.intent('AnswerBuildingNameIntent')
def answer_buildingname(buildingname):
session.attributes['buildingname'] = buildingname
confirm_msg = render_template("confirm-clue",
which_name="building name",
name=buildingname
)
return question(confirm_msg)
@ask.intent('StartIntent')
def start_search():
if 'buildingname' in session.attributes.keys():
buildingname = session.attributes['buildingname']
else:
buildingname = None
results = search_wirelesschecker(buildingname)
print(results)
if len(results) == 0:
answer_msg = render_template("answer-noresults")
else:
answer_msg = render_template("answer-results", result=results[0])
# clear all variables
if 'buildingname' in session.attributes.keys():
session.attributes.pop('buildingname')
return question(answer_msg)
if __name__ == '__main__':
app.run(debug=True)