My bot stores the name of the user in a database, and, from time to time, the database sends the session a message “setname username”. Sample rivescript:
+ setname *
- <set name=<formal>>
+ (what is my name|who am i)
- You're <get name>, right?
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- {topic=random}Thanks for charing.
< topic
+ *
- I don't have a reply for that.
- Try asking that a different way.
The problem is when the user is in a topic like ‘nlike’ that is exited by * and I send the message to set the name, then the conversation exits the topic.
Expected conversation:
Me: hello
Bot: I don't have a reply for that.
Me: didntlike
Bot: Why?
Me: setname John
Bot:
Me: I didn't like because you are ugly.
Bot: Thanks for charing.
Me: Who am I?
Bot: You're John, right?
Is there a way to treat that in the begin block? I tried different syntaxes, but no positive result. I thought of something like:
> begin
+ setname *
- <set name=<formal>>
+ request
- {ok}
< begin
One workaround is to add the same trigger inside all topics, but I need a better solution, because that approach is error prone as my rive files get bigger.
==== Code tried based on Nelson's answer =====
> begin
+ request
- {ok}{topic=specialtriggers}
< begin
> topic specialtriggers
+ setname *
- <set name=<formal>>
< topic
+ (what is my name|who am i)
- You're <get name>, right?
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- {topic=random}Thanks for charing.
< topic
+ *
- I don't have a reply for that.
- Try asking that a different way.
I think adding the topic to {ok}{topic=specialtriggers} making all triggers outside this topic fail. After the preprocessing, Rivescript should answer if it is a specialtrigger or else search for the normal triggers.
Answer based on Noah Petherbridge's response on chatbots.org, one viable solution is using topic inheritance: