Publish a bot

In this article we will show you how to publish your bot to Azure Web App and Azure Functions. Bot Framework Composer includes instructions and scripts to help make this process easier. Follow the steps in this article to complete the publish process or refer to the README file in your bot's project folder, for example, under this directory: C:\Users\UserName\Documents\Composer\BotName. Please also note that the process to publish your bot to Azure Web App and Azure Functions are slightly different.

Prerequisites

Create Azure resources

The first step to publish your bot is creating all the necessary Azure resources. If you already have your Azure resources provisioned, you can skip to the Deploy bot to Azure section.

  1. Open a new Command Prompt. Navigate to the scripts folder of your bot's project folder. E.g.

    cd C:\Users\UserName\Documents\Composer\BotName\scripts
    
    
  2. Run the following command:

    npm install
    
  3. Then run the following command:

    If you publish your bot to Azure Web App please run the following command:

    node provisionComposer.js --subscriptionId=<YOUR AZURE SUBSCRIPTION ID> --name=<NAME OF YOUR RESOURCE GROUP> --appPassword=<APP PASSWORD> --environment=<NAME FOR ENVIRONMENT DEFAULT to dev>
    

    If you publish your bot to Azure Functions, you need to run the following command:

    node provisionComposer.js --subscriptionId=<YOUR AZURE SUBSCRIPTION ID> --name=<NAME OF YOUR RESOURCE GROUP> --appPassword=<APP PASSWORD> --environment=<NAME FOR ENVIRONMENT DEFAULT to dev> --customArmTemplate=DeploymentTemplates/function-template-with-preexisting-rg.json
    
    Property Value
    Your Azure Subscription ID Find it in your Azure resource in the Subscription ID field.
    Name of your resource group The name you give to the resource group you are creating.
    App password At least 16 characters with at least one number, one letter, and one special character.
    Name for environment The name you give to the publish environment.
  4. You will be asked to login to the Azure portal in your browser.

    publish az login

    Note that if you see an error message "InsufficientQuota", you need to add an param '--createLuisAuthoringResource false' and run the script again. For example:

    node provisionComposer.js --subscriptionId=<YOUR AZURE SUBSCRIPTION ID> --name=<NAME OF YOUR RESOURCE GROUP>--appPassword=<APP PASSWORD> --environment=<NAME FOR ENVIRONMENT DEFAULT to dev> --createLuisAuthoringResource false
    

    Please note that if you publish your bot to Azure Functions, you need to run the following command:

    node provisionComposer.js --subscriptionId=<YOUR AZURE SUBSCRIPTION ID> --name=<NAME OF YOUR RESOURCE GROUP> --appPassword=<APP PASSWORD> --environment=<NAME FOR ENVIRONMENT DEFAULT to dev> --createLuisAuthoringResource false --customArmTemplate=DeploymentTemplates/function-template-with-preexisting-rg.json
    

    Note

    If you use --createLuisAuthoringResource false, you will also need to manually add the authoring key to the publish configuration, otherwise, the bot will not work. Also, the default region is westus. If you want to provision to other regions, you can add --location region.

    After running the last command, you will see the following.

    create azure resource command line

  5. The process will take a few minutes. After this is completed, you will see a JSON file in command line.

    {
        "accessToken": "<SOME VALUE>", 
        "name": "<NAME OF YOUR RESOURCE GROUP>",
        "environment": "<ENVIRONMENT>",
        "hostname": "<NAME OF THE HOST>",
        "luisResource": "<NAME OF YOUR LUIS RESOURCE>"
        "settings": {
            "applicationInsights": {
            "InstrumentationKey": "<SOME VALUE>"
            },
            "cosmosDb": {
            "cosmosDBEndpoint": "<SOME VALUE>",
            "authKey": "<SOME VALUE>",
            "databaseId": "botstate-db",
            "collectionId": "botstate-collection",
            "containerId": "botstate-container"
            },
            "blobStorage": {
            "connectionString": "<SOME VALUE>",
            "container": "transcripts"
            },
            "luis": {
            "endpointKey": "<SOME VALUE>",
            "authoringKey": "<SOME VALUE>",
            "region": "westus"
            },
            "MicrosoftAppId": "<SOME VALUE>",
            "MicrosoftAppPassword": "<SOME VALUE>"
        }
    }
    

Deploy bot to Azure

Now that you have completed provisioning the Azure resources, let's deploy your bot to Azure.

  1. In Composer, navigate to Publish page from the menu and select Add new profile.

  2. Select where you would like to publish your bot: Publish bot to Azure Web App, or Publish bot to Azure Functions.

  3. In this step, you need to choose the option you want to proceed based on your Azure resources:

Deploy to new Azure resources

If you use the provisioning scripts to create new Azure resources as instructed in the create Azure resources section, you only need to add the generated JSON file from the create Azure resources section to the Publish Configuration field and Save.

publish configuration

Deploy to existing Azure resources

If you are NOT using the provisioning script and you are manually creating your own resources in Azure portal, you will need to edit the JSON file and there are 2 optional settings in the publish profile:

  • hostname - this is the hostname of your azure webapp or azure function, if it does not match the form of <name>-<env>;
  • luisResource - this is the hostname of your LUIS endpoint resource if not in the form <name>-<env>-<luis>. You can EXCLUDE cosmos db, applicationInsights, blob storage, or luis if you don't want those features enabled or use them. This is the primary way you can opt-in or opt-out of those features in the runtime.

Examples:

  • Deploy your bot without configuring any other services:

    {
    "accessToken": "<your access token>",
    "hostname": "<your web app name>",  
    "settings": {
        "MicrosoftAppId": "<the appid of your bot channel registration>",
        "MicrosoftAppPassword": "<the app password of your bot channel registration>"
         }
    }
    
  • If you have luis configured in your Composer bot, you should use this:

    {
    "accessToken": "<your access token>",
    "hostname": "<your web app name>",
    "luisResource": "<your luis service name>", 
    "settings": {
        "luis": {
        "endpointKey": "<your luis endpointKey>",
        "authoringKey": "<your luis authoringKey>",
        "region": "<your luis region, for example westus>"
            },
        "MicrosoftAppId": "<the appid of your bot channel registration>",
        "MicrosoftAppPassword": "<the app password of your bot channel registration>"
        }
    }
    

    Note

    You should author and publish in the same region. Read more in the Authoring and publishing regions and associated keys article.

  1. Next, select Publish to selected profile and select Okay.

    publish to selected profile

    After this step, you will see this:

    publish in process

Test

You can open your Azure portal and test your newly published bot in Test in Web Chat.

test in web chat

Additional information

When publishing, if you encounter an error about your access token being expired. You can follow the steps to get a new token:

  • Open a terminal window.
  • Run az account get-access-token.
  • This will result in a JSON object printed to the console, containing a new accessToken field.
  • Copy the value of the accessToken from the terminal and into the publish accessToken field in the profile in Composer.