Skip to content

Commit

Permalink
Merge pull request #2 from mariacarlinahernandez/master
Browse files Browse the repository at this point in the history
Request glucose level entry via sms feature
  • Loading branch information
superdiana authored Aug 4, 2020
2 parents d1e0ff0 + 1cc6989 commit 23e9ae9
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion notifier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nexmo
import json
import json, ast
import os
from flask import Flask, request, jsonify, render_template, session, redirect, url_for
from flask_cors import CORS
Expand Down Expand Up @@ -271,10 +271,69 @@ def call_glucose_alert(to, glucose):
return False


def sms_request_glucose_level(args, glucose):
global client

args = ast.literal_eval(json.dumps(args))

# Parse incoming values
keyword = args['keyword'][0]
to = args["msisdn"][0]
response = None

if keyword == "NIGHTSCOUT":
# "msg" stores the response to be sent\
msg = "Hey, the latest blood glucose level entry: {glucose}".format(glucose=glucose)

response = requests.post(
'https://api.nexmo.com/v0.1/messages',
auth=HTTPBasicAuth(os.getenv("NEXMO_API_KEY"),
os.getenv("NEXMO_API_SECRET")),
headers={
"Content-Type": "application/json",
"Accept": "application/json"
},
json={
"from": {
"type": "sms",
"number": os.getenv('NEXMO_NUMBER')
},
"to": {
"type": "sms",
"number": to
},
"message": {
"content": {
"type": "text",
"text": msg
}
}
}).json()

if response is not None and "message_uuid" in response:
return True
else:
return False


@app.route('/webhooks/inbound-messages', methods=["POST"])
def inbound_sms():
args = dict(request.form)

if args.get('status'):
return args['status']

sms_request_glucose_level(args, glucose)

return "Message Received"


@app.route('/webhooks/events', methods=["POST", "GET"])
def events():
global client
global active_scouts
global glucose

req = request.get_json()
# Create scouts instance
nightscouts = scouts()
Expand Down

0 comments on commit 23e9ae9

Please sign in to comment.