Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ServiceNow SlackMessage #servicenow #slack #scriptinclude
// ServiceNow Slack Message
// Script Include
// SlackMessage.js
// Rich Bocchinfuso - 2017/05/10
var SlackMessage = Class.create();
var iconurl = 'http://www.gb-advisors.com/wp-content/uploads/2016/06/servicenow-sm-icon.png';
var emoji = ':warning:';
var channel = '#test';
var username = 'ServiceNow';
var endpoint = '';
gs.print(iconurl);
gs.print(emoji);
gs.print(channel);
gs.print(username);
gs.print(endpoint);
SlackMessage.prototype = {
'initialize': function() {
if (gs.getProperty('slack_message.default_icon_url') != '') {
this.payload.icon_url = gs.getProperty('slack_message.default_icon_url');
}
else if (gs.getProperty('slack_message.default_icon_emoji') != '') {
this.payload.icon_emoji = gs.getProperty('slack_message.default_icon_emoji');
}
},
'send': function (text, channel) {
// Set the text and channel (or fall back to defaults)
this.payload.text = text || this.payload.text;
this.payload.channel = channel || this.payload.channel;
// Encode the payload as JSON
var SNJSON = JSON; // Workaround for JSLint warning about using JSON as a constructor
var myjson = new SNJSON();
var encoded_payload = myjson.encode(this.payload);
// Create and send the REST Message
var msg = new sn_ws.RESTMessageV2();
msg.setEndpoint(this.endpoint);
msg.setHttpMethod(this.method);
msg.setRequestBody(encoded_payload);
var res = msg.execute();
return res;
},
'endpoint': endpoint,
'method': 'post',
'payload': {
'channel': channel,
'username': username,
'text': '',
'attachments': []
},
'type': 'SlackMessage'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment