I'm going to store this URL as a Firebase config as well, to hide it from prying eyes.Ĭonst axios = require ( " axios " ) const functions = require ( " firebase-functions " ) const octokit = require ( " " ) const webhooks = new octokit. You can set these up in the Server settings > Integrations > Webhooks. Discord API allows incoming webhooks to send messages into a specific channel on Discord. Now that it's confirmed that github webhooks can trigger firebase functions correctly, it's time to hook up actual functionality and send hooks to Discord. Step 6: Set up incoming webhooks on Discord You should see the standard set of logs that firebase produces whenever it handles an event Over on Firebase functions, you can inspect the logs for the function that was deployed to check that it correctly handled the incoming webhook. Once you've set it up, you can try create a PR or an issue, or anything that triggers the webhook, and go over to the "Recent Deliveries" tab of the webhook, where you can inspect the delivery status and payload of the webhook I have it set to notify on: "Issues", "Issue comments", "Pull requests", and "Releases".
But it may be nicer to restrict it here to save on how many times your function will have to trigger. You don't have to do this as you can filter out the events in the functions in a sec. Optionally, select Let me select individual events and then select just the events you want to notify on. Set the Secret to the secret set in the previous step. Set the content type to application/json. Set the Payload URL to the address from firebase. Copy this, then go over to your github hooks in your repository (Settings > Webhooks, then Add webhook) This is the URL that you want Github to send webhooks to. Once the function is deployed, you can find its HTTP url on the Firebase web console: Inside the index.js file I added the following boilerplate for handling github webhooks using the octokit webhooks library:Įnter fullscreen mode Exit fullscreen mode Step 3: Add a github webhook receiving endpoint Had the use-case been more complicated (if we had more than one type/format of notification to send), I would have gone with it.
#CONNECT WEBOOK TO GET FULL LIST INSTALL#
It's also possible to install discord.js library which helps you format the outgoing webhooks to Discord API, but I've decided not to use this as the use-case is relatively simple, and I didn't want to install quite a large library unnecessarily. Github provides a convenient library for webhooks called to make processing them easily, which can be installed using npm install from inside the new functions folder that firebase creates. I selected Javascript, and some other default settings. You can either select an existing firebase project from the menu (if you created a new firebase project online or previously), or the CLI will let you create a new firebase project. Then firebase init functions in a new folder to set up a new project with Firebase functions.Then firebase login to log in (following the prompts).With node.js and NPM installed, npm install -g firebase-tools to install the firebase CLI tools.I won't go into it here, but you can pretty much drive the whole thing from the firebase CLI ( docs), and goes something like this: Step 1: Set up new/existing Firebase project So I threw up a small firebase function (written in Javascript) to serve as an intermediary between GitHub and Discord to give me this control. However, you don't have much control over how this notification is presented, and you only get coarse-grain control over what notifications are sent, or people to ping. Discord actually provides this functionality out of the box as part of webhooks, you can set up a webhook with github and immediately start receiving notifications, which look like this: When working in a team, or a public project, sometimes you want to see github activity notifications in your discord chats (because who pays attention to github notification emails? got too many emails as it is).