From 0046ea53d8d7e6ff7bd6948339aab70bc7a64e8c Mon Sep 17 00:00:00 2001 From: jim7207 Date: Wed, 13 Sep 2023 20:43:29 -0500 Subject: [PATCH 01/15] Update app.py --- app.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app.py b/app.py index d82c51f0d..fef892573 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,26 @@ +import json from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' + +def save_to_json(): + with open('responses.json', 'w') as file: + json.dump(responses, file) + +@app.route('/webhook', methods=['POST']) +def webhook(): + data = request.json + responses.append(data) + save_to_json() + return jsonify(success=True), 200 + +@app.route('/get_responses', methods=['GET']) +def get_responses(): + with open('responses.json', 'r') as file: + data = json.load(file) + return jsonify(data), 200 + + From 13f3be30d0f154185579b6326627e892cac127ff Mon Sep 17 00:00:00 2001 From: jim7207 Date: Thu, 14 Sep 2023 06:20:08 -0500 Subject: [PATCH 02/15] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index fef892573..e51a9324e 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ import json -from flask import Flask +from flask import Flask,request, jsonify app = Flask(__name__) @app.route('/') From c4e06534a05b74de7e03a9958c75a6322c7778e9 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Thu, 14 Sep 2023 06:25:32 -0500 Subject: [PATCH 03/15] Update app.py --- app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.py b/app.py index e51a9324e..57df7c6a0 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,8 @@ import json from flask import Flask,request, jsonify + +responses = [] + app = Flask(__name__) @app.route('/') From 0f692d59c90c9e13921ace400b739d81b370d371 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Thu, 14 Sep 2023 06:44:41 -0500 Subject: [PATCH 04/15] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 57df7c6a0..6a3254e48 100644 --- a/app.py +++ b/app.py @@ -16,7 +16,7 @@ def save_to_json(): @app.route('/webhook', methods=['POST']) def webhook(): data = request.json - responses.append(data) + responses.append(data, content_type='application/json') save_to_json() return jsonify(success=True), 200 From f06c11f6d8625429500ed70d7546c8299277fc35 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Thu, 14 Sep 2023 06:50:37 -0500 Subject: [PATCH 05/15] Update app.py --- app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 6a3254e48..30a41f853 100644 --- a/app.py +++ b/app.py @@ -16,7 +16,8 @@ def save_to_json(): @app.route('/webhook', methods=['POST']) def webhook(): data = request.json - responses.append(data, content_type='application/json') + message_body = request.form.get('Body') + responses.append(message_body) save_to_json() return jsonify(success=True), 200 From ec58d2f2814fa4d54ed083825a87293dc9450a7a Mon Sep 17 00:00:00 2001 From: jim7207 Date: Thu, 14 Sep 2023 20:52:38 -0500 Subject: [PATCH 06/15] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 30a41f853..d3e2e4446 100644 --- a/app.py +++ b/app.py @@ -15,8 +15,8 @@ def save_to_json(): @app.route('/webhook', methods=['POST']) def webhook(): - data = request.json message_body = request.form.get('Body') + print(message_body) responses.append(message_body) save_to_json() return jsonify(success=True), 200 From 785707be0ff98c071c95d983393eef126950fd48 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Thu, 14 Sep 2023 22:19:32 -0500 Subject: [PATCH 07/15] Update app.py --- app.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index d3e2e4446..c7871f6fd 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ import json from flask import Flask,request, jsonify +from twilio.twiml.messaging_response import MessagingResponse responses = [] @@ -16,10 +17,14 @@ def save_to_json(): @app.route('/webhook', methods=['POST']) def webhook(): message_body = request.form.get('Body') - print(message_body) responses.append(message_body) save_to_json() - return jsonify(success=True), 200 + + # Start our TwiML response + resp = MessagingResponse() + resp.message("Hi!") + + return str(resp) @app.route('/get_responses', methods=['GET']) def get_responses(): From fadeabeb220e3b528390ffce1da60c19dfa7ee11 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Thu, 14 Sep 2023 22:23:49 -0500 Subject: [PATCH 08/15] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 147ddd086..fe9327a55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Flask Gunicorn +Twilio From b415634709de176a796a8a4bb79dffe8e8f923d9 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Fri, 15 Sep 2023 14:26:58 -0500 Subject: [PATCH 09/15] Update app.py --- app.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index c7871f6fd..3f2a9b274 100644 --- a/app.py +++ b/app.py @@ -22,7 +22,10 @@ def webhook(): # Start our TwiML response resp = MessagingResponse() - resp.message("Hi!") + if message_body == 1 or message_body == 2 + resp.message("Got it!") + else: + resp.message("Please send 1 or 2. I was unable to record your message.") return str(resp) From 98da6d5414242c45c383feda7b1b6642e58f7431 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Fri, 15 Sep 2023 14:29:10 -0500 Subject: [PATCH 10/15] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 3f2a9b274..215ffa0fe 100644 --- a/app.py +++ b/app.py @@ -22,7 +22,7 @@ def webhook(): # Start our TwiML response resp = MessagingResponse() - if message_body == 1 or message_body == 2 + if message_body == 1 or message_body == 2: resp.message("Got it!") else: resp.message("Please send 1 or 2. I was unable to record your message.") From b89d0204c730ff8001078d50c3b49a2e2ca538f9 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Fri, 15 Sep 2023 14:30:37 -0500 Subject: [PATCH 11/15] Update app.py --- app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 215ffa0fe..7ad27fac7 100644 --- a/app.py +++ b/app.py @@ -22,10 +22,10 @@ def webhook(): # Start our TwiML response resp = MessagingResponse() - if message_body == 1 or message_body == 2: - resp.message("Got it!") - else: - resp.message("Please send 1 or 2. I was unable to record your message.") + if message_body == 1 or message_body == 2: + resp.message("Got it!") + else: + resp.message("Please send 1 or 2. I was unable to record your message.") return str(resp) From 0be2da4226b19166581e22759bce950f86617b32 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Fri, 15 Sep 2023 14:56:03 -0500 Subject: [PATCH 12/15] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 7ad27fac7..4b8ea026e 100644 --- a/app.py +++ b/app.py @@ -22,7 +22,7 @@ def webhook(): # Start our TwiML response resp = MessagingResponse() - if message_body == 1 or message_body == 2: + if message_body == "1" or message_body == "2": resp.message("Got it!") else: resp.message("Please send 1 or 2. I was unable to record your message.") From 39fb8a9e507aefccd6970c1e6863b02531b9bdb3 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Fri, 22 Sep 2023 06:56:17 -0500 Subject: [PATCH 13/15] first first commit --- responses.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 responses.json diff --git a/responses.json b/responses.json new file mode 100644 index 000000000..d9a488831 --- /dev/null +++ b/responses.json @@ -0,0 +1 @@ +[null, "2"] \ No newline at end of file From 41f2b5d4ad301c1ac970819af404bf5ff4e16dcf Mon Sep 17 00:00:00 2001 From: jim7207 Date: Fri, 22 Sep 2023 07:19:38 -0500 Subject: [PATCH 14/15] remove json storage --- app.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app.py b/app.py index 4b8ea026e..4e51fe991 100644 --- a/app.py +++ b/app.py @@ -10,15 +10,10 @@ def hello_world(): return 'Hello, World!' -def save_to_json(): - with open('responses.json', 'w') as file: - json.dump(responses, file) - @app.route('/webhook', methods=['POST']) def webhook(): message_body = request.form.get('Body') responses.append(message_body) - save_to_json() # Start our TwiML response resp = MessagingResponse() @@ -29,10 +24,5 @@ def webhook(): return str(resp) -@app.route('/get_responses', methods=['GET']) -def get_responses(): - with open('responses.json', 'r') as file: - data = json.load(file) - return jsonify(data), 200 From ffa14bda28d6845908b6e69efa0ef5ef5300f0a5 Mon Sep 17 00:00:00 2001 From: jim7207 Date: Fri, 22 Sep 2023 08:13:12 -0500 Subject: [PATCH 15/15] send Jim valid responses via SMS --- app.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 4e51fe991..b11b8a0c9 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,17 @@ import json from flask import Flask,request, jsonify +import os from twilio.twiml.messaging_response import MessagingResponse +TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID') +TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN') +TWILIO_PHONE_NUMBER = os.environ.get('TWILIO_PHONE_NUMBER') +TARGET_PHONE_NUMBER = os.environ.get('TARGET_PHONE_NUMBER') +JIM_PHONE_NUMBER = os.environ.get('JIM_PHONE_NUMBER') + +from twilio.rest import Client + + responses = [] app = Flask(__name__) @@ -18,11 +28,20 @@ def webhook(): # Start our TwiML response resp = MessagingResponse() if message_body == "1" or message_body == "2": - resp.message("Got it!") + resp.message("Got it!") + send_sms(message_body) else: resp.message("Please send 1 or 2. I was unable to record your message.") return str(resp) +def send_sms(message_body): + client = Client(TWILIO_ACCOUNT_SID,TWILIO_AUTH_TOKEN) + message = client.messages.create( + body="Got a response from James: " + message_body, + from_=TWILIO_PHONE_NUMBER, + to=JIM_PHONE_NUMBER + ) + print(f"SMS sent to dad with message ID: {message.sid}")