0

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
            })
        }
    }
})
  • 1
    Have tried to build a conversational dialog? You need to keep chat state somewhere. – wowkin2 Sep 09 '20 at 09:27
  • In your backend you need to implement the logic to keep asking questions until (10 questions?) the quiz is completed and can take a different action (provide results? ask feedback?) – Beppe C Sep 11 '20 at 11:42

1 Answers1

0

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.

Mohamed Sohail
  • 1,659
  • 12
  • 23