Closed mattw114862 closed 3 years ago
This is most likely due to the fact that your bot is "hearing" messages from itself. Make sure you are not processing messages FROM the bot.
After playing around with it I was able to get it fixed. It seems to be an issue with the slack API and how it handles retries in POST. I noticed on Ngrok that it was posting multiple 200 OK responses. I can't really say for sure if it is because it was the bot trying to respond to it's on query, however, I did notice that it only seemed to do this when I had Microsoft's QnA Maker integrated into the bot's responses.
Doing some googling on other people reporting the same issue I was finally able to stop the repeats by adding a few snippets:
// Create an express server with json and urlencoded body parsing
const webserver = express();
webserver.use((req, res, next) => {
res.set("X-Slack-No-Retry", "1"); // disable retries
res.status(200).json();
req.rawBody = '';
req.on('data', function (chunk) {
req.rawBody += chunk;
});
next();
return;
});
webserver.use(express.json());
webserver.use(express.urlencoded({ extended: true }));
Hope this helps any one else who experiences the same issue.
Ah! This happens when the 200 response takes too long to be sent, which can happen when using external services like QNA Maker.
Thanks for the follow-up!
Integrating QnA Maker with Slack through botkit seems to cause an issue where the response from the bot keeps repeating itself. I am unsure of how to resolve this. I thought maybe it was reading the messages of itself and responding back but I am not so sure. I also have the same integration for teams and twilio both which work fine.