Answer the question
In order to leave comments, you need to log in
How to organize an exit button in a tg bot?
At the moment I have:
When loading scenes, I put:
scene.on("message", async (ctx, next) => await utils.keyboard.exitHandler(ctx, next))
scene.on("message", async (ctx, next) => await utils.keyboard.backHandler(ctx, next))
module.exports = async (ctx, next) => {
if("text" in ctx.message){
if(ctx.message.text === ctx.i18n.t("exitButton")){
if(++ctx.session.count % 2 === 0){
ctx.session.count = 0;
return next()
}
//get state
if(ctx.session.scenesHistory.length - 2 >= 0){
let last = ctx.session.scenesHistory[ctx.session.scenesHistory.length - 2]
ctx.session.scenesHistory = ctx.session.scenesHistory.splice(ctx.session.scenesHistory.length - 2, 1)
return ctx.scene.enter(last)
}else {
return ctx.scene.enter("start")
}
}
}
return next()
}
module.exports = async (ctx, next) => {
if("text" in ctx.message){
if(ctx.message.text === ctx.i18n.t("backButton")){
//get state
if(ctx.session.__scenes.cursor !== 1){
ctx.wizard.selectStep(ctx.session.__scenes.cursor - 2)
}else {
ctx.reply("Не могу перейти на предыдущий этап. Используйте кнопку " + ctx.i18n.t("exitButton"))
}
return next()
}
}
return next()
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question