Skip to content

Commit

Permalink
refactor(detections): restrict webhook and telegram to sequence creat…
Browse files Browse the repository at this point in the history
…ion (#416)
  • Loading branch information
frgfm authored Jan 17, 2025
1 parent 6c8b02f commit 840640c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/app/api/api_v1/endpoints/detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,20 @@ async def create_detection(
)
)
# Update the detection with the sequence ID
await detections.update(det.id, DetectionSequence(sequence_id=sequence_.id))
det = await detections.update(det.id, DetectionSequence(sequence_id=sequence_.id))
for det_ in dets_:
await detections.update(det_.id, DetectionSequence(sequence_id=sequence_.id))

# Webhooks
whs = await webhooks.fetch_all()
if any(whs):
for webhook in await webhooks.fetch_all():
background_tasks.add_task(dispatch_webhook, webhook.url, det)
# Telegram notifications
if telegram_client.is_enabled:
org = cast(Organization, await organizations.get(token_payload.organization_id, strict=True))
if org.telegram_id:
background_tasks.add_task(telegram_client.notify, org.telegram_id, det.model_dump_json())
# Webhooks
whs = await webhooks.fetch_all()
if any(whs):
for webhook in await webhooks.fetch_all():
background_tasks.add_task(dispatch_webhook, webhook.url, det)
# Telegram notifications
if telegram_client.is_enabled:
org = cast(Organization, await organizations.get(token_payload.organization_id, strict=True))
if org.telegram_id:
background_tasks.add_task(telegram_client.notify, org.telegram_id, det.model_dump_json())
return det


Expand Down

0 comments on commit 840640c

Please sign in to comment.