| 1 | from loguru import logger |
| 2 | from sqlalchemy.ext.asyncio import AsyncSession |
| 3 | |
| 4 | from app.connectors.shuffle.schema.integrations import ExecuteWorkflowRequest |
| 5 | from app.connectors.shuffle.services.integrations import execute_workflow |
| 6 | from app.incidents.schema.incident_alert import CreatedCaseNotificationPayload |
| 7 | from app.incidents.services.db_operations import get_customer_notification |
| 8 | |
| 9 | |
| 10 | async def handle_customer_notifications_case( |
| 11 | customer_code: str, |
| 12 | case_payload: CreatedCaseNotificationPayload, |
| 13 | session: AsyncSession, |
| 14 | type: str = "case", |
| 15 | ) -> None: |
| 16 | customer_notifications = await get_customer_notification(customer_code, session) |
| 17 | logger.info(f"Sending case_payload {case_payload} to customer code {customer_code}") |
| 18 | if customer_notifications and customer_notifications[0].enabled: |
| 19 | logger.info(f"Executing workflow for customer code {customer_code}") |
| 20 | await execute_workflow( |
| 21 | ExecuteWorkflowRequest( |
| 22 | workflow_id=customer_notifications[0].shuffle_workflow_id, |
| 23 | execution_arguments={ |
| 24 | "type": type, |
| 25 | "customer_code": customer_code, |
| 26 | "case_name": case_payload.case_name, |
| 27 | "alerts": case_payload.alerts, |
| 28 | }, |
| 29 | start="", |
| 30 | ), |
| 31 | ) |