negezor / vk-io

Modern VK API SDK for Node.js
https://npm.im/vk-io
MIT License
549 stars 85 forks source link

Add new type of scenes #538

Open rtkid-nt opened 1 year ago

rtkid-nt commented 1 year ago

For example i will use telegraphjs

What we have

import { Scenes } from 'telegraf';

const contactDataWizard = new Scenes.WizardScene(
  'CONTACT_DATA_WIZARD_SCENE_ID', // first argument is Scene_ID, same as for BaseScene
  (ctx) => {
    ctx.reply('What is your name?');
    ctx.wizard.state.contactData = {};
    return ctx.wizard.next();
  },
  (ctx) => {
    // validation example
    if (ctx.message.text.length < 2) {
      ctx.reply('Please enter name for real');
      return; 
    }
    ctx.wizard.state.contactData.fio = ctx.message.text;
    ctx.reply('Enter your e-mail');
    return ctx.wizard.next();
  },
  async (ctx) => {
    ctx.wizard.state.contactData.email = ctx.message.text;
    ctx.reply('Thank you for your replies, we'll contact your soon');
    await mySendContactDataMomentBeforeErase(ctx.wizard.state.contactData);
    return ctx.scene.leave();
  },
);

What i think is need

import { Scenes } from 'telegraf';

const scenarioTypeScene = new Scenes.BaseScene('SCENARIO_TYPE_SCENE_ID');

scenarioTypeScene.enter((ctx) => {
  ctx.session.myData = {};
  ctx.reply('What is your drug?', Markup.inlineKeyboard([
    Markup.callbackButton('Movie', MOVIE_ACTION),
    Markup.callbackButton('Theater', THEATER_ACTION),
  ]).extra());
});

scenarioTypeScene.action(THEATER_ACTION, (ctx) => {
  ctx.reply('You choose theater');
  ctx.session.myData.preferenceType = 'Theater';
  return ctx.scene.enter('SOME_OTHER_SCENE_ID'); // switch to some other scene
});

scenarioTypeScene.action(MOVIE_ACTION, (ctx) => {
  ctx.reply('You choose movie, your loss');
  ctx.session.myData.preferenceType = 'Movie';
  return ctx.scene.leave(); // exit global namespace
});

scenarioTypeScene.leave((ctx) => {
  ctx.reply('Thank you for your time!');
});