Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indirect/77c314ab67368cdb0ea0d5a7761b3c07 to your computer and use it in GitHub Desktop.
Save indirect/77c314ab67368cdb0ea0d5a7761b3c07 to your computer and use it in GitHub Desktop.
Slack Notification Filter using webtask.io
var request = require('request');
function shouldNotify(data) {
return data.text.includes("andre") || data.text.includes("indirect");
}
module.exports = function (context, done) {
console.log(JSON.stringify(context));
if (context.body.token === context.data.EXPECTED_TOKEN) {
if (shouldNotify(context.body)) {
var url = context.data.WEBHOOK_URL;
var slackTeamBaseUrl = "https://" + context.body.team_domain + ".slack.com/";
var originalMessageLink = slackTeamBaseUrl + "archives/" + context.body.channel_name + "/p" + context.body.timestamp.replace(".", "");
var msg = {
attachments: [
{
"fallback": "<<plain text summary, used by clients that don't show attachments>> ",
"color": "#2992CC",
"author_name": context.body.user_name,
"author_link": slackTeamBaseUrl + "team/" + context.body.user_name,
"pretext": "",
"text": context.body.text + '\n<' + originalMessageLink + '|Original Message>',
"ts": context.body.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.body.token);
done(null, null);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment