- Implemented the initial version of the web interface. refactor: Begin Telegram bot refactoring - Started restructuring the bot’s code for better maintainability. chore: Migrate to Flask project structure - Reorganized the application to follow Flask's project structure. cleanup: Extensive code cleanup - Removed redundant code and improved readability. Signed-off-by: UdoChudo <stream@udochudo.ru>
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from utilities.notification_manager import NotificationManager
|
||
from utilities.telegram_utilities import extract_region_number, format_message
|
||
from flask import current_app
|
||
|
||
|
||
|
||
class NotificationService:
|
||
def __init__(self):
|
||
self.logger = current_app.logger
|
||
self.manager = NotificationManager(self.logger)
|
||
|
||
def process_notification(self, data):
|
||
self.logger.info(f"Получены данные уведомления: {data}")
|
||
|
||
region_id = extract_region_number(data.get("host"))
|
||
if region_id is None:
|
||
self.logger.error(f"Не удалось извлечь номер региона из host: {data.get('host')}")
|
||
return {"status": "error", "message": "Invalid host format"}, 400
|
||
|
||
self.logger.debug(f"Извлечён номер региона: {region_id}")
|
||
|
||
subscribers = self.manager.get_subscribers(region_id, data['severity'])
|
||
|
||
if self.manager.is_region_active(region_id):
|
||
message = format_message(data)
|
||
self.manager.send_notifications(subscribers, message)
|
||
|
||
return {"status": "success"}, 200
|