counterdata-network / story-processor

Story discovery engine for the Counterdata Network. Grabs relevant stories from various APIs, runs them against bespoke classifier models, post results to a central server.
Apache License 2.0
0 stars 2 forks source link

support posting summary email text to Slack #4

Closed rahulbot closed 1 year ago

rahulbot commented 1 year ago

Right now, at the end of a nightly cron-triggered data ingestion run we use the processor.notifications.send_email helper function to notify people of how many stories, and for which projects, we discovered. The recipient email configuraiton comes from environment variables.

This isn't great, because we don't want to receive more barrages of emails. An alternative would be to use the Slack API to post these to a Slack channel, because we use Slack for project coordination. This task involves researching the Slack API, setting up a channel to post updates to, and adding support to post some version of the email text to Slack in addition (based on configured environment variables). Slack offers an SDK that should make the integration easier.

rahulbot commented 1 year ago

The goal here is to end up with something like a processor.notifications.send_slack_msg method, with appropriate arguments, that lets us post a msg to a slack channel based on env-vars.

You can build this with a slightly test-driven approach by having a processor.test.test_notifications.test_slack_msg() method that posts a dummy slack message to a channel that we can verify manually as having posted. Then we integrate it into places where send_email is used to allow send_slack_msg to be used in addition or instead.

This should work of off env-vars just like the email one does, returning False with a warning log if the code tries to use the method but Slack API env-vars are not configured. Ie. a notification failure should not stop regular execution flow of the program.

rahulbot commented 1 year ago

@adityagurnani22 can you make a PR to get this work integrated into main branch?

rahulbot commented 1 year ago

completed via #11