Manage bot resources

APPLIES TO: yesSDK v4 no SDK v3

Bots usually consume different services, such as LUIS.ai or QnaMaker.ai. When you are developing a bot, you need to be able to keep track of them all. You can use various methods such as appsettings.json, web.config, or .env.

Important

Prior to the Bot Framework SDK 4.3 release, we offered the .bot file as a mechanism to manage resources. However, going forward we recommend that you use appsettings.json or .env file for managing these resources. Bots that use .bot file will continue to work for now even though the .bot file has been deprecated. If you've been using a .bot file to manage resources, follow the steps that apply to migrate the settings.

Migrating settings from .bot file

The following sections cover how to migrate settings from the .bot file. Follow the scenario that applies to you.

Scenario 1: Local bot that has a .bot file

In this scenario you have a local bot that uses a .bot file, but the bot has not been migrated to the Azure portal. Follow the steps below to migrate settings from the .bot file to appsettings.json or .env file.

  • If the .bot file is encrypted, you'll need to decrypt it using the following command:
msbot secret --bot <name-of-bot-file> --secret "<bot-file-secret>" --clear` command.
  • Open the decrypted .bot file, copy the values and add them to the appsettings.json or .env file.
  • Update the code to read settings from appsettings.json or .env file.

In the ConfigureServices method, use the configuration object that ASP.NET Core provides, for example:

Startup.cs

var appId = Configuration.GetSection("MicrosoftAppId").Value;
var appPassword = Configuration.GetSection("MicrosoftAppPassword").Value;
options.CredentialProvider = new SimpleCredentialProvider(appId, appPassword);

If needed, provision resources and connect them to your bot using the appsettings.json or .env file.

Scenario #2: Bot deployed to Azure with a .bot file

In this scenario you have already deployed a bot to the Azure portal using the .bot file, and now you want to migrate settings from the .bot file to appsettings.json or .env file.

  • Download the bot code from the Azure portal. When you download the code, you'll be prompted to include appsettings.json or .env file that will have your MicrosoftAppId and MicrosoftAppPassword and any additional settings in it.
  • Open the downloaded appsettings.json or .env file, and copy the settings from it into your local appsettings.json or .env file. Don't forget to remove the botSecret and botFilePath entries from your local appsettings.json or .env file.
  • Update the code to read settings from appsettings.json or .env file.

In the ConfigureServices method, use the configuration object that ASP.NET Core provides, for example:

Startup.cs

var appId = Configuration.GetSection("MicrosoftAppId").Value;
var appPassword = Configuration.GetSection("MicrosoftAppPassword").Value;
options.CredentialProvider = new SimpleCredentialProvider(appId, appPassword);

You’ll also need to remove the botFilePath and botFileSecret from the Application Settings section in the Azure portal.

If needed, provision resources and connect them to your bot using the appsettings.json or .env file.

Scenario #3: For bots that use appsettings.json or .env file

This scenario covers the case in which you are starting to develop bots using SDK 4.3 from scratch and don't have existing .bot files to migrate. All settings that you want to use in your bot are in the appsettings.json or .env file as shown below:

{
  "MicrosoftAppId": "<your-AppId>",
  "MicrosoftAppPassword": "<your-AppPwd>"
}

To read the above settings in your C# code, you'll use the configuration object that ASP.,NET Core provides for example: Startup.cs

var appId = Configuration.GetSection("MicrosoftAppId").Value;
var appPassword = Configuration.GetSection("MicrosoftAppPassword").Value;
options.CredentialProvider = new SimpleCredentialProvider(appId, appPassword);

If needed, provision resources and connect them to your bot using the appsettings.json or .env file.

FAQ

Q: I want to create a new V4 bot in Azure portal. How has the Azure portal experience changed with the removal of the .bot file?

A: When you create a bot in the Azure portal, .bot file will not be created. You can use the Application Settings section in the Azure portal to find IDs/Keys. When you download the code, these settings will be stored in the appsettings.json or .env file for you. In your bot, you can update the code to read the settings before making the call to the individual service. After you’ve updated your bot code, you can use az bot publish to deploy your bot.

Q: What about V3 bots?

A: The scenario for V3 bot is similar to the scenario for V4 bots without a bot file. The deployment process will continue to work.

Additional resources

  • For steps to deploy the bot, see deployment topic.
  • To protect keys and secrets, we recommend you use Azure Key Vault. Azure Key Vault is a tool for securely storing and accessing secrets, such as your bot's endpoint and authoring keys. It provides a Key Management solution and makes it easy to create and control your encryption keys, so you have tight control over your secrets.