-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapp.py
29 lines (22 loc) · 1.23 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
from flask import Flask
from flask import render_template
from flask import request, redirect
from twilio.rest import TwilioRestClient
app = Flask(__name__) # Creating the Flask app
client = TwilioRestClient ('TWILIO_ACCOUNT_SID = os.environ['TWILIO_ACCOUNT_SID']', 'TWILIO_AUTH_TOKEN = os.environ['TWILIO_AUTH_TOKEN']') # Paste in your AccountSID and AuthToken here
twilio_number = "+1234567890" # Replace with your Twilio number
@app.route("/") # When you go to top page of app, this is what it will execute
def main():
return render_template('form.html')
@app.route("/submit-form/", methods = ['POST'])
def submit_number():
number = request.form['number']
formatted_number = "+1" + number # Switch to your country code of choice
client.messages.create(to=formatted_number, from_ = twilio_number, body = "Message of your choice to text people.") # Replace body with your message of choice
return redirect('/messages/')
@app.route("/messages/")
def list_messages():
messages = client.messages.list(to=twilio_number)
return render_template('messages.html', messages = messages)
if __name__ == '__main__': # If we're executing this app from the command line
app.run("0.0.0.0", port = 3000, debug = True)