-
Notifications
You must be signed in to change notification settings - Fork 0
/
alice.py
45 lines (36 loc) · 1.08 KB
/
alice.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
from flask import Flask, request
import logging
import json
import random
from requests import post
app = Flask(__name__)
logging.basicConfig(level=logging.INFO)
@app.route('/post', methods=['POST'])
def main():
logging.info('Request: %r', request.json)
response = {
'session': request.json['session'],
'version': request.json['version'],
'response': {
'end_session': False
}
}
handle_dialog(response, request.json)
logging.info('Response: %r', response)
return json.dumps(response)
def handle_dialog(res, req):
if req['session']['new']:
res['response']['text'] = 'Привет! Введи <login> <password>'
args = req["original_utterance"].strip()
login, passw = args
print(login, passw)
response = post('http://localhost:5000/api/auth',
data={"login": login, "password": passw}).json()
print(response)
if response["token"]:
res["text"] = "Успешно"
else:
res["text"] = response["error"]
return
if __name__ == '__main__':
app.run()