I am trying to stopPoll() function but I am getting error
ETELEGRAM: 400 Bad Request: poll can't be stopped
I want to stop the poll when a desired person (userId) answers the poll.
Here is my function which create the poll and stops the poll.
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);
})
})
}
Note: I save the pollMessageId from the response when poll is sent, then I pass that pollMessageId to stop the poll.
Am I doing something wrong here?
Here is the completed stacktrace.
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)
from ETELEGRAM: 400 Bad Request: poll can't be stopped
No comments:
Post a Comment