WizardScene: Handle question and answer in the same step

See original GitHub issue

Is it possible to send the question (e.g. ‘Please enter your email adress’) and handle the answer (‘abc@gmx.com’) in the same function in a SceneWizard?

So (in simplified) code it would look kinda like this:

function setup_email_adress() {
  send_message("Please enter your email adress");
  on_message_receive(function(email) {
    if (is_valid_email(email)) {
      save_email_into_db(email)
      ctx.wizard.next()
    } else {
      send_message("Please enter a valid email adress")
    }
  }
}

function setup_password() {
  ....
}

setup_wizard = new WizardScene('setup',
  setup_email_adress,
  setup_password,
  ...
);

I am sure, that it would be easy to do a workaround, but I wonder if there is an intended way to do this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
Otto-AAcommented, May 16, 2018

Yeah, but can this help me achieve a chat like this?

Me:     /test
Bot:    Please enter your first name
Me:     John
Bot:    Please enter your last name
Me:     Doe
Bot:    Finished

I am currently only able do get following structure (without doing something hacky like ctx.wizard.steps[ctx.wizard.cursor](ctx);):

Me:     /test
Bot:    Please enter your first name
Me:     John
Me:     Please go ahed, dear bot
Bot:    Please enter your last name
Me:     Doe
Me:     Please go ahead, dear bot
Bot:    Finished
2reactions
Otto-AAcommented, May 14, 2018

I am not sure if this solves my problem: If I ask multiple questions one after another and implement it in your way, I get the following chat result

grafik The problem about this, is that I don’t want the user to write this ok, but instantly trigger the next function.

My current workaround is to call ctx.wizard.next() and afterwards ctx.wizard.stepsctx.wizard.cursor;` to first increase the cursor and then call the next function.

So my current code is following (which works fine, but doesn’t seem to be right imo):

const test_setup = new WizardScene('test_setup',
  function(ctx) {
    ctx.reply('Enter first name')
    ctx.wizard.next()
  },
  function(ctx) {
    // Do something with the first name
    ctx.wizard.next();
    ctx.wizard.steps[ctx.wizard.cursor](ctx);
  }, 
  function(ctx) {
    ctx.reply('Enter last name')
    ctx.wizard.next()
  },
  function(ctx) {
    // Do something with the last name
    ctx.wizard.next();
    ctx.wizard.steps[ctx.wizard.cursor](ctx);
  },
  function(ctx) {
    ctx.reply('Done');
    ctx.wizard.next();
  }
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Telegraf.js: leave WizardScene with a button - Stack Overflow
I would put a button after a message in a WizardScene with a "Cancel" ... is undefined and go back to the previous...
Read more >
Class WizardScene<C> - Telegraf
Registers middleware for handling matching callback queries. Parameters. triggers: Triggers<C>. Rest .
Read more >
Telegraf VS Node-Telegram-Bot-API - DEV Community ‍ ‍
Telegraf Scene is the same, but let's display it in code. This library has two types of scene: Base Scene and Wizard Scene....
Read more >
cjd - River Thames Conditions - Environment Agency - GOV.UK
Charlie boutique hampstead, Konstanze kuss, Keytrain answers level 5 reading, ... Toilet tank float ball, Single serving question sites, Or2 program, ...
Read more >
telegraf@4.11.2 - jsDocs.io
Generates middleware for handling provided update types. ... Note: The Bot API must receive an answer within 10 seconds after the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found