Skip to content
Akinboyewa Akindolani edited this page Nov 19, 2017 · 9 revisions

IntroductionTriggersRepliesConversationsTopicsPlugins and FunctionsKnowledgeUnder the Hood


Conversations

For conversation to really flow you need to have more than one exchange. We use a % command to recall the previous thing said and continue to build off of that. The % line is not case sensitive and can include wildcards (to search for a partial match, especially when previous replies are complex or contain functions and filters):

+ *
- What is your favorite color?

  + *1
  % what is your favorite color
  - <cap> is my favorite color, too!

Let's walk through this example:

  1. The user says something, and this is matched by the * generic wildcard. The bot then replies with What is your favorite color?.
  2. When the next input from the user comes into the system, we first check the history and see if the previous reply has more dialogue. This is noted by the % What is your favorite color? line in SuperScript.
  3. We then pull the next trigger, in this case it is *1 meaning one word. The bot then replies with <cap> is my favorite color, too! (where <cap> is the user input).

Please note that:

  • In the current version of SuperScript, the line with the previous reply match (the % line) comes after, and not before, the matching gambit with + command
  • In conversations like this, we always try to match forward, but once there is no more matches we don't walk back up the tree, we reset back to the Random Topic. Also, * in conversation threads have the same weight as topic level * wildcards.

Complex conversations

Sometimes conversations can span on more than one levels (the indentation in writing the code is only a visual aid and does not have any impact in how SuperScript is parsed). There are some numbers in the first column, with the only purpose to identify the gambits in this code (do not use them in writing your code):

1  + conversation
   - What is your name?

2      + [my name is] *1
       % * what is your name
       - So your first name is <cap1>?

3           + ~yes
            % so your first name is *
            - Okay good.

4           + *
            % so your first name is *
            - Oh, lets try this again... {@conversation}

5       + *
        % * what is your name
        - I don't get it. {@conversation}

6   + *
    - Let's talk about something else now. {topic=new_topic}

Let's take a similar exchange of inputs/replies and see what happens in two separate cases: a topic with the keep flag and a topic without the keep flag (you can use {keep} only on few replies in a non-keep topic, to achieve various results).

Note: in the examples below, the approach for filtering LastReply is less greedy, meaning the bot will match ANY trigger for which the % line matches LastReply, as well as any trigger without a % line (in the above case gambit no. 6). This means that not having a specific % line is equivalent with having a % * line (catch all).

Keep topic

Who Message Behind the scenes
User conversation User just starts the conversation
Bot What is your name? Bot matches this in gambit 1 and replies, then sets LastReply to What is your name? and waits for the next user input
User Rob Ellis User input contains the two words.
Bot I don't get it. What is your name? Bot tries to match the user input with any gambits in order in the whole topic. Gambits 3 and 4 are eliminated, since their % line does not match LastReply, and the bot tries to find a match in these gambits in order: 1, 2, 5, 6. The first match is found in gambit no. 5, and the bot replies with I don't get it, and redirects to the first reply. Since this is a keep topic, the reply used from gambit 5 is not discarded! The LastReply is now I don't get it. What is your name?
User Rob Ellis User inputs the same, just to be stubborn (we'll see that the bot reacts different in a keep vs not-keep topic
Bot I don't get it. What is your name? Bot repeats the above process. Since LastReply is now I don't get it. What is your name?, gambit 1, 2, 5, 6 are matched again, and the process can loop forever, since we have a keep topic and a stubborn user. The bot wins at stubborness in this case, until the user complies.
User My name is Rob Finally user gives in and gives a proper answer
Bot So your first name is Rob? The bot tries to match agains the same gambits (1, 2, 5, 6) and finds a match in gambit 2, therefore replies and sets LastReply to So your first name is Rob
User Huh? User gives a random answer
Bot Oh, let's try this again... What is your name? Bot filters gambits for which the % line corresponds with LastReply and only gambits 1, 3, 4, 6 are considered. Then tries to match Huh? and finds a match in gambit 4, so replies and redirects to gambit 1. LastReply is now Oh let's try this again... What is your name?
User My name is Rob User behaves
Bot So your first name is Rob? Same logic as above
User Yes User finally comes to his senses and realises bot can be more stubborn, so no point in playing this game for hours
Bot Okay, good. Bot uses same logic as above, filtering gambits to be considered by LastReply and from the 1, 3, 4, 6 gambits finds a match in 3 and replies accordingly. 'LastReplyis nowOK Good.`
User Finally! Basically user can say anything
Bot Let's talk about something else now Bot first tries to filter gambits based on the OK Good. last reply, and only gambits 1 and 6 can be considered. Bot matches Finally with the catch all trigger in gambit 6 and moves on with the conversation, maybe to a new topic.

Non-keep topic

Who Message Behind the scenes
User conversation User just starts the conversation
Bot What is your name? Bot matches this in gambit 1 and replies, then sets LastReply to What is your name? and waits for the next user input. The reply is discarded (so if the user says again conversation it will not be matched, but the redirect {@conversation} in gambits 4 & 5 forces the reply anytime
User Rob Ellis User input contains the two words.
Bot I don't get it. What is your name? Bot tries to match the user input with any gambits in order in the whole topic. Gambits 3 and 4 are eliminated, since their % line does not match LastReply, and the bot tries to find a match in these gambits in order: 1, 2, 5, 6. The first match is found in gambit no. 5, and the bot replies with I don't get it, and redirects to the first reply. Since this is NOT a keep topic, the reply used from gambit 5 is discarded! The LastReply is now I don't get it. What is your name?
User Rob Ellis User inputs the same, just to be stubborn (we'll see that the bot reacts different now)
Bot Let's talk about something else now. Bot repeats the above process. Since LastReply is now I don't get it. What is your name?, gambit 1, 2, 5, 6 are matched again. But (and this is different from the keep topic), there is no reply available for gambit 5 (even if this is the first match), so the bot goes to gambit 6—a more flexible and understanding bot, who won't put up with stubborn users.

Key takeaways:

  • Bot eliminates only gambits for which LastReply does not match the % line rule.
  • Gambits without a % rule are considered when matching a reply.
  • The order for matching is similar with the order of the gambits.

Continue to Topics

Clone this wiki locally