-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
conditional logic problems #42
Comments
I think its down to trying to capture the user's input chosen color here:
|
but when i remove that there's no way to capture the color in a variable for later, eg:
if they say |
also there are some problems 'returning' from a conditional block
however if I used an unknown color that fell through to the end it would work
so a bit puzzled on a few things here. |
Hey DC We're currently working on bubl, a codepen-like solution dedicated at designing botml-enabled bots. It's not polished just yet, but could improve your workflow by letting you test it in a REPL way, validate your scripts and observe all the conversational paths dynamically. Could you test your script there? |
Got it, I saw that on your notion page. The whole script is in the URL then? Hope that works :) so when the extra capture is there
everything will get captured there. https://github.com/codename-co/botml#conditional-branches
but I guess in that case you are then capturing and doing tests later against the variable itself. So this method works, it's just quite ugly to write:
So then the question is how to capture variables if just using normal expression matching without regexes |
It seems clear that the conditional branches should be more documented. You are right: there are two ways of using them, and a few things to know beforehand. The first thing to know is that in botml, any block is linear, meaning there is a single start and a single end. Except for conditional branches, where we can conditionally fork into external paths. To me the best example that describes it is the following authentication flow:
Here, we see that very linear flow that relies on a breakpoint But there is an edge case: which is actually knowing the passcode. And here we fork to an "external" branch (here it's at the end of the block, but it could be the reference of another workflow. This is the primary way of using conditional branches, where the capture/test is done at each step and enables the more flexibility. The second thing to know is that, because blocks are linear, they will "return" into their parent flow (if any) only when their main flow is reached; not the edge cases. Another way of using conditional branches is to capture first, like in the docs:
The best use case for this type of writing are validations. In such cases, we want to capture first, and fork to a branch only after a certain type of test. We found this way of handling tests and validations way clearer. And very handy in production for handling real complex use cases. But this can be subject to discussion, and I can understand that it may not the most clearer choice. |
when you say "edge case" you mean when any condition is met other than the default/fall-through? The other method you've shown is basically writing javascript inside ``` blocks. So switching back and forth between the two, where all logic is actually JS. That seems a bit messy... Did you think of other ways to handle conditionals? I'm sure there's a bot ruby-like DSL that has the basic flow-control of a script language, but without all the extra For example if a line did NOT have one of the special symbols could it just be treated as JS?
or
for one of our YAML interpreters we ended up using a mongo like matching syntax, which was easy to parse but really ugly to hand-write.
|
for reference:
conditionals aren't too bad and do allow you to also redirect
if they just got rid of that XMLy stuff and had |
I made a simple "survey" type bot, but the conditionals logic doesn't seem to work like expected. .bot script is here:
https://github.com/dcsan/botml/blob/master/examples/survey.bot
I run it with
nodemon --ext js,bot lib/cli.js examples/survey.bot
but I get a result like this on running it:
The text was updated successfully, but these errors were encountered: