Introduction

When creating a bot, there might be instances where you need to externalize certain values or constants. Environment variables allow you to create a set of values that are connected to a particular bot instance.

For example, if you have a bot that has both a Sandbox and Production version, 99% of the functionality will be the same, but certain values (like skill IDs for instance) might be different. Defining and storing these values outside of the bot makes them easier to manage.

System environment variables

Conversation Builder includes a number of environment variables that you can use to take advantage of associated bot behaviors:

Variables for customizing disambiguation

You can use these environment variables to customize how disambiguation works; for details, see here.

  • system_groupConsecutiveIntentRanksInDisambiguation
  • system_useIntentsOnlyWithDialogStartersInDisambiguation

Variables for blocking consumer interruptions

These environment variables work together to block consumer interruptions while the bot is responding to the consumer; for details, see here.

  • system_handleIntermediateUserMessage
  • system_intermediateBotMessage
  • system_intermediateBotResponseTimeout

Add environment variables

If you are using multiple bot instances (e.g., a Sandbox version and a Production version), you would create a Sandbox environment and a Production environment and then associate the specific environment with the specific bot.

To add environment variables

  1. From the Conversation Builder dashboard, click Manage Bot Environments in the upper-right corner.
  2. Click Add Environment in the lower-left corner.
  3. Specify the following:

    • Environment Name: Enter a descriptive name. For example, you might have Sandbox and Production instances (e.g., "Router Bot Sandbox").
    • Environment Values: Enter the key/value pairs for each variable. Variables cannot have spaces or special characters in their names, only letters and numbers.

    You can add the key/value pairs one by one using the fields provided. Alternatively, click the Bulk Add link and enter them in key=value format in the text box provided. The text box also lets you copy the values from another source and paste them in.

  4. Click Save.

Once you’ve created an environment, you need to connect it to your bot.

To link environment variables to a bot

  1. Open the bot, and click (ellipsis icon) in the upper-right corner.
  2. Click Bot Settings from the menu that appears.
  3. Scroll down, and click More Settings.
  4. For Bot Environment, select the name of the environment.
  5. Click Save.

Use environment variables

There are two ways you can call environment variables.

For JavaScript, use the following notation: botContext.getEnvVariable(variableName);

For example:

switch(intent) {
  case "billing":
    transferMessage = "Hold on while I transfer you to someone who can help with your billing";
    skillId = botcontext.getEnvVariable('billing');
    skillName = intent;
    break;
  case "account":
    transferMessage = "Hold on while I transfer you to someone who can help with your account";
    skillId = botcontext.getEnvVariable('account');
    skillName = intent;
    break;
  case "help":
    transferMessage = "Hold on while I transfer you to someone who can help with your issue";
    skillId = botcontext.getEnvVariable('help');
    skillName = intent;
    break;
}

To display an environment variable directly in text, use the following notation: {$env.variableName}

For example:

Export environment variables to a CSV file

Exporting a set of environment variables is useful when you need to "move" the values from one environment to another, e.g., from Development to Staging, or from Staging to Production. You can export the variables and then use the Bulk Add feature (and copy/paste) to add them to the new environment.

To export environment variables to a CSV file

  1. From the Conversation Builder dashboard, click Manage Bot Environments in the upper-right corner.
  2. In the left panel, select the environment.
  3. In the right panel, under More Options, click (Download icon) beside Export Environment Variables.
  4. Follow the browser prompts to access and save the CSV file to a location of your choice.