webhook-receiver

module
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2023 License: MIT

README

Web hook Receiver: Post to Twitter or Mastodon from RSS feed

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:

  1. Build the blog on Netlify
  2. The build is successful
  3. Netlify hits webhook-receiver running on webhooks.example.com
  4. Then webhook-receiver fetches the RSS feed on example.com/feed.xml
  5. It checks the local cache db which items haven't been posted to Twitter
  6. 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
  7. 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.

Directories

Path Synopsis
cmd
api
service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL