Yoctol / bottender

⚡️ A framework for building conversational user interfaces.
https://bottender.js.org
MIT License
4.22k stars 334 forks source link

How to set a conversation flow? #109

Closed lucasansei closed 6 years ago

lucasansei commented 6 years ago

Can someone give me an example on how to build a multi-step conversation flow?

chentsulin commented 6 years ago

We have a lot of approaches using state to achieve step control. How about this one:

bot.setInitialState({
  step: 1,
});

bot.onEvent(async context => {
  switch (context.state.step) {
    case 1:
      // ...do something in step 1
      context.setState({ step: context.state.step + 1 });
      break;
    case 2:
      // ...do something in step 2
      context.setState({ step: context.state.step + 1 });
      break;
    case 3:
      // ...do something in step 3
      break;
  }
});
lucasansei commented 6 years ago

Thanks! This worked perfectly!

LintangWisesa commented 4 years ago

Hi, Sir @chentsulin. I'm new to Bottender.js. I've successfully created a simple Messenger chatbot using Express.js (+ngrok) with MongoDB database, but I have a little problem. How I can make a multi-step conversation flow in Bottender 1.4? I've tried use state, but still stucked. Thanks in advance.

chentsulin commented 4 years ago

Hi @LintangWisesa, you can find some latest examples there using the bottender-proposal-conversation module to make multi-step conversations. You may try and see if it works in your use case.

LintangWisesa commented 4 years ago

Great, thanks Sir @chentsulin