-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
55 lines (41 loc) · 1.4 KB
/
app.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
from flask import Flask
from flask import render_template
from flask import request
from flask import Response
from flask import send_from_directory
import boto3
import os
app = Flask(__name__)
app.debug = True
aws_access_key_id = os.environ["aws_access_key_id"]
aws_secret_access_key = os.environ["aws_secret_access_key"]
aws_region = os.environ["defaultRegion"]
aws_queue_url = os.environ["alexa_queue_url"]
def sendToQueue(txt):
sqs = boto3.resource('sqs', region_name=aws_region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
queue = sqs.Queue(aws_queue_url)
response = queue.send_message(MessageBody=txt)
return response.get('MessageId')
def sendMessage(txt):
txt = txt.strip()
txt = txt[:500]
if (not txt):
return "No text entered!"
messageId = sendToQueue(txt)
return "Thank you."
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico', mimetype='image/vnd.microsoft.icon')
@app.route('/', methods=['GET'])
def hello():
return render_template('home.html')
@app.route('/speak', methods=['POST'])
def speak():
user_message = sendMessage(request.form['txt'])
return render_template('thankyou.html', user_message = user_message)
@app.route("/sms", methods=['POST'])
def sms():
user_message = sendMessage(request.form['Body'])
return ""
if __name__ == "__main__":
app.run(debug=True, use_reloader=True)