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

Issue with parenthesis in % (conversations) #79

Open
arashsa opened this issue Feb 8, 2017 · 3 comments
Open

Issue with parenthesis in % (conversations) #79

arashsa opened this issue Feb 8, 2017 · 3 comments

Comments

@arashsa
Copy link
Contributor

arashsa commented Feb 8, 2017

If a reply has a parenthesis then it is not possible to use it in % mode.

+ k
- (ok)

+ *
% (ok)
- percentage
+ k
- (ok)

+ *
% ok
- percentage

None of the above work.

@kirsle
Copy link
Member

kirsle commented Feb 8, 2017

Both forms seem to work for me on v1.14.4:

First:

      .   .       
     .:...::      RiveScript Interpreter (Python)
    .::   ::.     Library Version: v1.14.4
 ..:;;. ' .;;:..  
    .  '''  .     Type '/quit' to quit.
     :;,:,;:      Type '/help' for more options.
     :     :      

Using the RiveScript bot found in: tmp
Type a message to the bot and press Return to send it.

You> k
[RS] Get reply to [localuser] k
[RS] Checking topic random for any %Previous's.
[RS] There is a %Previous in this topic!
[RS] lastReply: undefined
[RS] Try to match lastReply (undefined) to (ok)
[RS] Try to match u'k' against u'k' (u'^k$')
[RS] Found a match!
[RS] Reply: (ok)
Bot> (ok)
You> test
[RS] Get reply to [localuser] test
[RS] Checking topic random for any %Previous's.
[RS] There is a %Previous in this topic!
[RS] lastReply: ok
[RS] Try to match lastReply (ok) to (ok)
[RS] Bot side matched!
[RS] Now try to match test to *
[RS] Found a match!
[RS] Reply: percentage
Bot> percentage

Second:

You> k
[RS] Get reply to [localuser] k
[RS] Checking topic random for any %Previous's.
[RS] There is a %Previous in this topic!
[RS] lastReply: undefined
[RS] Try to match lastReply (undefined) to ok
[RS] Try to match u'k' against u'k' (u'^k$')
[RS] Found a match!
[RS] Reply: (ok)
Bot> (ok)
You> lol
[RS] Get reply to [localuser] lol
[RS] Checking topic random for any %Previous's.
[RS] There is a %Previous in this topic!
[RS] lastReply: ok
[RS] Try to match lastReply (ok) to ok
[RS] Bot side matched!
[RS] Now try to match lol to *
[RS] Found a match!
[RS] Reply: percentage
Bot> percentage

Run the RiveScript bot in debug mode (e.g., I put the test file in a folder I named tmp in the git root and ran python shell.py --debug tmp and see what it's trying to match against.

The % command works a lot like the + command except it tests the bot's previous response; and the bot's previous response is sent through all the same substitutions and formatting as the user's messages, so even though the response contained literal parenthesis characters, those get removed before the % is tested just like it would with a +.

@arashsa
Copy link
Contributor Author

arashsa commented Feb 10, 2017

Maybe it's an issue with the version on pip?

@kirsle
Copy link
Member

kirsle commented Feb 24, 2017

Can you test with the version on pip and a simplified test file that only tests the code snippet given on this ticket? The versions of the module on pip should correlate 1:1 with the "Prepare vX.X.X for release" commits from GitHub, as I make those commits just before publishing to PyPI.

For example, use a script like the example.py from the root of this repo and test the bare minimum RiveScript code in a terminal session to see whether it's a bug in RiveScript itself or a bug in your specific application.


For more background and ideas of where the problem might lie:

  • If you have more RiveScript code in your actual bot than what you pasted on this ticket, it could be uncovering a different problem than this ticket suggests.

    I've had bug reports in the past where the sorting algorithm for %Previous was incorrect, and the bug would appear when you have multiple triggers that all share a matching %Previous command. The root cause was that the triggers weren't being sorted properly and one of them was made un-matchable whereas the other one would work.

  • I've seen people lately using RiveScript for Facebook Messenger bots and similar platforms, where they built a web server (such as with Flask) to provide the webhook for the bot platform.

    That architecture introduces all sorts of new moving parts that aren't present in more simple, single process command line applications. For example, a common deployment mode for Flask apps is to use gunicorn and run multiple instances of the app, for example, have four different Python processes all running the app and load balancing requests. This is generally good for simple stateless web apps, but RiveScript's automatic in-memory caching of user variables becomes a problem, because different Python processes might handle different requests from the same user, and they won't all agree on the user variables. Consider using something like rivescript-redis if this sounds familiar. More info on this kind of thing is in the RiveScript Wiki.

To generalize, %Previous only works when the bot is able to remember the previous reply given to the user, and for that to work, user variables have to be kept around somehow between requests. If the user is hitting a different process with each request, or if the RiveScript instance is being torn down and rebuilt on each request, then their variables won't be consistent and their last reply will be missing or incorrect.

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

No branches or pull requests

2 participants