-
Notifications
You must be signed in to change notification settings - Fork 11
rocket.chat parser script example
Christoph Bajohr edited this page Apr 12, 2016
·
1 revision
Example parser script for the incoming webhook in rocket chat:
class Script {
process_incoming_request({ request }) {
var content = request.content;
var message_icon = ":package:";
var attachments = [{}];
var text = '';
var username = 'Capistrano: '+content.event.hook;
var color = '#f0ad4e';
att_text = content.event.text;
if(content.event.hook == 'finished'){
color = '#5cb85c';
message_icon = ':postal_horn:';
}
else if(content.event.hook == 'failed'){
color = '#d9534f';
message_icon = ':rotating_light:';
}
attachments = [{
"color": color,
"text": att_text,
"fields": [{}]
}];
// DEBUG JSON OUTPUT
// debug = "\n\n\n DEBUG:\n\n content: ```JSON\n"+JSON.stringify(content)+"```"
// text += debug;
// background debug
console.log(content);
return {
content: {
username: username,
icon_emoji: message_icon,
text: text,
attachments: attachments
}
};
}
}