On a fast-moving dev team, it’s sometimes a challenge keeping up with what’s new! We had this problem, so we built a widget that posts in a Slack channel each time we merge a PR. It uses GitHub webhooks to know when a PR gets merged, and the Slack postMessage API to post the message.
Here’s the code:
And here’s the result:
To set this up for yourself, you’ll need to create a GitHub webhook pointing at your widget, and a Slack app with the chat:write.public
scope.
Follow the first few steps of the Slack API Quickstart: Create a new app from scratch, and request the chat:write.public
scope so it can post in any public channel. Then install it on your workspace.
Next, you’ll need to copy your Slack bot token and use it to fill out the slack_token
secret in your widget’s secrets.
Finally, you’ll need to get the Channel ID for the channel you want your bot to post in. You can get this by right-clicking the channel in Slack and choosing View Channel Details. Then update the CHANNEL_ID
constant in your widget code.
Go to the Settings of your GitHub repository, then choose Webhooks, then create a new webhook. You’ll need to paste the URL of your HTTP route, select JSON delivery, and choose Send me everything to be notified when PRs are merged:
Try merging a PR in GitHub, and watch your app post!
If you’re having trouble and need to debug, look for error messages in your widget output, or check the “Recent Deliveries” tab in your GitHub webhook configuration.
Have fun!
See more things you can do with py.space: