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)