I'm using the Slack API to get a link from a Slack workspace. It works except when a message is posted, it triggers more then once. Everytime. Here is the code I have:
exports.slack = (req , res) => {
var message = req.body;
if (message.challenge) {
res.send(message.challenge);
} else if (message.event.type == 'message_received') {
if (message.event.text.includes('<')) {
// Link
console.log('NEW LINK');
var link = message.event.text.slice(1, -1);
getArticleInfo(link, (error, body) => {
if (error)
console.error(error);
else {
newArticleToDB(body , link, req);
}
});
}
}
}
Everytime a new message is posted I get a 'NEW LINK' log multiple times. Any ideas where to look for this issue?
Thanks.