N
N
Nikolai2020-12-16 16:12:40
JavaScript
Nikolai, 2020-12-16 16:12:40

How to track exits from a scene in telegraf?

There is an external scene StartScene.

It starts the other two scenes Requests and Signin.

How to track the exit from these scenes in StartScene?

const bot = new Telegraf(CONFIG.BOT_TOKEN);

// Создаем сцены
const requests = createRequestsScene();
const signIn = createSignInScene();
const startScene = new BaseScene("StartScene");
const stage = new Stage([startScene, signIn, requests]);

// Настройка бота
bot.use(session());
bot.use(stage.middleware());

bot.use(async (ctx, next) => ctx.scene.enter("StartScene"));

startScene.enter(async (ctx) => {
  // Проверка на доступ
  await Helper.checkUser(ctx.message.from).then(async ({ isHaveAccess }) => {
    if (isHaveAccess) {
      ctx.scene.enter("Requests");
    } else {
      ctx.scene.enter("SignIn");
    }
  });
});

bot.launch().then(() => console.log("Bot started!"));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question