33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
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
|