Answer the question
In order to leave comments, you need to log in
Telegram bot on NodeJS?
I use this library node-telegram-bot-api , via polling.
There was a question how to make that after entering / setname , the bot prompted to enter a name. If, for example, within 30 seconds, the user did not enter anything, then the command was canceled. How can I do that?
Answer the question
In order to leave comments, you need to log in
What exactly is the problem ?, it seems like the solution is obvious, suggest the user to enter a name and after 30 seconds they do not process it anymore and display a warning to the user if they want.
this lib has this type
https://github.com/mdibaiee/node-telegram-api/wiki...
It would be more correct to enter a name next to the command itself
. Although it is possible like this:
var stateSetName = false;
bot.onText(/\(.*)/, function (msg, match) {
if(!stateSetName)return;
var name = match[1];
});
bot.onText(/\/setname/, function (msg, match) {
var fromId = msg.from.id;
bot.sendMessage(fromId, "Введите имя");
stateSetName =true;
setTimeout(function(){ bot.sendMessage(fromId, "Отмена!"); stateSetName =false;},30000);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question