L
L
Lynatik0012020-07-17 17:58:05
Node.js
Lynatik001, 2020-07-17 17:58:05

Telegram bot and "Scripts" how to properly organize the transition between them?

On my main page, index.js takes me to the Scenegenerator file at startup (the scenes are placed there)

const currScene = new SceneGenerator();
const mainMenuScene = currScene.mainMenu(Usrmenu);
const entryMenuScene = currScene.entryMenu(arrayOfLabel);
const bot = new Telegraf(config.tgToken);
const stage = new Stage([
  mainMenuScene,
  entryMenuScene,
  currScene.controlPanel(Botmenu, usrPanelKeyboard),
]);

bot.use(session());
bot.use(stage.middleware());
bot.command('mainMenu', (ctx) => ctx.scene.enter('mainMenu'));
bot.launch();
bot.start(async (ctx) => {
  user1.checkAddUser(ctx.from);
  ctx.scene.enter('entryMenu');
});


And then in scripts to process transitions on any menus. No sooner said than done.
Made it seem logical. but I have a transition from one menu to another - this is a transition from one scene to another.
When I thought that the scene itself - a personal account - like other similar multifunctional ones, would take up a lot of space, and, accordingly, it would be a sin to store it in one file. you need to share to make a scene file - a personal account - that it will have in itself, all scenes related specifically to the LC. Trouble got up in the fact that Telegraf just doesn’t shine with documentation and examples.

Here's a scene in Scenegenerator that jumps to a scene in another file.
controlPanel(Botmenu, usrPanelKeyboard) {
    const controlPanelScene = new Scene('controlPanel');

    const BS = new BotScene();
    const Botscene = new Stage([BS.controlPanelCurrBot(usrPanelKeyboard)]);
    controlPanelScene.use(Botscene.middleware());
    // controlPanelScene.use(() => new Stage([BotScene.mainMenu()]).middleware());
    controlPanelScene.enter(async (ctx) => {
      await ctx.reply(`this :\n${ctx.from.first_name} (@${ctx.from.username})`, Botmenu);
    });
    controlPanelScene.leave((ctx) => ctx.reply('Bye'));
    // controlPanelScene.action('controlbot', (ctx) => controlPanelScene.scene.enter('BotScene'));

    controlPanelScene.action('controlbot', (ctx) => ctx.scene.enter('controlCurrBot'));
    controlPanelScene.on('message', (ctx) => ctx.scene.reenter());
    return controlPanelScene;
  }


here is the scene in another file. when switching to this scene, only controlPanelScene.enter(...) is displayed - from the text and keyboard outputs. but then the scene ends? it doesn't handle controlPanelScene.leave((ctx) => ctx.reply('Bye')); not controlPanelScene.on('message', async (ctx) => ctx.reply('dialog not out'));
She ends just like that. and now you can /start will refer to the original scene. Please tell me what is the bug. how to call previous scenes (which are in other files) - exits without overriding controlPanelScene.use(Botscene.middleware()); - because it seems to me that the share of the blame lies with the redefinition of this.

controlPanelCurrBot(usrPanelKeyboard) {
    const controlPanelScene = new Scene('controlCurrBot');
    const dialog = ` №1 /change_img`;
    controlPanelScene.enter(async (ctx) => {
      await ctx.reply(dialog, usrPanelKeyboard);
    });
    controlPanelScene.leave((ctx) => ctx.reply('Bye'));
    controlPanelScene.on('message', async (ctx) => ctx.reply('dialog not out'));
    return controlPanelScene;
  }


Of course, I can add all the scenes to the original file.

const stage = new Stage([
  mainMenuScene,
  entryMenuScene,
  currScene.controlPanel(Botmenu, usrPanelKeyboard),
.....
]);

and supposedly continue all this there but xs ...

Advise what I'm doing wrong, what to do better, or maybe I just do very much abusing such concepts as "scene"?

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