-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
331 additions
and
79 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,52 @@ | ||
from ability_000 import ScheduleParser | ||
from reactions import * | ||
import logging | ||
|
||
logging.getLogger().setLevel(logging.DEBUG) | ||
|
||
def handler(event, context): | ||
""" | ||
Entry-point for Serverless Function. | ||
:param event: request payload. | ||
:param context: information about current execution context. | ||
:return: response to be serialized as JSON. | ||
""" | ||
|
||
def handler(event, context): | ||
logging.debug("start") | ||
try: | ||
if 'session' in event and 'message_id' in event['session']: | ||
|
||
match event['session']['message_id']: | ||
# Назовите Станцию Отправления | ||
case 0: | ||
|
||
text = 'Назовите Станцию Отправления:' | ||
end_session = 'false' | ||
session_dict = None | ||
|
||
# Назовите Станцию Прибытия | ||
case 1: | ||
|
||
if 'request' in event and \ | ||
'original_utterance' in event['request'] \ | ||
and len(event['request']['original_utterance']) > 0: | ||
|
||
text = 'Назовите Станцию Прибытия:' | ||
end_session = 'false' | ||
session_dict = {'st1': event['request']['original_utterance']} | ||
|
||
# Возврат расписания | ||
case 2: | ||
|
||
if 'request' in event and \ | ||
'original_utterance' in event['request'] \ | ||
and len(event['request']['original_utterance']) > 0: | ||
|
||
if 'state' in event and \ | ||
'session' in event['state'] and \ | ||
'st1' in event['state']['session']: | ||
st1 = event['state']['session']['st1'] | ||
else: | ||
raise 'State error' | ||
|
||
st2 = event['request']['original_utterance'] | ||
|
||
try: | ||
schedule = ScheduleParser(str(st1), str(st2)).parse() | ||
|
||
if schedule["error"] is None: | ||
text = 'Ближайшее отправление: ' + schedule['r1'][0] + ' с прибытием ' + schedule['r1'][1] + \ | ||
'. Второе ближайшее отправление: ' + schedule['r2'][0] + ' с прибытием ' + schedule['r2'][1] + \ | ||
'. Третье ближайшее отправление: ' + schedule['r3'][0] + ' с прибытием ' + schedule['r3'][1] | ||
end_session = 'true' | ||
session_dict = None | ||
else: | ||
text = schedule['error'] | ||
end_session = 'true' | ||
session_dict = None | ||
except Exception as e: | ||
text = str(e) | ||
end_session = 'true' | ||
session_dict = None | ||
if 'request' in event and \ | ||
'command' in event['request']: | ||
|
||
logging.debug("command in request; matching...") | ||
match event['request']['command']: | ||
case "": | ||
return answer_on_init(event, context) | ||
case "помощь": | ||
return answer_on_help(event, context) | ||
case "что ты умеешь": | ||
return answer_on_what(event, context) | ||
case _: | ||
logging.debug("not _ or h or w; searching for st1...") | ||
if 'state' in event and \ | ||
'session' in event['state'] and \ | ||
'st1' in event['state']['session']: | ||
logging.debug("st1 in state") | ||
return answer_on_st2(event, context) | ||
else: | ||
logging.debug("st1 not in state") | ||
return answer_on_st1(event, context) | ||
|
||
except Exception as e: | ||
text = str(e) | ||
end_session = 'true' | ||
session_dict = None | ||
|
||
return { | ||
'version': event['version'], | ||
'session': event['session'], | ||
'response': { | ||
# Respond with the original request or welcome the user if this is the beginning of the dialog and the request has not yet been made. | ||
'text': text, | ||
# Don't finish the session after this response. | ||
'end_session': end_session | ||
}, | ||
'session_state': session_dict | ||
} | ||
logging.debug(e) | ||
return { | ||
'version': event['version'], | ||
'session': event['session'], | ||
'response': { | ||
'text': e, | ||
'end_session': 'true' | ||
}, | ||
} | ||
|
||
else: | ||
logging.debug("idk") | ||
return { | ||
'version': event['version'], | ||
'session': event['session'], | ||
'response': { | ||
'text': "idk", | ||
'end_session': 'true' | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from ability_000 import ScheduleParser | ||
|
||
|
||
def handler(event, context): | ||
""" | ||
Entry-point for Serverless Function. | ||
:param event: request payload. | ||
:param context: information about current execution context. | ||
:return: response to be serialized as JSON. | ||
""" | ||
|
||
try: | ||
if 'session' in event and 'message_id' in event['session']: | ||
|
||
match event['session']['message_id']: | ||
# Назовите Станцию Отправления | ||
case 0: | ||
|
||
text = 'Назовите Станцию Отправления:' | ||
end_session = 'false' | ||
session_dict = None | ||
|
||
# Назовите Станцию Прибытия | ||
case 1: | ||
|
||
if 'request' in event and \ | ||
'original_utterance' in event['request'] \ | ||
and len(event['request']['original_utterance']) > 0: | ||
|
||
text = 'Назовите Станцию Прибытия:' | ||
end_session = 'false' | ||
session_dict = {'st1': event['request']['original_utterance']} | ||
|
||
# Возврат расписания | ||
case 2: | ||
|
||
if 'request' in event and \ | ||
'original_utterance' in event['request'] \ | ||
and len(event['request']['original_utterance']) > 0: | ||
|
||
if 'state' in event and \ | ||
'session' in event['state'] and \ | ||
'st1' in event['state']['session']: | ||
st1 = event['state']['session']['st1'] | ||
else: | ||
raise 'State error' | ||
|
||
st2 = event['request']['original_utterance'] | ||
|
||
try: | ||
schedule = ScheduleParser(str(st1), str(st2)).parse() | ||
|
||
if schedule["error"] is None: | ||
text = 'Ближайшее отправление: ' + schedule['r1'][0] + ' с прибытием ' + schedule['r1'][1] + \ | ||
'. Второе ближайшее отправление: ' + schedule['r2'][0] + ' с прибытием ' + schedule['r2'][1] + \ | ||
'. Третье ближайшее отправление: ' + schedule['r3'][0] + ' с прибытием ' + schedule['r3'][1] | ||
end_session = 'true' | ||
session_dict = None | ||
else: | ||
text = schedule['error'] | ||
end_session = 'true' | ||
session_dict = None | ||
except Exception as e: | ||
text = str(e) | ||
end_session = 'true' | ||
session_dict = None | ||
|
||
except Exception as e: | ||
text = str(e) | ||
end_session = 'true' | ||
session_dict = None | ||
|
||
return { | ||
'version': event['version'], | ||
'session': event['session'], | ||
'response': { | ||
# Respond with the original request or welcome the user if this is the beginning of the dialog and the request has not yet been made. | ||
'text': text, | ||
# Don't finish the session after this response. | ||
'end_session': end_session | ||
}, | ||
'session_state': session_dict | ||
} |
Oops, something went wrong.