Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Slack Notification Filter using webtask.io
var request = require('request');
function shouldNotify(data) {
//replace this with the appropriate check/filter for you
return data.text.includes("should notify");
}
module.exports = function (context, done) {
if (context.data.token == context.data.EXPECTED_TOKEN) {
if (shouldNotify(context.data)) {
var url = context.data.WEBHOOK_URL;
var slackTeamBaseUrl = "https://" + context.data.team_domain + ".slack.com/";
var originalMessageLink = slackTeamBaseUrl + "archives/" + context.data.channel_name + "/p" + context.data.timestamp.replace(".", "");
var msg = {
attachments: [
{
"fallback": "<<plain text summary, used by clients that don't show attachments>> ",
"color": "#2992CC",
"author_name": context.data.user_name,
"author_link": slackTeamBaseUrl + "team/" + context.data.user_name,
"pretext": "<<your comment on the notification>>",
"text": context.data.text + '\n<' + originalMessageLink + '|Original Message>',
"ts": context.data.timestamp
}
]
};
request({url: url, method: 'POST', json: msg}, function (error, res, body) {
if (error) {
console.error(error);
}
done(null, null);
});
}
else {
done(null, null);
}
}
else {
console.error("invalid token:" + context.data.token);
done(null, null);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.