Skip to content

Instantly share code, notes, and snippets.

@csepulv
Last active November 17, 2022 22:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save csepulv/7174b19c1fbe219f057f1c89b1abc806 to your computer and use it in GitHub Desktop.
Save csepulv/7174b19c1fbe219f057f1c89b1abc806 to your computer and use it in GitHub Desktop.
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