노션에서 이벤트 발생 시 웹훅을 수신하고, 해당 이벤트 페이지에 대해 메시지를 보내주는 기능을 구현
This commit is contained in:
32
app/routes/webhook/notion.py
Normal file
32
app/routes/webhook/notion.py
Normal file
@ -0,0 +1,32 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
from lib.notion_api import handle_notion_event
|
||||
from lib.send_message import send_message_to_mattermost
|
||||
import logging
|
||||
|
||||
notion_webhook_bp = Blueprint("notion_webhook", __name__)
|
||||
|
||||
@notion_webhook_bp.route("/webhook/notion", methods=["POST"])
|
||||
def receive_notion_webhook():
|
||||
try:
|
||||
event = request.get_json()
|
||||
if not event:
|
||||
logging.warning("빈 요청 수신됨")
|
||||
return jsonify({"error": "Invalid JSON"}), 400
|
||||
|
||||
# 메시지 생성
|
||||
message = handle_notion_event(event)
|
||||
if not message:
|
||||
logging.warning("처리 가능한 메시지 없음")
|
||||
return jsonify({"status": "ignored"}), 200
|
||||
|
||||
# Mattermost로 전송
|
||||
result = send_message_to_mattermost(message)
|
||||
if result:
|
||||
return jsonify({"status": "ok"}), 200
|
||||
else:
|
||||
logging.error("Mattermost 전송 실패")
|
||||
return jsonify({"error": "failed to send"}), 500
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("노션 웹훅 처리 중 예외 발생")
|
||||
return jsonify({"error": str(e)}), 500
|
||||
Reference in New Issue
Block a user