Add web_app.py
This commit is contained in:
parent
0ae01fdfc3
commit
3e1c7fd0b0
|
@ -0,0 +1,21 @@
|
||||||
|
from flask import Flask, request, jsonify
|
||||||
|
from irc_bot import bot
|
||||||
|
from config import API_TOKEN
|
||||||
|
|
||||||
|
appV3 = Flask(__name__)
|
||||||
|
|
||||||
|
# Handle incoming chatbox messages
|
||||||
|
@appV3.route("/incoming", methods=["POST"])
|
||||||
|
def incoming():
|
||||||
|
auth_header = request.headers.get("Authorization", "")
|
||||||
|
if auth_header != f"Bearer {API_TOKEN}":
|
||||||
|
return jsonify({"error": "Unauthorized"}), 401
|
||||||
|
|
||||||
|
data = request.get_json()
|
||||||
|
user = data.get("username")
|
||||||
|
text = data.get("text")
|
||||||
|
if not user or not text:
|
||||||
|
return jsonify({"error": "Invalid data"}), 400
|
||||||
|
|
||||||
|
bot.send_to_channel(f"[CHATBOX] {user}: {text}")
|
||||||
|
return jsonify({"success": True}), 200
|
Loading…
Reference in New Issue