This is a service that acts as a receiver for web hooks. Once it's getting hit by an incoming web hook (For example from Netlify on a successful build) fetches an RSS feed and tweets/toots out the items that haven't been tweeted/tooted yet. It does this by keeping a local cache db of things it tweeted/tooted so it'll only do it once.
There's alternatives like Zapier and IFTTT but they don't have a way to customize the Tweet/Toot format. Their defaults don't look that nice too.
Use Case / Features
My use case is a Hugo blog deployed on Netlify, once I push a new blog post it'll:
- Build the blog on Netlify
- The build is successful
- Netlify hits
webhook-receiver
running on webhooks.example.com
- Then
webhook-receiver
fetches the RSS feed on example.com/feed.xml
- It checks the local cache db which items haven't been posted to Twitter
- It tweets/toots one feed item that hasn't been posted yet and adds it to the cache. If there's multiple items that are not published yet it'll only post one. The next one will be posted on the next web hook trigger
- It goes back to listening for new web hooks from Netlify
Caveats
- Currently only using Atom fields, make sure your feed has the right fields set (
<summary>
and <link>
are currently used)
Deploy
There are the environment variables that can be set.
export WR_ENVIRONMENT=development
export WR_PORT=8080
export WR_CACHE_DATABASE_PATH=/cache
export WR_FEED_URL=https://example.com/feed.xml
export WR_HOOK_TOKEN=changeme
export WR_TWITTER_CONSUMER_KEY=changeme
export WR_TWITTER_CONSUMER_SECRET_KEY=changeme
export WR_TWITTER_ACCESS_TOKEN=changeme
export WR_TWITTER_ACCESS_TOKEN_SECRET=changeme
export WR_TWITTER_USERNAME=changeme
export WR_MASTODON_SERVER=changeme
export WR_MASTODON_CLIENT_KEY=changeme
export WR_MASTODON_CLIENT_SECRET=changeme
export WR_MASTODON_ACCESS_TOKEN=changeme
There's also a Dockerfile
and Docker Compose file included so you can easily run it via docker-compose -f docker-compose.yml up -d
. Create the cache
file in the location where your volume maps to (touch /your/volume/location/cache
.
The Twitter credentials can be generated by setting up a new "App" on developer.twitter.com.
Development
If you want to look at the content of the incoming web hook use webhook.site.
To hit your web hook receiver running locally use ngrok and set it up as a web hook on the third party service you are testing it with.