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. For example:

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

    npm install
    
  3. Then run the following command to provision your Azure resources.

    If you publish your bot to Azure Web App 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, 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:

    For Azure Web App:

    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
    

    For Azure Functions:

    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 in this step, you will need to manually add the LUIS authoring key to the publish configuration in the deploy to new Azure resources section, otherwise, the bot will not work. 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. The process will take a few minutes.

    Create Azure resource command line

  5. After the previous step is completed, you will see a generated 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"
            },
            "qna": {
            "endpoint": "<SOME VALUE>",
            "subscriptionKey": "<SOME VALUE>"
            },
            "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.

Select your publish destination

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

  2. Enter a name for your publish file and select where you would like to publish your bot: Publish bot to Azure Web App (Preview), or Publish bot to Azure Functions (Preview).

In the next step, choose the option you want to proceed based on your Azure resources:

Deploy to new Azure resources

This option applies to 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 step to the Publish Configuration field and Save.

Add publish file

Note

If you use --createLuisAuthoringResource false in the 4th step of the create Azure resources section, you will need to manually add the LUIS 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 this step, you can move on to the publish section.

Deploy to existing Azure resources

This option applies to 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.

After this step, you can move on to the publish section.

Publish

  1. Select the file you want to publish from the navigation pane.

    Select profile to publish

  2. Select Publish to selected profile from Composer toolbar. In the pop-up window select Okay.

    Publish to selected profile

    You will see the publishing page like 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.