简体   繁体   中英

Rivescript: Using Keyword Triggers in Conditional Responses

I am working on a chatbot with Rivescript and am trying to use keyword triggers in conditional responses.

In the tutorial on the site, it is explained that you can use...

[*] optionals to ignore parts of a message...

This works fine in the initial prompt + [*] you [*] but when I try to use this method to capture any response that contains yes or no as part of a conditional response it seems to break it? I don't get an error code, but it simply defaults to - So, back to the matter at hand... as a response.

  + [*] you [*]
  - Oh, so we're talking about me now?

  + *
  % oh so we are talking about me now
  * <star> == [*] no [*]  => Whatever...
  * <star> == [*] yes [*] => This should be fun.{topic=myself}
  - So, back to the matter at hand...

If this were to work I would expect the conversation to go, for example:

User: What do you do?
Bot: Oh, so we're talking about me now?
User: Yes, I suppose so
Bot: This should be fun.

So, is there any way to use conditional responses without an explicit user input? But rather one that just contains a certain response? I imagine this is a problem with using the * in two instances, both as <star> and [*] , but can't work out a solution within the framework? Maybe I'm missing something? I've also tried using *yes* and *no* .

Update:

Perhaps, it is a problem with the conditional operator I am using? Maybe == is not the correct method for comparing two values when I am simply trying to find out whether one is contained in the other? I've since found the Working Draft but no luck here either...

OK, so I have found a solution using object macros – but it is not very elegant.

This solution returns the users full response (with all the words made lowercase –with lowercase – separated in an array) to the test object macro in the args variable. The items in this array are enumerated to see whether any of them match an item in the positives or negatives arrays (which are essentially duplicated substitutions already present in the rivescript 'brain').

If there is a match, the action variable is updated to either yes or no and the loop is broken, if there isn't a match then the action variable remains undefined . This action variable is then returned to the conditional response and evaluated by rivescript to see if it fits any of the conditions.

> object test javascript
    let positives = ['yes', 'yeah', 'yep', 'yup', 'yh', 'ya', 'y', 'sure'];
    let negatives = ['no', 'nope', 'na', 'nah', 'pass'];
    var action = 'undefined';
    for (var i = 0; i < args.length; i++) {
      if (positives.indexOf(args[i]) !== -1) {
        action = 'yes'
        break;
      } else if (negatives.indexOf(args[i]) !== -1){
        action = 'no'
        break;
      } else {

      }
    }
    return action;
< object

// In the topic/main section

+ [*] you [*]
- Oh, so we're talking about me now?

+ *
% oh so we are talking about me now
* <call>test <lowercase></call> == no        => Whatever...
* <call>test <lowercase></call> == yes       => This should be fun.{topic=myself}
* <call>test <lowercase></call> == undefined => So, back to the matter at hand...
- So, back to the matter at hand...

This seems to work pretty well but I am sure there must be a better solution, even if it is only in cleaning up the object macro itself (maybe there is a way to bring the substitutions into the object macro??).

I am accepting this answer, but if anyone has any alternative suggestions/solutions I would still be happy to hear them.

So, I managed to get in touch with Noah Petherbridge who worked on Rivescript and who very kindly took the time to correct my understanding:

+ [*] you [*]
- So you are talking about me now?

+ [*] (yes|no) [*]
% so you are talking about me now
* <star> == yes => yes answer
* <star> == no => no answer
- default, shouldn't happen answer

For some reason I guess I assumed that I couldn't use trigger alternations in the conditional's trigger – there was a more elegant solution after all!

I will accept this answer now and leave this little journey for anyone else who might be struggling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM