|
22 | 22 | SystemConfigValidationErrorResponse, |
23 | 23 | TestLLMChannelRequest, |
24 | 24 | TestLLMChannelResponse, |
| 25 | + TestNotificationChannelRequest, |
| 26 | + TestNotificationChannelResponse, |
25 | 27 | UpdateSystemConfigRequest, |
26 | 28 | UpdateSystemConfigResponse, |
27 | 29 | ValidateSystemConfigRequest, |
@@ -346,6 +348,50 @@ def test_llm_channel( |
346 | 348 | ) |
347 | 349 |
|
348 | 350 |
|
| 351 | +@router.post( |
| 352 | + "/config/notification/test-channel", |
| 353 | + response_model=TestNotificationChannelResponse, |
| 354 | + responses={ |
| 355 | + 200: {"description": "Notification channel test completed"}, |
| 356 | + 500: {"description": "Internal server error", "model": ErrorResponse}, |
| 357 | + }, |
| 358 | + summary="Test one notification channel", |
| 359 | + description="Send a short test notification using unsaved or saved notification configuration.", |
| 360 | +) |
| 361 | +def test_notification_channel( |
| 362 | + request: TestNotificationChannelRequest, |
| 363 | + service: SystemConfigService = Depends(get_system_config_service), |
| 364 | +) -> TestNotificationChannelResponse: |
| 365 | + """Validate and test one notification channel without writing `.env`.""" |
| 366 | + try: |
| 367 | + payload = service.test_notification_channel( |
| 368 | + channel=request.channel, |
| 369 | + items=[item.model_dump() for item in request.items], |
| 370 | + mask_token=request.mask_token, |
| 371 | + title=request.title, |
| 372 | + content=request.content, |
| 373 | + timeout_seconds=request.timeout_seconds, |
| 374 | + ) |
| 375 | + return TestNotificationChannelResponse.model_validate(payload) |
| 376 | + except (ValueError, TypeError) as exc: |
| 377 | + raise HTTPException( |
| 378 | + status_code=422, |
| 379 | + detail={ |
| 380 | + "error": "validation_error", |
| 381 | + "message": str(exc), |
| 382 | + }, |
| 383 | + ) |
| 384 | + except Exception as exc: |
| 385 | + logger.error("Failed to test notification channel: %s", exc, exc_info=True) |
| 386 | + raise HTTPException( |
| 387 | + status_code=500, |
| 388 | + detail={ |
| 389 | + "error": "internal_error", |
| 390 | + "message": "Failed to test notification channel", |
| 391 | + }, |
| 392 | + ) |
| 393 | + |
| 394 | + |
349 | 395 | @router.post( |
350 | 396 | "/config/llm/discover-models", |
351 | 397 | response_model=DiscoverLLMChannelModelsResponse, |
|
0 commit comments