0

I make a telegram bot via Telegraf.js, and faced such problem: I have 4 buttons, one of which starts Wizard Scene. Other 3 buttons (common keyboard, not an inline one) should run some functions, but they do that after second click (first one is to quit the wizard and second - normal work of those). What do I want is to make them work after first click, like I'm not in a wizard.

Here is a small example. chooseSettingsAction should be like a handler for messages or callbacks. If the bot receives text, handleText function starts. If user clicks 'settings' it's ok, just reentering wizard. But, for example, 'exchange' causes scene leave but that's all, despite bot has a handler for this text that works properly when I click at 'exchange' second time

const {Scenes} = require('telegraf')
const {fmt, bold} = require("telegraf/format");
 
const settingsWizard = new Scenes.WizardScene(
    'settingsWizard',
    async (ctx) => await showSettingsMenu(ctx),
    async (ctx) => await chooseSettingsAction(ctx),
)
 
const showSettingsMenu = async (ctx) => {
    // some code
    return ctx.wizard.next()
}
 
const chooseSettingsAction = async (ctx) => {
    
    if(ctx.message){
        await handleText(ctx)
    }else if(ctx.callbackQuery.data){
        await handleCallback(ctx)
    }
}
 
const handleText = async (ctx) => {
 
    switch (ctx.message.text) {
        case '⚙️ Settings':
            await ctx.scene.reenter()
        // all other buttons have their own handlers
        case ' Exchange':
            await ctx.scene.leave()
            // some button actions should run here
            break
    }
}
 
const handleCallback = (ctx) => {
    
}
 
module.exports = {settingsWizard}

0 Answers0