Answer the question
In order to leave comments, you need to log in
Is it possible to access a variable inside a function, or how else to solve the problem?
I create a telegram bot on node js
, there is an array with Arr objects, and the getRandomObj function, which returns a random object from this array,
in theory, the bot displays a message, the timer should immediately start,
then the person presses the button either ready or canceling, depending on what will be apply further actions
bot.onText(/\/go/, function(msg, match) {
var obj= getRandomObj();
id = msg.chat.id;
title = obj.title;
time = obj.time;
var message = title + ' for ' + time/1000/60 + ' mitute.';
var options = {
reply_markup: JSON.stringify({
inline_keyboard: [
[{ text: 'Готово!', callback_data: 'done' }],
[{ text: 'Отменить', callback_data: 'reject' }]
]
})
};
bot.sendMessage(id, message, options);
});
var timerId = setTimeout( function(){
bot.sendMessage(id, 'time is over!');
}, time)
bot.on('callback_query', function(cb) {
if (cb.data === 'done') {
//тут надо остановить таймер
bot.sendMessage(id, 'done');
} else{
//и тут
bot.sendMessage(id, 'отклонено');
}
});
Answer the question
In order to leave comments, you need to log in
you can shove the id of the timers into the global hash array with the chat key. well, or some other "sessions" to fasten, if the library supports. telegraf seems to support
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question