Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add new type of scenes #538

Open
rtkid-nt opened this issue Mar 31, 2023 · 0 comments
Open

Add new type of scenes #538

rtkid-nt opened this issue Mar 31, 2023 · 0 comments
Labels
package: @vk-io/scenes Issues related to @vk-io/scenes

Comments

@rtkid-nt
Copy link

rtkid-nt commented Mar 31, 2023

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!');
});
@rtkid-nt rtkid-nt added the package: @vk-io/scenes Issues related to @vk-io/scenes label Mar 31, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
package: @vk-io/scenes Issues related to @vk-io/scenes
Projects
None yet
Development

No branches or pull requests

1 participant