I'm building a Slack bot to facilitate the standups for teams of developers.
I want the bot to run async and not have to wait for one person's response before it starts interviewing others.
Here's what I think is the solution for it, however I'm not really sure. I would appreciate a second eye on this.
const users = await Users.getActive();
for(let user of users) {
const message_obj = { user: user.slack_id };
const questions = await Questions.getByTeamId(user.team.id);
bot.startPrivateConversation(message_obj, function(err, convo) {
if(!err){
for (let question of questions) {
convo.addQuestion(question.text, function (response, convo) {
convo.next();
}, {key: `${question.id}`}, `default`);
}
convo.on(`end`, async function (convo) {
if (convo.status == `completed`) {
const report = await Reports.createReport(user.id);
for (let question_id in convo.extractResponses()) {
if (convo.extractResponses().hasOwnProperty(question_id)) {
await Responses.createResponse(question_id, report.id, convo.extractResponses()[question_id]);
}
}
convo.say(`Nice Job! 👍`);
} else {
// this happens if the conversation ended prematurely for some reason
convo.say(`OK, nevermind!`);
}
});
}else {
bot.botkit.log(`Failed to start a conversation :(`, err);
}
});
}