@gauthier

Почему может быть подобная бага в телеграм боте?

Пишу телеграм бота, и возникла ошибка с выходом из сцены.

При нажатии на /start все отрабатывает хорошо, но если сразу нажать на кнопку из keyboard, то снова выведется стартовое сообщение. При этом при повторном нажатии все отрабатывает хорошо. Так же из кнопкой "Назад", если захочу выйти из сцены до полного завершения сценария.

Стек: Node.js и Telegraf

const getBackKeyboard = () => {
    const backKeyboard = Markup.keyboard([buttons.back]);
    return backKeyboard.resize();
}

const getDefaultKeyboard = () => {
    const defaultKeyboard = Markup.keyboard([
        [buttons.how_buy_toncoin, buttons.wallet]
    ]);
    return defaultKeyboard.resize();
}

const startScene = new WizardScene(
    'START_SCENE',
    async (ctx) => {
        await ctx.replyWithHTML(text.welcome, getDefaultKeyboard());
        return ctx.scene.leave(ctx);
    }
);

const walletScene = new WizardScene(
    'WALLET_SCENE',
    async (ctx) => {
        await ctx.reply(`text.wallet_how_balance`, getBackKeyboard());
        return ctx.wizard.next();
    },
    async (ctx) => {
        const wallet = ctx.message.text;

        await fetchAddressInformation(wallet).then(({ result }) => {
                const balance = (result.balance * 1e-9).toFixed(2);

                ctx.reply(`text.balance`, {parse_mode: 'HTML'});
                return ctx.scene.leave(ctx);
        }).catch(() => {
            ctx.reply(`text.wallet_incorrect`);
            return;
        });
    }
);
walletScene.hears(buttons.back, leave());

const howBuyToncoinScene = new WizardScene(
    'HOW_BUY_TONCOIN_SCENE',
    async (ctx) => {
        await ctx.reply(text.how_buy_toncoin, {
            parse_mode: 'HTML',
            disable_web_page_preview: true
        });
        return ctx.scene.leave();
    }
);

const stage = new Stage([ walletScene, startScene, howBuyToncoinScene ]);

const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN);
bot.use(session(), stage.middleware());

bot.start(async (ctx) => ctx.scene.enter('START_SCENE'));
bot.hears(buttons.wallet, async (ctx) => ctx.scene.enter('WALLET_SCENE'));
bot.hears(buttons.back, (ctx) => ctx.reply(text.welcome_back, getDafaultKeyboar()));
bot.hears(buttons.how_buy_toncoin, async (ctx) => ctx.scene.enter('HOW_BUY_TONCOIN_SCENE'));
bot.launch();
  • Вопрос задан
  • 178 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы