Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Custom validator is not working, could you provide an example? #30

Closed
yasinAtlibra opened this issue Nov 2, 2017 · 3 comments
Closed
Labels

Comments

@yasinAtlibra
Copy link

yasinAtlibra commented Nov 2, 2017

I was trying to define an customer validator to check user's answer. If the answer is "yes","sure" ... then jump to one rule. Otherwise, terminate (which part I did not write yet).
Here is my code.

      bot.start();

     bot.validators.define("agreed", {
      validate: (expected, answer) => {
          console.log("answer:"answer)
          console.log("expected:"expected)
          return answer === "yes" || answer === "sure";
       },
          warning: "You disagree :( sorry!"
     });

The rules are as following.

        - message: How can I help you?
          name: hello
         type: String
         next: order
        

        - message: would like to order something?!
         name: order
         type: String
         -validators : 
             - agreed : true
               next: food

        - message: what do you like to have?

It works without that validator. I tried to print out inside the definition of validator, but nothing is printed.

Am I defining validator incorrectly?
Could you provide an example of validator or tell me what I am doing wrong here?

Thanks in advance!

@andersonba
Copy link
Owner

Your YAML example is invalid.
Check using a linter.

I have tested it with the following code:

- message: How can I help you?
  name: hello
  type: String

- message: Would like to order something?!
  name: order
  type: String
  validators:
    - agreed: true

- message: What do you like to have?
  type: String
  name: product

It works correctly.

But you can use the SingleChoice type to make this question:

- message: Would like to order something?!
  name: order
  type: SingleChoice
  options:
    - label: Yes
      next: products
    - label: No
      next: quit

@yasinAtlibra
Copy link
Author

Oops, yeah, the YAML has problem. Thanks.
I have some questions.

  1. is it possible to have some context sensitive dialogs? Such as, user input "help" in any time during the conversation, then the conversation jump to a particular dialog.
  2. is it always only one YAML file, or there are ways to manage multiple YAMLs to mimic a complex situations?

@andersonba
Copy link
Owner

andersonba commented Nov 8, 2017

  1. No yet, it's an awesome feature. The initial concept was rule-based, with a start and end. But we can have "subscribers" to control the current rule. I will create an issue. [edited] Make the bot passive #41
  2. YAML is a suggestion, you can create a conversation just using javascript. Currently, I'm working on "Flows", you'll be able to split the rules into separated flows, so, you can "download" the new flow via API and inject in the bot, or read from another file if you prefer. You can jump between rules and flows. [edited] feature: grouping rules into flows #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants