I have a simple code here. Im using https://github.com/yagop/node-telegram-bot-api telegram framework to make my first bot. I have array with 10 questions in it. So i can't understarnd what should i do if i want to start a new poll only after user answered for a previous one? My current code just list all 10 polls when i use /start. Here is my code (i used snippet cos its working correct only in this way):
bot.onText(/\/start (.+)/, (msg, [source, match]) => {
const { id } = msg.chat
if (match === test1Code){
for (let i=0; i<test1Questions.length; i++){
bot.sendPoll(id, test1Questions[i], pollOptions, {
is_anonymous: false
})
}
}
})
You need some sort of queue or flow manager. I can recommend node-telegram-operation-manager or mau query engine. Alternatively you can use a database to keep track of answers from a particular userId. With this approach you would send only the 1st poll. Then the rest of the polls would be sent based on the logic inside the poll event listener.