The goal of that project is to handle releases from github webhook and send it to a Gchat channel.
That project is mainly inspired from worker-slack-bot.
Clone the repo and use wrangler publish. If you do not know wrangler please follow the guide here.
Then follow requirements described for the deployment option you want to go to:
Additionaly you can follow logging instruction here to monitor any error raised by your workers.
That deployment means you need to enter the webhook URL in Github that point to your Cloudflare Workers. You are leveraging the path /webhook and all the query string parameters expected by thta deployment (described below). In that mode, the Cloudflare Workers is a middelware to adapt the webhhok request sent by github into a webhook message understood by Google Chat.
Requirements in webhook mode:
The Workers has a path /webhook that need to be used.
In addition to that the Workers is using the google webhook schema. The current logic is used:
https://chat.googleapis.com/v1/spaces/<SPACE-ID>/messages?key=<KEY>&token=<TOKEN>
The SPACE-ID, KEY and TOKEN has to be sent in order to handle the destination correctly
The following params are available:
- space: defined the space-id destination in Google.
- key: defined the key for the Gchat destination.
- token: defined the token for the Gchat destination
Here an example of the final URL you have to configure in github to get webhook in GChat: https://github2gchat-webhook.<subdomain>.workers.dev/webhook?space=<SPACE-ID>&key=<KEY>&token=<TOKEN>
The monitoring mode leverage KV storage in Cloudflare and Workers Cron jobs in order to monitor specific RSS feed and post any update in a Gchat via a webhooks.
Requirements in webhook mode:
In order to use that mode, you have to:
- Configure a KV store and bind it to your workers:
wrangler kv:namespace create KV - Configure the structure use by the Workers in order to monitor an RSS feed. Here an example:
wrangler kv:key put --binding=KV "webhooks" '[{"name": "Terraform Provider Cloudflare", "source": "https://github.com/cloudflare/terraform-provider-cloudflare/releases.atom", "destinations": ["https://chat.googleapis.com/v1/spaces/<SPACE_ID>/messages?key=<KEY>&token=<TOKEN>"]}]'Please not that the url should not be URL encoded, menaing you need to remove any excape characters like\and replace%3Dby=for example. More info here. Otherwise the escape charactere is breaking the JSON object. - Make sure you are using
htmlparser2dependency. Runnpm install. - (if needed) Change the default Cron triggers (set to every minutes in the wrangler.toml file) as described in the docs here
The following structure has to be defined in the KV store:
- KV key: webhooks
- KV Value: an Array containing a JSON object with:
- name: name of the webhook
- source: RSS feed to monitor in my example I am taking RSS feed directly from github.
- destinations: Array of Google Chat webhook on which any update are posted.
Note: There is a static test in order to removed scheduled events part of the cloudflare incident. If you want to received those events you have to create a new webhook name with scheduled inside.
RSS feed example supported by Github:
/* Repo releases */
https://github.com/:owner/:repo/releases.atom
/* Repo commits */
https://github.com/:owner/:repo/commits.atom
/* Private feed (You can find Subscribe to your news feed in dashboard page after login) */
https://github.com/:user.private.atom?token=:secret
/* Repo tags */
https://github.com/:user/:repo/tags.atom
/* User activity */
https://github.com/:user.atom
The project use Sentry as logging endpoint for every errors.
Requirements for logging:
To redirect those error correctly you need to set-up Sentry_Key and Sentry_ID (if not specify no logging would be done).
The steps are the following:
wrangler secret put Sentry_Key: Defined your Sentry Keywrangler secret put Sentry_ID: Defined your Sentry ID
If you want to test locally, you have to follow the steps below:
- Create a file
.dev.varsat the root with the variableSentry_KeyandSentry_ID. - Run the project with
wrangler dev
The current version of the webhook mode only handle released as an action as per the github doc here.
When you add the webhook (in webhook mode), the Workers handles ping event and write a message in the destination chat channel.
Enjoy! 🎉