Introduction

During a bot conversation with a consumer, you’ll likely want to capture and store some information that’s been collected along the way. You can store that information in variables and slots:

  • Variables: Variables are more commonly used than slots. Use a variable when you simply want to save a value, for example, to save a consumer’s response in a Question interaction. Using a slot for this basic behavior doesn’t offer any additional value. So, when in doubt, use a variable.
  • Slots: Slot variables are still variables; they’re just a special type. If you want to automatically detect an entity within a Question interaction, you must use a slot variable that’s associated with that entity. Using a standard variable won’t accomplish this; only slot variables have this specialized behavior.

You can add both variables and slots to the custom rules of an interaction.

If you’re adding an API integration to perform some action or retrieve information (e.g., retrieve an order’s status), variables and slots are useful for storing and then passing along the necessary data (e.g., the order’s number).

See also this tutorial on using variables in interactions.

Best practices

  • Get and save system data (user data and session data) in variables in the initConversation function in Global Functions, so the data can be accessed from anywhere in the bot. Keep in mind the requirements and best practices for custom code.
  • Use variables to insert dynamic values in interactions, e.g., to dynamically set data retrieved from an API call in the next interaction. See referencing variables and slots.
  • Use variables to insert dynamic values in integrations, i.e., to set headers, query parameters, the payload for POST and PUT API calls, etc. See referencing variables and slots.

Referencing variables and slots

To reference variables and slots and thereby insert dynamic values in interactions and integrations, use {}. Follow this syntax:

When adding a variable in a Next Action rule using another botContext variable as the new variable's value, follow this syntax: botVariableName, with no opening or closing braces. Learn more.

Duration

When you define a variable or slot, you specify how long to keep the stored data.

The options for specifying a duration

There are three options for the duration:

  • Request: The data is saved until a new consumer message is received by the bot.
  • Dialog: The data is saved for the duration of the dialog. Once the dialog’s flow ends, the data is cleared.
  • Session: The data is saved for the entirety of the consumer’s bot session. This is useful when you’re using the data to query APIs and retrieve information that might be useful across the entire bot.

If you need to store data for the long term, use the Conversation Context Service.

Limits

There are no character limits for the values of bot variables and slots.