I'm trying to figure out how to set up Slack notifications from GitHub Actions at my organization. I found an example that uses the `users.lookupByEmail` method in Slack's API, which seems like it could work if I can get the email address of the `${GITHUB_ACTOR}`. However, when I tested using `gh api /users/$ACTOR`, the email field returned `null`, which makes me think I might be doing something wrong or it could be a permissions issue. I feel like this is a common setup, so I'd love to hear how others manage sending Slack notifications from their GitHub Actions. Any advice would be appreciated!
5 Answers
Check out the Slack and GitHub documentation about permissions. It mentions that if the email isn’t set to public on GitHub, you'll get `null` for the email field. You’ll also run into issues if a user’s primary email is personal and not their organizational one. For us, we mute direct message bots and channel notifications instead, which makes it less intrusive.
To bridge Slack and GitHub accounts, we maintain a mapping of GitHub usernames to Slack handles. We use Infrastructure as Code (IaC) with Terraform to inject this mapping into GitHub variables. This way, our Slack notification action can replace the usernames correctly before posting messages.
Have you considered using the GitHub app for Slack? It handles a lot of notifications automatically. Users can subscribe to PRs, and you'll get notifications about commits, PRs, deployments, etc., directly in a channel. Plus, if users log into the GitHub app in Slack, it syncs GitHub usernames to Slack names, making it easier.
Our setup sends notifications through a pub/sub system, which interfaces with different services. It's a bit complex, but it has the flexibility to route messages wherever they're needed in our engineering team.
We typically use a generic inbox for pipeline notifications and a fixed Slack webhook for important messages. For notifications aimed at the PR author, I just leave a comment on their PR. That way, GitHub sends them an email as well.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically