Created
October 18, 2017 17:39
-
-
Save mmchugh/889831df05752fef925923542939e2ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, jsonify, request | |
from sparkpost import SparkPost | |
app = Flask(__name__) | |
SPARKPOST_KEY = '<SPARKPOST_API_KEY>' | |
VALIDATION_CODE = '<OPEN_CHANNEL_PLATFORM_VALIDATION>' | |
@app.route('/message/push', methods=['POST']) | |
def message(): | |
payload = request.get_json(force=True, silent=True) | |
sp = SparkPost(SPARKPOST_KEY) | |
for content in payload["values"]: | |
if content["payload"].get("title"): | |
subject = content["payload"]['title'] | |
else: | |
subject = "No subject" | |
sp.transmissions.send( | |
recipients=[content["target"]["address"]], | |
text=content["payload"]["alert"], | |
html='<p>{}</p>'.format(content["payload"]["alert"]), | |
from_email="[email protected]", | |
subject=subject | |
) | |
return jsonify({'success': True}) | |
@app.route('/message/validate', methods=['GET']) | |
def validate(): | |
return jsonify( | |
{'confirmation_code': VALIDATION_CODE} | |
) | |
if __name__ == '__main__': | |
app.run(port='8801') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment