This is an example Cloudflare Workers Slack App/Bot to retrieve titles of shared YouTube links and post them back to the channel. It uses the Slack Events API to listen for and respond to events. This is just a quick and dirty Worker script. Things will probably break when YouTube does a slight change to their site. 🤷
The whole process was a bit confusing, I hope the steps below help you get started.
Cloudflare Part:
- Clone this repo
- Optionally make adjustments to
wrangler.toml
to add your own name, domain etc. or just deploy it withnpm run deploy
- Create the Slack App now to retrieve your OAuth token etc.
- Add the OAuth token to your Cloudflare Worker secrets with
wrangler secret put slackToken
Slack Part:
- Create a new Slack App
- Add these features and functionality from the Slack App information page:
- Event Subscriptions
- Bots
- Permissions
- Note down the OAuth Token under OAuth & Permissions
- Add the following Bot Token Scopes:
chat:write
andlinks:read
- Add your Cloudflare Workers domain to Event Subscriptions and…
- Add
link_shared
as a Bot User Event - add
youtube.com
andyoutu.be
to the App unfurl domains
- Add
Resources: