feat: add feature enable/disable flags for notification platforms

- Add MATTERMOST_ENABLED, TELEGRAM_ENABLED, SYNOLOGY_ENABLED, NOTION_ENABLED, GA4_ENABLED flags
- Skip disabled platforms in message_sender.py
- Comment out unused config variables in .env.sample
- Add .vscode settings for virtual environment debugging
This commit is contained in:
2025-12-31 10:20:17 +09:00
parent 4ff5dba4b1
commit dd9564a326
4 changed files with 79 additions and 23 deletions

View File

@ -37,7 +37,8 @@ AIR_STATION_NAMES=운정
WEATHER_STN_IDS=99 WEATHER_STN_IDS=99
# ===== Google Analytics 4 설정 ===== # ===== Google Analytics 4 설정 =====
# GA4 API를 통한 웹사이트 방문자 데이터 수집 # GA4 기능 사용 여부 (true/false)
GA4_ENABLED=false
GA4_API_TOKEN=your_ga4_api_token GA4_API_TOKEN=your_ga4_api_token
GA4_PROPERTY_ID=384052726 GA4_PROPERTY_ID=384052726
GA4_SERVICE_ACCOUNT_FILE=./conf/service-account-credentials.json GA4_SERVICE_ACCOUNT_FILE=./conf/service-account-credentials.json
@ -85,24 +86,34 @@ BOARD_CONTENT=게시판 기본 내용
BOARD_MB_ID=admin BOARD_MB_ID=admin
BOARD_NICKNAME=관리자 BOARD_NICKNAME=관리자
# ===== Mattermost 알림 설정 ===== # ===== 알림 서비스 설정 =====
# 메시지 알림 서비스 연동 # 각 플랫폼별로 ENABLED 설정이 false이거나 주석처리되어 있으면 해당 기능을 건너뜁니다.
# ----- Mattermost 알림 설정 -----
# 사용 여부 (true/false)
MATTERMOST_ENABLED=false
MATTERMOST_URL=https://mattermost.example.com MATTERMOST_URL=https://mattermost.example.com
MATTERMOST_TOKEN=your_bot_token MATTERMOST_TOKEN=your_bot_token
MATTERMOST_CHANNEL_ID=your_channel_id MATTERMOST_CHANNEL_ID=your_channel_id
MATTERMOST_WEBHOOK_URL=https://mattermost.example.com/hooks/xxx # MATTERMOST_WEBHOOK_URL=https://mattermost.example.com/hooks/xxx
# ===== Telegram 알림 설정 (선택) ===== # ----- Telegram 알림 설정 -----
TELEGRAM_BOT_TOKEN=your_telegram_bot_token # 사용 여부 (true/false)
TELEGRAM_CHAT_ID=your_chat_id TELEGRAM_ENABLED=false
# TELEGRAM_BOT_TOKEN=your_telegram_bot_token
# TELEGRAM_CHAT_ID=your_chat_id
# ===== Synology Chat 설정 (선택) ===== # ----- Synology Chat 설정 -----
SYNOLOGY_CHAT_URL=https://your-synology.com/webapi/entry.cgi # 사용 여부 (true/false)
SYNOLOGY_CHAT_TOKEN=your_token SYNOLOGY_ENABLED=false
# SYNOLOGY_CHAT_URL=https://your-synology.com/webapi/entry.cgi
# SYNOLOGY_CHAT_TOKEN=your_token
# ===== Notion API 설정 ===== # ===== Notion API 설정 =====
# Notion 웹훅 알림 연동 # Notion 웹훅 알림 연동
NOTION_API_SECRET=your_notion_api_secret # 사용 여부 (true/false)
NOTION_ENABLED=false
# NOTION_API_SECRET=your_notion_api_secret
# ===== Flask 설정 ===== # ===== Flask 설정 =====
FLASK_SECRET_KEY=your_secret_key_here FLASK_SECRET_KEY=your_secret_key_here

View File

@ -126,6 +126,7 @@ class Config:
# GA4 설정 # GA4 설정
self.ga4 = { self.ga4 = {
'enabled': self._get_bool('GA4_ENABLED', False),
'api_token': self._get_env('GA4_API_TOKEN', ''), 'api_token': self._get_env('GA4_API_TOKEN', ''),
'property_id': self._get_int('GA4_PROPERTY_ID', 0), 'property_id': self._get_int('GA4_PROPERTY_ID', 0),
'service_account_file': self._get_env('GA4_SERVICE_ACCOUNT_FILE', './conf/service-account-credentials.json'), 'service_account_file': self._get_env('GA4_SERVICE_ACCOUNT_FILE', './conf/service-account-credentials.json'),
@ -183,6 +184,7 @@ class Config:
# Mattermost 설정 # Mattermost 설정
self.mattermost = { self.mattermost = {
'enabled': self._get_bool('MATTERMOST_ENABLED', False),
'url': self._get_env('MATTERMOST_URL', ''), 'url': self._get_env('MATTERMOST_URL', ''),
'token': self._get_env('MATTERMOST_TOKEN', ''), 'token': self._get_env('MATTERMOST_TOKEN', ''),
'channel_id': self._get_env('MATTERMOST_CHANNEL_ID', ''), 'channel_id': self._get_env('MATTERMOST_CHANNEL_ID', ''),
@ -191,18 +193,21 @@ class Config:
# Telegram 설정 # Telegram 설정
self.telegram = { self.telegram = {
'enabled': self._get_bool('TELEGRAM_ENABLED', False),
'bot_token': self._get_env('TELEGRAM_BOT_TOKEN', ''), 'bot_token': self._get_env('TELEGRAM_BOT_TOKEN', ''),
'chat_id': self._get_env('TELEGRAM_CHAT_ID', ''), 'chat_id': self._get_env('TELEGRAM_CHAT_ID', ''),
} }
# Synology Chat 설정 # Synology Chat 설정
self.synology = { self.synology = {
'enabled': self._get_bool('SYNOLOGY_ENABLED', False),
'chat_url': self._get_env('SYNOLOGY_CHAT_URL', ''), 'chat_url': self._get_env('SYNOLOGY_CHAT_URL', ''),
'chat_token': self._get_env('SYNOLOGY_CHAT_TOKEN', ''), 'chat_token': self._get_env('SYNOLOGY_CHAT_TOKEN', ''),
} }
# Notion 설정 # Notion 설정
self.notion = { self.notion = {
'enabled': self._get_bool('NOTION_ENABLED', False),
'api_secret': self._get_env('NOTION_API_SECRET', ''), 'api_secret': self._get_env('NOTION_API_SECRET', ''),
} }

View File

@ -52,37 +52,46 @@ class MessageSender:
def __init__( def __init__(
self, self,
mattermost_enabled: bool = False,
mattermost_url: str = "", mattermost_url: str = "",
mattermost_token: str = "", mattermost_token: str = "",
mattermost_channel_id: str = "", mattermost_channel_id: str = "",
mattermost_webhook_url: str = "", mattermost_webhook_url: str = "",
telegram_enabled: bool = False,
telegram_bot_token: str = "", telegram_bot_token: str = "",
telegram_chat_id: str = "", telegram_chat_id: str = "",
synology_enabled: bool = False,
synology_webhook_url: str = "" synology_webhook_url: str = ""
): ):
""" """
메시지 발송자 초기화 메시지 발송자 초기화
Args: Args:
mattermost_enabled: Mattermost 사용 여부
mattermost_url: Mattermost 서버 URL (예: https://mattermost.example.com) mattermost_url: Mattermost 서버 URL (예: https://mattermost.example.com)
mattermost_token: Mattermost Bot 인증 토큰 mattermost_token: Mattermost Bot 인증 토큰
mattermost_channel_id: 메시지를 보낼 채널 ID mattermost_channel_id: 메시지를 보낼 채널 ID
mattermost_webhook_url: 웹훅 URL (웹훅 방식 사용 시) mattermost_webhook_url: 웹훅 URL (웹훅 방식 사용 시)
telegram_enabled: Telegram 사용 여부
telegram_bot_token: Telegram Bot API 토큰 telegram_bot_token: Telegram Bot API 토큰
telegram_chat_id: Telegram 채팅방 ID telegram_chat_id: Telegram 채팅방 ID
synology_enabled: Synology Chat 사용 여부
synology_webhook_url: Synology Chat 웹훅 URL synology_webhook_url: Synology Chat 웹훅 URL
""" """
# Mattermost 설정 # Mattermost 설정
self.mattermost_enabled = mattermost_enabled
self.mattermost_url = mattermost_url.rstrip('/') if mattermost_url else "" self.mattermost_url = mattermost_url.rstrip('/') if mattermost_url else ""
self.mattermost_token = mattermost_token self.mattermost_token = mattermost_token
self.mattermost_channel_id = mattermost_channel_id self.mattermost_channel_id = mattermost_channel_id
self.mattermost_webhook_url = mattermost_webhook_url self.mattermost_webhook_url = mattermost_webhook_url
# Telegram 설정 # Telegram 설정
self.telegram_enabled = telegram_enabled
self.telegram_bot_token = telegram_bot_token self.telegram_bot_token = telegram_bot_token
self.telegram_chat_id = telegram_chat_id self.telegram_chat_id = telegram_chat_id
# Synology Chat 설정 # Synology Chat 설정
self.synology_enabled = synology_enabled
self.synology_webhook_url = synology_webhook_url self.synology_webhook_url = synology_webhook_url
@classmethod @classmethod
@ -91,6 +100,7 @@ class MessageSender:
설정 파일에서 메시지 발송자 생성 설정 파일에서 메시지 발송자 생성
환경변수에서 모든 메시징 설정을 로드하여 인스턴스를 생성합니다. 환경변수에서 모든 메시징 설정을 로드하여 인스턴스를 생성합니다.
ENABLED가 false이거나 주석처리된 플랫폼은 비활성화됩니다.
Returns: Returns:
설정이 적용된 MessageSender 인스턴스 설정이 적용된 MessageSender 인스턴스
@ -98,12 +108,15 @@ class MessageSender:
config = get_config() config = get_config()
return cls( return cls(
mattermost_enabled=config.mattermost.get('enabled', False),
mattermost_url=config.mattermost.get('url', ''), mattermost_url=config.mattermost.get('url', ''),
mattermost_token=config.mattermost.get('token', ''), mattermost_token=config.mattermost.get('token', ''),
mattermost_channel_id=config.mattermost.get('channel_id', ''), mattermost_channel_id=config.mattermost.get('channel_id', ''),
mattermost_webhook_url=config.mattermost.get('webhook_url', ''), mattermost_webhook_url=config.mattermost.get('webhook_url', ''),
telegram_enabled=config.telegram.get('enabled', False),
telegram_bot_token=config.telegram.get('bot_token', ''), telegram_bot_token=config.telegram.get('bot_token', ''),
telegram_chat_id=config.telegram.get('chat_id', ''), telegram_chat_id=config.telegram.get('chat_id', ''),
synology_enabled=config.synology.get('enabled', False),
synology_webhook_url=config.synology.get('chat_url', ''), synology_webhook_url=config.synology.get('chat_url', ''),
) )
@ -159,14 +172,23 @@ class MessageSender:
return success return success
def _get_configured_platforms(self) -> List[str]: def _get_configured_platforms(self) -> List[str]:
"""설정된 플랫폼 목록 반환""" """
활성화되고 설정이 완료된 플랫폼 목록 반환
ENABLED가 true이고 필수 설정이 있는 플랫폼만 반환합니다.
"""
platforms = [] platforms = []
if self.mattermost_url and (self.mattermost_token or self.mattermost_webhook_url): # Mattermost: enabled=true이고 URL과 (토큰 또는 웹훅) 필요
if self.mattermost_enabled and self.mattermost_url and (self.mattermost_token or self.mattermost_webhook_url):
platforms.append('mattermost') platforms.append('mattermost')
if self.telegram_bot_token and self.telegram_chat_id:
# Telegram: enabled=true이고 토큰과 chat_id 필요
if self.telegram_enabled and self.telegram_bot_token and self.telegram_chat_id:
platforms.append('telegram') platforms.append('telegram')
if self.synology_webhook_url:
# Synology: enabled=true이고 웹훅 URL 필요
if self.synology_enabled and self.synology_webhook_url:
platforms.append('synology') platforms.append('synology')
return platforms return platforms
@ -176,6 +198,7 @@ class MessageSender:
Mattermost로 메시지 발송 Mattermost로 메시지 발송
웹훅 또는 API 방식으로 메시지를 발송합니다. 웹훅 또는 API 방식으로 메시지를 발송합니다.
MATTERMOST_ENABLED가 false이면 건너뜁니다.
Args: Args:
message: 발송할 메시지 message: 발송할 메시지
@ -184,6 +207,10 @@ class MessageSender:
Returns: Returns:
발송 성공 여부 발송 성공 여부
""" """
if not self.mattermost_enabled:
logger.debug("Mattermost가 비활성화되어 있습니다. (MATTERMOST_ENABLED=false)")
return True # 비활성화 상태는 성공으로 처리
try: try:
if use_webhook and self.mattermost_webhook_url: if use_webhook and self.mattermost_webhook_url:
# 웹훅 방식 # 웹훅 방식
@ -240,12 +267,18 @@ class MessageSender:
""" """
Telegram으로 메시지 발송 Telegram으로 메시지 발송
TELEGRAM_ENABLED가 false이면 건너뜁니다.
Args: Args:
message: 발송할 메시지 message: 발송할 메시지
Returns: Returns:
발송 성공 여부 발송 성공 여부
""" """
if not self.telegram_enabled:
logger.debug("Telegram이 비활성화되어 있습니다. (TELEGRAM_ENABLED=false)")
return True # 비활성화 상태는 성공으로 처리
if not self.telegram_bot_token or not self.telegram_chat_id: if not self.telegram_bot_token or not self.telegram_chat_id:
logger.error("Telegram 설정이 완료되지 않았습니다.") logger.error("Telegram 설정이 완료되지 않았습니다.")
return False return False
@ -274,12 +307,18 @@ class MessageSender:
""" """
Synology Chat으로 메시지 발송 Synology Chat으로 메시지 발송
SYNOLOGY_ENABLED가 false이면 건너뜁니다.
Args: Args:
message: 발송할 메시지 message: 발송할 메시지
Returns: Returns:
발송 성공 여부 발송 성공 여부
""" """
if not self.synology_enabled:
logger.debug("Synology Chat이 비활성화되어 있습니다. (SYNOLOGY_ENABLED=false)")
return True # 비활성화 상태는 성공으로 처리
if not self.synology_webhook_url: if not self.synology_webhook_url:
logger.error("Synology Chat 웹훅 URL이 설정되지 않았습니다.") logger.error("Synology Chat 웹훅 URL이 설정되지 않았습니다.")
return False return False

View File

@ -1,8 +1,8 @@
# =================================================================== # ===================================================================
# requirements.txt # requirements.txt
# FGTools 통합 프로젝트 의존성 # FGTools ?듯빀 ?꾨줈?앺듃 ?섏〈??
# =================================================================== # ===================================================================
# 모든 서비스에서 사용하는 패키지들의 통합 목록입니다. # 紐⑤뱺 ?쒕퉬?ㅼ뿉???ъ슜?섎뒗 ?⑦궎吏€?ㅼ쓽 ?듯빀 紐⑸줉?낅땲??
# pip install -r requirements.txt # pip install -r requirements.txt
# =================================================================== # ===================================================================
@ -34,29 +34,30 @@ python-dateutil>=2.8.2
google-analytics-data>=0.18.5 google-analytics-data>=0.18.5
# ===== Forecasting (Optional) ===== # ===== Forecasting (Optional) =====
# 방문객 예측 기능 사용 시 설치 # 諛⑸Ц媛??덉륫 湲곕뒫 ?ъ슜 ???ㅼ튂
# prophet>=1.1.5 # prophet>=1.1.5
# statsmodels>=0.14.0 # statsmodels>=0.14.0
# scikit-learn>=1.3.2 # scikit-learn>=1.3.2
# ===== Visualization (Optional) ===== # ===== Visualization (Optional) =====
# 데이터 시각화 사용 시 설치 # ?곗씠???쒓컖???ъ슜 ???ㅼ튂
# matplotlib>=3.8.2 # matplotlib>=3.8.2
# ===== Web Automation (Optional) ===== # ===== Web Automation (Optional) =====
# 날씨 캡처 기능 사용 시 설치 # ?좎뵪 罹≪쿂 湲곕뒫 ?ъ슜 ???ㅼ튂
# selenium>=4.0.0 # selenium>=4.0.0
# pillow>=10.0.0 # pillow>=10.0.0
# ===== FTP (Optional) ===== # ===== FTP (Optional) =====
# 파일 업로드 기능 사용 시 설치 # ?뚯씪 ?낅줈??湲곕뒫 ?ъ슜 ???ㅼ튂
# ftputil>=5.0.0 # ftputil>=5.0.0
# ===== GUI (Optional) ===== # ===== GUI (Optional) =====
# GUI 도구 사용 시 설치 # GUI ?꾧뎄 ?ъ슜 ???ㅼ튂
# customtkinter>=5.2.0 # customtkinter>=5.2.0
# tkcalendar>=1.6.1 # tkcalendar>=1.6.1
# ===== Utilities ===== # ===== Utilities =====
tabulate>=0.9.0 tabulate>=0.9.0
watchdog>=3.0.0 watchdog>=3.0.0