Posting Errors to Slack
We have logs, I think. I don’t really check them. The logs are treated like a debugging tool, I tail them when I really need to see why something’s broken. This is bad and the gods of good system architecture are going to smite me but we have a small, fast moving code base. Right now I need to push code much more urgently than I need to avoid technical debt. The truth is, a lot of this code is unlikely to exist in three months and many things are interim solutions or water testing.
But there are certain things that shouldn’t happen. Shopify shouldn’t bounce our API requests. Customers shouldn’t decline a billing charge. Facebook shouldn’t deauthorise our access token. And for these things, Slack integration is amazing.
We already use Slack to notify us of new users, and uninstalls, but now I also have Slack telling me if there’s an error that I need to deal with right now. And it couldn’t be easier to set up.
- Get your team on Slack.
- Create a new bot for error messages
3. Get your bot’s API key
The rest of this assumes you’re using Node.js but it should be easily adaptable for any language.
4. Save your bot’s details in the config (optional)
5. Add the bot to a channel (#general is added by default)
6. Send a message over HTTP (I like request but you use whatever library makes you happy)
7. Bonus: Wrap the Slack functionality up in a controller
8 And call like this