问题描述
我这里有一个简单的代码.我使用 https://github.com/yagop/node-telegram-bot-api 电报框架来制作我的第一个机器人.我有一个包含 10 个问题的数组.所以我无法理解如果我只想在用户回答上一个投票后才开始新的投票,我该怎么办?当我使用/start 时,我当前的代码只列出所有 10 个民意调查.这是我的代码(我使用了代码片段,因为它只能以这种方式正确工作):
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
})
}
}
})
推荐答案
您需要某种队列或流管理器.我可以推荐 node-telegram-operation-manager或 mau 查询引擎.或者,您可以使用数据库来跟踪来自特定用户 ID 的答案.使用这种方法,您将只发送第一次民意调查.然后将根据 poll 事件侦听器内部的逻辑发送其余的 poll.
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.
这篇关于如何在回答上一个投票后才开始新的投票?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!