Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
slack events api triggers multiple times by one message

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.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I added res.sendStatus(200) and now everything works as expected. Here's the code:

exports.slack = (req , res) => {    
var message = req.body;
res.sendStatus(200);

if (message.challenge) {
    res.send(message.challenge);

} else if (message.event.type == 'message' && message.event.subtype != 'message_changed') {
    if (message.event.text && 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);
            }
        });  
    }
}
over 4 years ago · Santiago Trujillo Report

0

I had the issue, thank for @taylor-singletary suggestion. I had to print

console.log('Request Headers::: ', JSON.stringify(req.headers));

to look for

"x-slack-retry-num":"1"

To get header value, simply refer to this question: How to extract request http headers from a request using NodeJS connect

over 4 years ago · Santiago Trujillo Report

0

I had the same issue receiving multiple events. Turned out I was receiving 1 event per bot user event I added. I don't know if this is the API's intended behavior, but I decided to remove all events except app_mention and now I only receive 1 event.

Subscribe to bot events

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!