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

Accessing current trigger/topic or calling object macro in conditional #107

Closed
davidchriqui opened this issue Apr 30, 2016 · 5 comments · Fixed by #111
Closed

Accessing current trigger/topic or calling object macro in conditional #107

davidchriqui opened this issue Apr 30, 2016 · 5 comments · Fixed by #111

Comments

@davidchriqui
Copy link

davidchriqui commented Apr 30, 2016

Is there a way to access current trigger and current topic values in a conditional test ?
What about calling an object macros in a conditional?

@davidchriqui davidchriqui changed the title Accessing current trigger in conditional Accessing current trigger/topic in conditional Apr 30, 2016
@davidchriqui
Copy link
Author

davidchriqui commented Apr 30, 2016

I actually look for a way to do the following :

> topic topic1

+ trigger1
% previous
- reply1

+ trigger2
% reply1
- reply2

+ quit
- ok{topic=random}

< topic

I want the user to be able to "quit" the current topic to the random one, no matter what previous bot reply is. With the previous example, the user would trigger "trigger1" then if he triggers "quit", he is redirected to the random topic instead of being replied with "reply2".

@davidchriqui davidchriqui changed the title Accessing current trigger/topic in conditional Accessing current trigger/topic or calling object macro in conditional May 2, 2016
@davidchriqui
Copy link
Author

Is it there a way to perform the following :

+ *
* <call>checkMacro <star> == true => blablabla
* <call>checkMacro <star> == false => blablablablabla

@kirsle
Copy link
Member

kirsle commented May 2, 2016

That should work but you're missing the </call> tag.

+ *
* <call>checkMacro <star></call> == true => blablabla
* <call>checkMacro <star></call> == false => blablablablabla

You can do <get topic> to get the user's current topic. From an object macro you could use rs.lastMatch(rs.currentUser()) to get the current user's last matched trigger.

@davidchriqui
Copy link
Author

davidchriqui commented May 6, 2016

I can't get object macro calls to work with conditionals (WITH the closing tag :) )

+ my email is *
* <call>checkEmailFormat <star></call> == false => Wrong format
- right format

checkEmailFormat is never called and RS always replies with "right format" (I double checked the "checkEmailFormat" function and it works properly)

@kirsle
Copy link
Member

kirsle commented May 6, 2016

I verified the issue. This used to work, when <call> tags were executed inside the processTags() function with all the other tag processing, but in PR #78 support for asynchronous object macros was added which made this a two-pass approach:

processTags() just mangles the <call> tag to look like {__call__}name {__call_arg__}arg1{/__call_arg__}{/__call__} and that's where the condition was left when it came time to compare the result (which obviously fails the comparison 😜 ), and then processCallTags() was the one that actually ran the code.

So I have PR #111 open to fix this, but need to make sure it doesn't cause any other bugs (asynchronous object macros most likely won't work in conditions, because RiveScript needs the answer "now" to see if the condition is true or not).

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

Successfully merging a pull request may close this issue.

2 participants