From 79a439d8ede02b4abed71243b2589620bcbc3e0f Mon Sep 17 00:00:00 2001 From: Mohammad Osama Khan Date: Thu, 22 Dec 2022 15:18:07 +0530 Subject: [PATCH] Create a simple webhook for flask application --- flask_webhook/server.py | 15 +++++++++++++++ flask_webhook/webhook.py | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 flask_webhook/server.py create mode 100644 flask_webhook/webhook.py diff --git a/flask_webhook/server.py b/flask_webhook/server.py new file mode 100644 index 0000000..3b81f99 --- /dev/null +++ b/flask_webhook/server.py @@ -0,0 +1,15 @@ +from flask import Flask, request, abort + +app = Flask(__name__) + + +@app.route('/webhook', methods=['POST']) +def webhook(): + if request.method == 'POST': + print(request.json) + return 'success', 200 + else: + abort(400) + +if __name__ == '__main__': + app.run() diff --git a/flask_webhook/webhook.py b/flask_webhook/webhook.py new file mode 100644 index 0000000..6bc097d --- /dev/null +++ b/flask_webhook/webhook.py @@ -0,0 +1,10 @@ +import requests +import json + +webhook_url = 'http://127.0.0.1:5000/webhook' + +data = { 'name': 'Request three', + 'Channel URL': 'test url3' } + +r = requests.post(webhook_url, data=json.dumps(data), headers={'Content-Type': 'application/json'}) +