-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
38 lines (23 loc) · 832 Bytes
/
server.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
from flask import Flask, request, render_template, redirect, flash
import os
from helpers import send_message, add_msg_to_db
from model import connect_to_db
app = Flask(__name__)
app.secret_key = "SECRET"
@app.route('/')
def show_text_form():
"""Show user text form"""
return render_template("index.html")
@app.route('/send', methods=["POST"])
def send_twilio_message():
"""Send user's message, return homepage with success message"""
phone = request.form.get("phone")
body = request.form.get("body")
message = send_message(phone, body)
add_msg_to_db(message.sid, phone, body)
flash("You have successfully sent your message!")
return redirect("/")
if __name__ == "__main__":
connect_to_db(app)
PORT = int(os.environ.get("PORT", 5000))
app.run(host="0.0.0.0", port=PORT)