问题描述
我正在尝试调用telegramBot.stopPoll()
函数,但出现错误
ETELEGRAM: 400 Bad Request: poll can't be stopped
当想要的人(userId)回答调查时,我想停止调查。
这是我创建轮询并停止轮询的功能。
function sendJacuzziMaintenancePoll(chatId,userName){
return new Promise(function (resolve,reject) {
var question = "Jacuzzi Maintenance QA checklist. @"+userName+" Please mark you think you have done.";
var answers = ["Water quality check","Post the picture of the PH test stripe to the Telegram group","Check the current temperature and post the picture to the Telegram group"];
var pollMessageId = null;
var reply_markup = JSON.stringify({
'force_reply': true,'selective' : true
});
const opts = {
'is_anonymous': false,'allows_multiple_answers': true,'reply_markup': reply_markup
};
// set poll_answer listener so that we can stop the poll when answered by the desired user
// This will be called when a user answer a poll
telegramBot.addListener("poll_answer",function (response) {
console.log("poll_answer response",response);
// Remove listner first
telegramBot.removeListener("poll_answer");
// Check the same user
if (userName === response.user.username){
let message = "@" + userName + " " + STRINGS.BOT_MESSAGE_THANKYOU_FOR_POLL_Vote;
sendMessage(chatId,message);
//Stop the POLL
telegramBot.stopPoll(chatId,pollMessageId);
} else {
let message = "@" + userName + " --" + STRINGS.BOT_MESSAGE_THANKYOU_FOR_POLL_Vote;
sendMessage(chatId,message);
}
})
telegramBot.sendPoll(chatId,question,answers,opts).then(function(response){
pollMessageId = response.message_id;
resolve(response);
}).catch(function(err){
reject(err);
})
})
}
注意:发送轮询后,我将从响应中保存pollMessageId,然后将其传递给pollMessageId以停止轮询。
我在这里做错什么了吗?
这是完整的堆栈跟踪。
Unhandled rejection Error: ETELEGRAM: 400 Bad Request: poll can't be stopped
at /Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/node-telegram-bot-api/src/telegram.js:284:15
at tryCatcher (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/qadirhussain/workspace/nodeJS/qRoomCleaningBot/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:456:21)
解决方法
我不确定,但我相信在处理ForceReply
标记时这是Telegram Bot API实现的一个错误(因为其他reply_markup
选项(如内联按钮)可以正常工作)。删除该标记,它应该可以正常工作。
...
const opts = {
'is_anonymous': false,'allows_multiple_answers': true,// 'reply_markup': reply_markup // remove this
};