"""
작업 결과 알림 모듈.
실제 카카오톡 연동은 토큰/템플릿 등이 필요하므로,
여기서는 인터페이스를 정의하고 기본 구현은 로그 출력으로 둔다.
사용자는 KakaoTalkNotifier 를 확장하거나 구현체를 교체하면 된다.
"""
from __future__ import annotations
import abc
import logging
from typing import Any, Dict, Optional
logger = logging.getLogger("task_scheduler_mcp.notification")
class Notifier(abc.ABC):
"""알림 발송 공통 인터페이스."""
@abc.abstractmethod
def notify(self, target: str, message: str, extra: Optional[Dict[str, Any]] = None) -> None:
raise NotImplementedError
class LogNotifier(Notifier):
"""기본 구현: 로그 출력."""
def notify(self, target: str, message: str, extra: Optional[Dict[str, Any]] = None) -> None:
logger.info("Notify target=%s message=%s extra=%s", target, message, extra)
class KakaoTalkNotifier(Notifier):
"""
카카오톡 알림 전송용 골격.
실제 구현 시:
- REST API 토큰/앱 키를 환경변수로 받고
- 카카오톡 메시지 전송 API 호출을 구현하면 된다.
"""
def __init__(self, access_token: str | None = None):
self.access_token = access_token
def notify(self, target: str, message: str, extra: Optional[Dict[str, Any]] = None) -> None:
# TODO: 카카오톡 REST API 연동 구현
logger.info(
"[KakaoTalk MOCK] target=%s message=%s extra=%s token=%s",
target,
message,
extra,
"set" if self.access_token else "missing",
)
def get_default_notifier() -> Notifier:
"""
환경에 따라 기본 Notifier를 선택하는 팩토리.
일단은 로그 기반으로 두고, 추후 Kakao 연동을 쉽게 교체할 수 있게 구성.
"""
# 예: 환경 변수로 'NOTIFIER=KAKAO' 설정 시 KakaoTalkNotifier 선택 가능하게 확장
return LogNotifier()