Responses are the messages that your bot sends back after a user sends it an incoming message. Writing a response is just like writing a trigger, except they start with a - (minus) sign.

- Hi, human!

Mixing It Up

Suppose you want to spice up the variety of replies a bot can have to any message. Include more than one response after a trigger, and the bot will choose one of the subsequent responses at random to send back to the user.

+ hi bot
- Hi, human!
- Howdy, partner!
- Hello world!

You can even have one response include multiple text variants, by including different copy separated by pipes | within the {random}{/random} tags.

+ hi bot
- {random}(Hey|What's up|Hello){/random}, human!

While triggers offer fine-grained control over how to match incoming messages from your users, the real power in responses is creativity over how to respond. Learn more about these powerful tools:

What Your User Said

If you have a trigger with a * catch all, use <star> in your reponse to say back what your user said in place of the *. Try this in a bot:

+ i said *
- Oh! You said: <star>

Recall that Dexter strips out common punctuation marks before attempting to match against triggers. <star> also behaves in this way—it won't include any stripped punctuation marks. You need to use the # punc directive if you want to include any puncuation:

# punc nostrip
+ my email is *
- Ok! Your email is <star>.

Note that captures don't work on wildcards bound by optional brackets. The following <star> won't capture any text:

+ i like to eat [*]
- <star> is undefined, I don't know what you like to eat!

Learn more about how to capture and save <star> data in the getting and setting data section.

Line Breaks

Add line breaks (carriage returns) to your script with \n. It is like as if every time your bot sees \n, it will press "Enter" on its keyboard, but not send the message yet.

+ hello
- Hi there! \n \nHow can I help you today?

The above produces this:

Line breaks

It is important to note that line breaks are different than the concept of a single response in the editor that spans multiple lines. If you want your script to be more readable and break apart a single response into multiple lines, use ^ to indicate "this line belongs to the above line as well."

+ hello
- Hi! \s
^ How can I help you today?

Multiline responses

Dexter removes spaces at the start and end of lines, which means any spaces you have will likely be ignored when you use ^. You can specify a space between the messages on multiple lines manually with \s, as demonstrated above.

Trigger Redirects

Trigger redirects are powerful concepts that allow you to concatenate multiple responses together into one message. They can be used to keep your script concise or DRY.

You can use trigger redirects to combine a static response with a dynamic response to keep your bot conversation fresh:

+ [*] checkout [*]
- You've just bought three boxes of chocolate. {@ thanks}
+ thanks
- Thanks for purchasing from our store!
- Your purchase goes a long way!
- We appreciate your business.

You can also use trigger redirects in combination with topic redirects to [combine responses in multiple topics](.


Conditionals allow you to have your bot respond in different ways to the same trigger, based on some sort of test or requirement.

For example, if the bot wanted to greet a user by name, it would need to first know the user's name. By using conditionals, the bot first can test to see if it has previously saved the user's name in a name variable and then respond accordingly.

If you're unfamiliar with how to use <get> to remember variables, we recommend first taking a look at directions for recalling and remembering data.

Include a conditional by adding a new line immediately after a trigger. Start this line with an * (asterisk) sign, followed by a conditional test, followed by an => arrow and the response you want the bot to respond with if the conditional test ends up being true. If the conditional test is not met, the bot will default to the - response following the conditional.

+ hello
* <get name> == undefined => Hi there! I don't believe we've met before, what's your name?
- Hi <get name>, fancy meeting you again!
+ my name is *
- <set name=<star>>That's a lovely name!

Conditional tests can check for more than just equality ==. Try writing tests with inequality !=, less than <, less than or equal to, greater than >, or greater than or equal to >= conditions.

One trigger-response pair can include more than one conditional. They will be checked from top to bottom. The first conditional test that comes back true will determine how the bot responds.

+ is my name billy
* <get name> == billy => Billy!!!
* <get name> == bill => Bill? Close enough.
* <get name> == william => William is a bit of a stretch...
- You're not Billy, who are you!?