import config from external_api.base.clients.client import ApiClient class SlackReporter: http_client: ApiClient = ApiClient(config.SLACK_WEBHOOK_URL) env_name = config.ENV_IDENTIFIER async def notify_success(self, title, msg): if not config.SLACK_WEBHOOK_PATH: return params = { "attachments": [ { "fallback": f"[{self.env_name}] [SUCCESS] {title}", "pretext": f"[{self.env_name}] [SUCCESS] {title}", "color": "good", "fields": [{"title": "Details", "value": f"{msg}", "short": False}], } ] } await self.http_client.post(endpoint=config.SLACK_WEBHOOK_PATH, payload=params) async def notify_info(self, title, msg): if not config.SLACK_WEBHOOK_PATH: return params = { "attachments": [ { "fallback": f"[{self.env_name}] [INFO] {title}", "pretext": f"[{self.env_name}] [INFO] {title}", "color": "#00FFFF", "fields": [{"title": "Details", "value": f"{msg}", "short": False}], } ] } await self.http_client.post(endpoint=config.SLACK_WEBHOOK_PATH, payload=params) async def notify_error(self, title, msg): if not config.SLACK_WEBHOOK_PATH: return params = { "attachments": [ { "fallback": f"[{self.env_name}] [ERROR] {title}", "pretext": f"[{self.env_name}] [ERROR] {title}", "color": "danger", "fields": [{"title": "Details", "value": f"{msg}", "short": False}], } ] } await self.http_client.post(endpoint=config.SLACK_WEBHOOK_PATH, payload=params)