Description
Hello Rocket.Chat forum,
I’m not sure where to begin, so I hope this is the right place.
Google wasn’t really helpful, I only found:
I’m also new at JSON data, but I tried using https://jsonlint.com/ to validate it, which hasn’t failed. So I’m thinking it’s the script, but I can’t tell
I’m trying to send a webook from Tautulli to Rocket.Chat, from what I can tell, it’s correctly set up. I’ll show down in aditional information what has been setup.
I’m new at this, so I think I’ve done it the wrong way, but I can’t tell.
I’ve tried enabling all the logging, but it doesn’t pick anything up about the webhook from what I can tell.
Any ideas where to start, or even know how to make it work?
Server Setup Information
- Version of Rocket.Chat Server: 3.17.0
- Operating System: Ubuntu Server 20.04
- Deployment Method: Running on a VM
- Number of Running Instances: 1
- DB Replicaset Oplog: I’m not sure where to find it.
- NodeJS Version: v12.22.4
- MongoDB Version: v4.4.8
- Proxy: NPM (Nginx with Let’s Encrypt)
- Firewalls involved: UFW (disabled atm.)
Any additional Information
I’ve set it up following this guide, except from step 6 and afterwards:
The script I’m using is the one I found here: Integrations - Rocket.Chat Docs
/* exported Script */
/* globals console, _, s, HTTP */
/** Global Helpers
*
* console - A normal console instance
* _ - An underscore instance
* s - An underscore string instance
* HTTP - The Meteor HTTP object to do sync http calls
*/
class Script {
/**
* @params {object} request
*/
prepare_outgoing_request({ request }) {
// request.params {object}
// request.method {string}
// request.url {string}
// request.auth {string}
// request.headers {object}
// request.data.token {string}
// request.data.channel_id {string}
// request.data.channel_name {string}
// request.data.timestamp {date}
// request.data.user_id {string}
// request.data.user_name {string}
// request.data.text {string}
// request.data.trigger_word {string}
let match;
// Change the URL and method of the request
match = request.data.text.match(/^pr\s(ls|list)/);
if (match) {
return {
url: request.url + "/pulls",
headers: request.headers,
method: "GET",
};
}
// Prevent the request and return a new message
match = request.data.text.match(/^help$/);
if (match) {
return {
message: {
text: [
"**commands**",
"```",
" pr ls [open|closed|all] List Pull Requests",
"```",
].join("\n"),
// "channel": "#name-of-channel",
// "attachments": [{
// "color": "#FF0000",
// "author_name": "Rocket.Cat",
// "author_link": "open.rocket.chat/direct/rocket.cat",
// "author_icon": "open.rocket.chat/avatar/rocket.cat.jpg",
// "title": "Rocket.Chat",
// "title_link": "rocket.chat",
// "text": "Rocket.Chat, the best open source chat",
// "fields": [{
// "title": "Priority",
// "value": "High",
// "short": false
// }],
// "image_url": "rocket.chat/images/mockup.png",
// "thumb_url": "rocket.chat/images/mockup.png"
// }]
},
};
}
}
/**
* @params {object} request, response
*/
process_outgoing_response({ request, response }) {
// request {object} - the object returned by prepare_outgoing_request
// response.error {object}
// response.status_code {integer}
// response.content {object}
// response.content_raw {string/object}
// response.headers {object}
var text = [];
response.content.forEach(function (pr) {
text.push(
"> " +
pr.state +
" [#" +
pr.number +
"](" +
pr.html_url +
") - " +
pr.title
);
});
// Return false will abort the response
// return false;
// Return empty will proceed with the default response process
// return;
return {
content: {
text: text.join("\n"),
parseUrls: false,
// "attachments": [{
// "color": "#FF0000",
// "author_name": "Rocket.Cat",
// "author_link": "open.rocket.chat/direct/rocket.cat",
// "author_icon": "open.rocket.chat/avatar/rocket.cat.jpg",
// "title": "Rocket.Chat",
// "title_link": "rocket.chat",
// "text": "Rocket.Chat, the best open source chat",
// "fields": [{
// "title": "Priority",
// "value": "High",
// "short": false
// }],
// "image_url": "rocket.chat/images/mockup.png",
// "thumb_url": "rocket.chat/images/mockup.png"
// }]
},
};
}
}
The Webhook URL is (without the exact info):
http://192.168.X.X:3000/hooks/YXYZ
The Curl is:
curl -X POST -H 'Content-Type: application/json' --data \
'{
"text": "Example message",
"attachments": [
{
"title": "Rocket.Chat",
"title_link": "rocket.chat",
"text": "Rocket.Chat, the best open source chat",
"image_url": "/images/integration-attachment-example.png",
"color": "#764FA5"
}
]
}' http://192.168.X.X:3000/hooks/YXYZ
The JSON headers in Tautulli is:
Content-Type: application/json
Accept: application/json
The JSON Data int Tautulli and the example payload in Rocket.Chat is:
{
"text": "Example message",
"attachments": [
{
"title": "Rocket.Chat",
"title_link": "rocket.chat",
"text": "Rocket.Chat, the best open source chat",
"image_url": "/images/integration-attachment-example.png",
"color": "#764FA5"
}
]
}