Skip to content

Add slack notification #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Add slack notification #468

wants to merge 17 commits into from

Conversation

RonanMorgan
Copy link
Collaborator

@RonanMorgan RonanMorgan commented May 15, 2025

Give the possibility to activate slack notification into a channel (one channel per organisation)

=> Add an endpoint in the organizations/ path in order to activate the slack notification by registering the SLACK_HOOK
=> Create a SLACK service, similar to the Telegram service
=> modify the create_detection endpoint in on order to add the notification creation : the bbox is added to the images of the Sequence, a gif is created from the images of the Sequence, the gif is saved into the S3 bucket and the url is sent to slack.

class SlackClient:
def __init__(self) -> None:
self.is_enabled = True
# Do we want a config in settings ?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 45 lines in your changes missing coverage. Please review.

Project coverage is 82.28%. Comparing base (14d58dc) to head (cea33c7).

Files with missing lines Patch % Lines
src/app/api/api_v1/endpoints/detections.py 20.45% 35 Missing ⚠️
src/app/services/slack.py 74.19% 8 Missing ⚠️
src/app/api/api_v1/endpoints/organizations.py 88.88% 1 Missing ⚠️
src/app/main.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #468      +/-   ##
==========================================
- Coverage   84.79%   82.28%   -2.52%     
==========================================
  Files          38       39       +1     
  Lines        1151     1236      +85     
==========================================
+ Hits          976     1017      +41     
- Misses        175      219      +44     
Flag Coverage Δ
backend 81.50% <50.00%> (-2.64%) ⬇️
client 93.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RonanMorgan RonanMorgan marked this pull request as ready for review May 22, 2025 14:51
@RonanMorgan RonanMorgan requested a review from frgfm May 22, 2025 14:51
@github-actions github-actions bot added the topic: build Related to build, installation & CI label May 22, 2025
@frgfm
Copy link
Member

frgfm commented Jun 6, 2025

Hey there :)
Thanks for the PR!
Sorry about the late reply! Some concise feedback:

  • I 100% agree with the feature, but I think we could implement it in a better way. I'll do my best to address my concerns and suggestions below
  • this is adding an image processing capability in the API (only binary currently), not sure I'd like to go in that route nor that it's necessary (sharing a URL to the image will display it)
  • opencv is not a light dependency. I'd like to avoid that if possible.
  • excellent choice about the hook instead of full client 👌

So my suggestion:

  • remove any pillow or opencv dependency and share the URL in the slack message (i know it might not be enough but if that's not the case, this backend API is not a notification center 😅 )

And I have a question to understand the deeper need: is this for us to see when there is an alert or used by firefighters? Because we don't necessary need the GIF if that can be seen in the platform, perhaps only a link to the platform alert for gif visualization would be better (that way, we only share the static image URL + platform URL for action and GIF visualization)

@MateoLostanlen
Copy link
Member

Hey, thanks for the feedback!

I’m not sure I fully understand the issue here. Sure, OpenCV isn’t the lightest dependency, but it’s not exactly heavy either. Unless I’m missing something, we’re not particularly resource-constrained, are we? Do you have a concrete case in mind where this could be a problem?

More broadly, I get the idea of keeping the API minimal, but I think we might be underestimating how valuable it is to quickly visualize an alert. Seeing a fire without a bounding box takes time. And since we’re doing early detection, the fire is often small and not obvious. A still image with a bbox is better, but a GIF is even quicker to interpret. We’re racing against time here

If including OpenCV in the main container is really an issue, could we consider a second container dedicated to the computer vision part, just generating the GIF and returning a URL to the API? That would keep things modular while still providing the best user experience.

Let me know what you think!

@frgfm
Copy link
Member

frgfm commented Jun 9, 2025

Hey there :)

Yup fully get your point, here is some short feedback:

  • we're not exactly resource constrained: when I say light I mean in terms of dependencies (additional licenses but also versioning and bugs that comes with it). I've had that type of experience with some dependencies we have here in another project. I'm only mindful of those when I see a way to avoid them without degrading the output too much
  • to my previous point, the slack API is generous enough so that image URL are rendered. This avoids downloading bytes from s3 and "uploading them" to slack, it will only be "downloaded" by the end user when Slack renders --> much faster and lower load. Now you're correct that doing so, we can't modify the image (can't add bbox or transform into GIF) but I don't want the Alert API to take that responsibility, it's a slippery road to stretch that much
  • your suggestion is on point especially since I wanted to create a small vision API for pyronear

For now my suggestion:

  • first only forwarding the URL (no bbox, no GIF). Remember it's for our Slack, not firefighters
  • Otherwise I'd suggest including a URL to the platform: when we click it, it opens the platform on this specific alert. That way no one is taking extra load and everything stays lean :)

What do you think?

@MateoLostanlen
Copy link
Member

Just to clarify: this is actually meant for firefighters on our Slack, the idea is for them to get alerts in real time on their phone or computer

You're the API king haha, so I’ll let you make the call. I trust you, if you think it’s not the right direction long-term, then let's not go for it. Still, that GIF was pretty sexy! I guess we’ll need to kick off that vision API sooner rather than later. I really think there are quite a few interesting use cases we could develop around it

@RonanMorgan sorry about that… I should’ve kicked off the conversation earlier. I made you work for nothing. Would you mind updating the PR to go back to a message with alert info and a URL instead?

@frgfm
Copy link
Member

frgfm commented Jun 9, 2025

Just to clarify: this is actually meant for firefighters on our Slack, the idea is for them to get alerts in real time on their phone or computer

I thought they already had Telegram alerts? 🤔 Or do you mean non static ones?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants