GitHub
Setting up GitHub webhook integration with Rocket.Chat gives you the ability to
Receive event notifications from GitHub directly in your specified Rocket.Chat room (Incoming WebHook)
Send commands to GitHub and optionally receive a response (Outgoing WebHook).
These events include and are not limited to:
Comments
Issues events
Pull Requests
Merge requests
Deployment events
Comments and discussions
Tags, label and branch actions
etc.
GitHub Rocket.Chat Integration
We are going to see how to create both incoming and outgoing webhook integration between Rocket.Chat and GitHub.
Rocket.Chat Incoming webhook with GitHub
To configure an incoming webhook integration between GitHub and Rocket.Chat, you need to:
The following steps explain how to do this
Creating new GitHub webhook integration
Go to the Administration -> Workspace -> Integrations settings on your Rocket.Chat workspace
Switch to the Incoming tab and create a New Integration
Fill in the details of your webhook including the name of the webhook, the room to post into, the user to post as and enable it

Enable Scripts and paste any of the following example code into the Scripts box.
Save the settings
The Webhook URL and Token are generated after saving
Copy these credentials, they will be used later

GitHub Webhook Setting
After creating the new incoming webhook integration on Rocket.Chat, it is time to link it up with the GitHub repository.
Go to the GitHub project repository then navigate to Settings > Webhooks
Add webhook and fill in the
URL
andtoken
you copied from the Rocket.Chat settingSelect the list of events you want to be notified on and Add webhook
GitHub webhook setting
After successful configuration, you can test the Webhook with any event trigger and see the notification in your specified Rocket.Chat room.

Rocket.Chat GitHub Outgoing Webhook
Create a new Outgoing WebHook
Select the channel where you will use the commands and receive the responses
Set URLs as
https://api.github.com/repos/User-Or-Org-Name/Repo-Name
likehttps://api.github.com/repos/RocketChat/Rocket.Chat
Enable Scripts
Use this Script to listen for commands
pr ls
,pr list
andhelp
/* exported Script */
/* globals Store */
class Script {
prepare_outgoing_request({ request }) {
let match;
console.log('lastCmd', Store.get('lastCmd'));
match = request.data.text.match(/^pr last$/);
if (match && Store.get('lastCmd')) {
request.data.text = Store.get('lastCmd');
}
match = request.data.text.match(/^pr\s(ls|list)\s*(open|closed|all)?$/);
if (match) {
Store.set('lastCmd', request.data.text);
let u = request.url + '/pulls';
if (match[2]) {
u += '?state='+match[2];
}
return {
url: u,
headers: request.headers,
method: 'GET'
};
}
match = request.data.text.match(/^help$/);
if (match) {
Store.set('lastCmd', request.data.text);
return {
message: {
text: [
'**GitHub commands**',
'```',
' pr ls|list [open|closed|all] List Pull Requests',
'```'
].join('\n')
}
};
}
}
process_outgoing_response({ request, response }) {
var text = [];
response.content.forEach(function(pr) {
text.push('> '+pr.state+' [#'+pr.number+']('+pr.html_url+') - '+pr.title);
});
return {
content: {
text: text.join('\n'),
parseUrls: false
}
};
}
}
Save your integration
Customizing your integration scripts
The purpose of the integration script is to transform data in one format (the format provided by your incoming service, such as GitHub) into another format (the format expected by Rocket.Chat). Therefore, should you wish to customize either of the scripts presented above, you will need two resources:
Last updated