Introduction

You can store data that you’ve collected throughout a bot conversation with a consumer in variables. Variables are more commonly used than slots. Use a variable when you simply want to save a value. Using a slot for this basic behavior doesn’t offer any additional value. So, when in doubt, use a variable.

System variables

There are several system variables that store information that's commonly needed in use cases. You can use these variables in your interactions:

  • {$chatBotId}: Returns the ID of the bot.
  • {$chatBotUserId}: Returns the ID of the consumer.
  • {$chatBotUserPlatformId}: Returns the ID of the bot user agent. This is provided by Conversational Cloud.
  • {$conversationId}: Returns the ID of the current conversation. This is provided by Conversational Cloud.
  • {$firstname}: Returns the first name of the bot user agent. This is provided by Conversational Cloud.
  • {$quickReplyPayload}: Returns the quick reply payload for the current interaction.
  • {$userMessage}: Returns the most recent message from the consumer.

Store the consumer's response

The most common use case for variables is storing consumer responses to questions. Frequently, you’ll want to capture what the consumer just said as the value of a variable. You can use {$userMessage} to do this, for example:

Storing the consumer's most recent message in a variable in a rule

You can also use {$query} in the same way; it works like {$userMessage}.

Add a variable

  1. In the interaction, click Next Action, and then click + Custom Rule.

    The Custom Rule button that appears at the bottom of the dropdown when you click Next Action

  2. In the window that appears, define the custom rule. To add the variable, click + Add Variable, and then define the variable using the fields provided.

    The fields for definining a variable in a rule

    For the variable's value, you can specify:

    • A system variable, for example: {$userMessage} or {$firstname}. See the list of available system variables farther above on this page.
    • Another botContext variable, for example: variableName.
      Don't enter {$botContext.variableName}here. That's the syntax for referencing botContext variables elsewhere.
    • A string, for example, the number “1” or the phrase “vip.”

Clean variable data

Before setting or storing data in a variable, in the Process User Response code, it's a good idea to "clean" or "sanitize" the data by parsing it and transforming it to remove problematic issues, i.e., remove leading or trailing white space, remove new lines ( \n ) and special characters, and so on.

Store and access variable data with code

Use the Get and Set Bot Variables functions to store and access variable data in the Pre-Process Code, Post-Process Code, and Process User Response JavaScript code panels in interactions.