Telezab/app/services/notifications_service.py
UdoChudo 52e31864b3 feat: Develop web interface
- 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>
2025-06-10 14:39:11 +05:00

29 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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