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 and token you copied from the Rocket.Chat setting
Select the list of events you want to be notified on and Add webhook
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
Sending outgoing webhooks only works on public repositories
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 like https://api.github.com/repos/RocketChat/Rocket.Chat
Enable Scripts
Use this Script to listen for commands pr ls, pr list and help
/* exported Script *//* globals Store */classScript {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: