Skip to content

Commit

Permalink
fix: Fixes typo
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm committed Jan 24, 2024
1 parent b6bafa6 commit d73910c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/app/api/endpoints/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from app.api.crud.authorizations import check_group_read, is_admin_access
from app.api.crud.groups import get_entity_group_id
from app.api.deps import get_current_access, get_current_device, get_current_user, get_db
from app.api.endpoints.notifications import send_notification
from app.api.endpoints.notifications import _send_notification
from app.api.endpoints.recipients import fetch_recipients_for_group
from app.api.external import post_request
from app.db import alerts, devices, events, media
Expand Down Expand Up @@ -53,7 +53,7 @@ async def alert_notification(payload: AlertOut):
subject: str = Template(recipient.subject_template).safe_substitute(**info)
message: str = Template(recipient.message_template).safe_substitute(**info)
notification = NotificationIn(alert_id=payload.id, recipient_id=recipient.id, subject=subject, message=message)
await send_notification(notification)
await _send_notification(notification)


async def _create_alert(payload: AlertIn, background_tasks: BackgroundTasks) -> AlertOut:
Expand Down
19 changes: 11 additions & 8 deletions src/app/api/endpoints/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
router = APIRouter(dependencies=[Security(get_current_access, scopes=[AccessType.admin])])


async def _send_notification(payload: NotificationIn) -> NotificationOut:
recipient = RecipientOut(**(await get_recipient(recipient_id=payload.recipient_id)))
if recipient.notification_type == NotificationType.telegram:
send_telegram_msg(recipient.address, payload.message)
else:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid NotificationType, not treated")

return NotificationOut(**(await crud.create_entry(notifications, payload)))


@router.post("/", status_code=status.HTTP_201_CREATED, summary="Send and log notification")
async def send_notification(
payload: NotificationIn,
Expand All @@ -31,14 +41,7 @@ async def send_notification(
or "Example Value" to get a concrete idea of arguments
"""
telemetry_client.capture(user.id, event="notifications-send", properties={"recipient_id": payload.recipient_id})
recipient = RecipientOut(**(await get_recipient(recipient_id=payload.recipient_id)))
if recipient.notification_type == NotificationType.telegram:
send_telegram_msg(recipient.address, payload.message)
else:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid NotificationType, not treated")

notification: NotificationOut = NotificationOut(**(await crud.create_entry(notifications, payload)))
return notification
return _send_notification(payload)


@router.get(
Expand Down

0 comments on commit d73910c

Please sign in to comment.