Skip to content
Ben James edited this page May 24, 2017 · 19 revisions

IntroductionTriggersRepliesConversationsTopicsPlugins and FunctionsKnowledgeUnder the Hood


Replies

We have seen examples of replies in some of the examples on the Triggers page. Replies appear exactly as they are written - grammar, mistakes and all.

Basic replies

+ Hello *
- Hi, good to see you!

If you write more replies, the system will choose a random one, deliver it to the user and then discard it, so it is never used again for that user. If the user asks the same question again, they will be delivered one of the remaining replies and that reply is discarded too. This process repeats until there are no more replies, so it is a good idea to have a few replies for every trigger. This will also keep your dialogue less robotic and more natural. (Note: the system only checks for the past 10 messages when it discards replies).

+ Hello *
- Hi, good to see you!
- Hey, welcome back!
- Hello to you too!

If we don’t want an answer to be discarded from a set of replies, we can add {keep} in front of it. {keep} can also be applied to the topic, or passed in as an default superscript option called editMode default option is false.

+ Hello *
- {keep} Hi, good to see you!
- Hey, welcome back!
- Hello to you too!

You can also set {keep} on a gambit to keep all the replies without writing {keep} for each individually:

+ {keep} Hello *
- I'll keep this reply!
- And this one too.

Replies are chosen randomly by default. If you'd like them to instead appear in the order they were written, just add the {ordered} flag to the gambit like so:

+ {ordered} I like cats
- I'll say this first.
- The next time you ask me, I'll say this.
- The time after that, I'll say this.

Longer replies can be split over more lines using the continuation ^ token. Line breaks can be achieved by adding \n:

+ Hello *
- Hi, good to see you!\n
^ How are you today?

// the same as:

+ Hello there
- Hi, good to see you!\nHow are you today?

You can use alternates in replies, same as in inputs:

- Hi, ((good|great)) to see you!

will reply with Hi, good to see you! or Hi, great to see you!. This allows you to be more diverse in replies, without writing separate replies.

Capturing data from the input line

Sometimes you want to return the result of what was said back to the user in the reply. This is easily done by using the <cap> tag in replies.

+ my name is *2
- Nice to meet you, <cap>!

In the above example, the input My name is John Doe will trigger a reply Nice to meet you, John Doe!

If you have more than one thing you want to capture, just add a number to the <cap>:

+ *1 is taller than *2
- Are you sure that <cap1> is taller than <cap2>?

You will also have the previous captured data available.

+ my name is *1
- Nice to meet you <cap1>?

// Next reply
+ what is my name
- You just said it was <p1cap1>

<pNcapM> is previous captured data. Where N is the previous volley in the conversation. And M is the captured offset.

  • Generic wildcards and optionals are not captured.
  • Variable length, precise length, min-max wildcards, alternates, wordnet keywords and parts of speech are captured.

Redirecting {@__reply__}

Sometimes you want to reuse the same reply/set of replies in more than one gambit. Instead of duplicating, you can define this set of replies in a new gambit, then redirect to it (we use double underscore to delimit it rather to avoid confusing it with regular gambits, it’s not a technical requirement):

+ hello my friend
- {@__greeting__} How are you today?
+ __greeting__
- Hi there!
- Hello to you too!
- Howdy!

will match Hello my friend! and reply with one of these three replies:

  • Hi there! How are you today?
  • Hello to you too! How are you today?
  • Howdy! How are you today?

Unlike regular replies, these are truly random (not a random sequence), meaning you can get the same reply even three times in a row. When using a redirect, it should be a NxM random combination, providing each N has a redirect to M.

Besides using the above inline redirect, replies can use redirect functions:

  • Replies can use a respond(topicName) function to redirect and search in another topic, including hidden topics.
  • Replies can use a topicRedirect(topicName,trigger) function to redirect to a certain gambit in another topic.

More details about these functions are here. All of these things can be nested in any order to create even more complex rules and conversations. For example, a reply can redirect to another gambit which calls a function that changes the topic and searches for another topic to find a matching gambit.

Sub Replies

If you would like to send messages in chunks, you can use the following syntax:

+ hello
- {delay=0} Hey there!\n
^ {delay=0} Nice to meet you.\n
^ {delay=0} Let me know if you need anything!

delay: Suggests to the client, how long to wait for the message to appear.

Note: This is just a suggestion, you are responsible for timing the messages in your client application.

On your client, you can access the array of messages in the subReplies property of the ss-message object

console.log(message.subReplies)

[
  { delay: '0', string: 'Hey there!' },
  { delay: '0', string: 'Nice to meet you.' },
  { delay: '0', string: 'Let me know if you need anything!' }
]

Comments

SuperScript supports C Style comments inside your scripts should you want to add a note or describe what your trigger is trying to match.

// This is a single line comment.

/*
 This is also a comment.
*/

Continue to Conversations

Clone this wiki locally