Create a Skill Bot from Azure Question Answering Service
Published Dec 05 2022 05:40 AM 6,143 Views
Microsoft

 

Question answering in Azure Cognitive Service For Language provides cloud-based Natural Language Processing (NLP) that allows you to create a natural conversational layer over your data. And it replaced Azure QnA Maker service since 1st Oct, 2022.

 

With Question Answering, developers can quickly create a bot in Azure by following this guide . However some developers noticed that this bot cannot be used as Skill Bot, for example, after taking below steps skill bot still return 401 errors to the root bot,

 

  1. Create empty root bot in Composer
  2. Generate and deploy a bot from Custom Question Answering project in Azure Language Service portal
  3. Create a simple skill manifest for the skill bot

 

{
    "$schema": "https://schemas.botframework.com/schemas/skills/v2.2/skill-manifest.json",
    "$id": "<newqna01-bot>",
    "name": "<newqna01-bot>",
    "version": "2022-01-14T08:54:40.2310775Z",
    "description": "newqnabot01 manifest",
    "publisherName": "<newqna01-bot>",
    "endpoints": [
        {
            "name": "newqnabot01 PROD",
            "protocol": "BotFrameworkV4",
            "description": "PROD",
            "endpointUrl": "https://<newqna01-bot>.azurewebsites.net/api/messages",
            "msAppId": "aa6fabxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        }
    ]
}

 

      4.  Add the skill bot to the root bot by importing manifest

      5.  Add trigger to skill bot in the root bot (refer to: Connect to a remote skill with Bot Framework Composer  )

      6.  Add root bot app id to allowedCallers field in appsettings.json under the skill bot project

      7.  Test skill bot trigger locally in root bot, hits the 401 error

 

The reason of this problem is the created bot from Language service uses a root bot pattern, which doesn’t include the authentication and error handling requirement for a typical skill bot.

 

To solve it, need to refer this article Implement a skill - Bot Service , and take below steps. In this article, I name the language service created bot as newqna01-bot, which will be our remote skill bot. Before starting, make sure we created a simple skill manifest for the skill bot, and import it to the root bot in Bot Composer as above.

 

Modify the skill bot project

======================

  1. Download the project code from newqna01-bot web service. (Not sure if you did this before, my method is: visit https://<newqna01-bot>.scm.azurewebsites.net/  , click Debug Console -> CMD, open Site folder, find wwwroot, download the whole content of wwwroot). The project name is QnABot. We can open its solution file in Visual Studio 2022:

     

    freistli_2-1670294514857.png
  2. Modify AdapterWithErrorHandler.cs , in it we need to add a new class of SkillAdapterWithErrorHandler. Refer to https://learn.microsoft.com/en-us/azure/bot-service/skill-implement-skill?view=azure-bot-service-4.0...
  3. Modify the startup.cs, in it, enable the AllowedCallersClaimsValidator, and use SkillAdapterWithErrorHandler. Refer to  https://learn.microsoft.com/en-us/azure/bot-service/skill-implement-skill?view=azure-bot-service-4.0...
  4.  Modify the appsettings.json as belowplease replace the highlighted fields based on yours:

 

{
  "DefaultAnswer": "",
  "DefaultWelcomeMessage": "",
  "MicrosoftAppType": "",
  "MicrosoftAppId": "aa6fab21-xxxxxxxxxxx",
  "MicrosoftAppPassword": "IZw8Q~xxxxxxxxxxxxx",
  "MicrosoftAppTenantId": "72f988bf-xxxxxxxxxxx",
  "AllowedCallers": [ "*" ],
  "LanguageEndpointHostName": https://<newqna01-xxxxxxxxx>.cognitiveservices.azure.com/,
  "ProjectName": "xxxxxxxxxxxxx",
  "LanguageEndpointKey" : "dda4cdxxxxxxxxxxx"
}

 

  1. In the QnABot project file, add ErrorOnDuplicatePublishOutputFiles setting, without it, I always hits publish failure on my side.

 

   <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <LangVersion>latest</LangVersion>
      <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>

 

  1. Publish the QnABot to the Azure web app. My sample here is newqna01-bot web app. Now the QnABot is ready to be used a remote skill bot.

 

Modify the Bot Composer Project Setting

=========================

  1. For local debugging (run the QnABot on your local side), need to run ngrok first. And then modify skillHostEndpoint in the root bot configuration:

 

"skillHostEndpoint": https://ca99-2404-f801-9000-18-6fec-00-d9.ap.ngrok.io/api/skills,

 

  1. Make sure the allowedCallers in root bot configuration included the skill bot app id:

 

 "skills": {
      "allowedCallers": [
        "aa6fab21-xxxxxxxxx"
      ]

 

  1. For local debugging (run the QnABot on your local side), set the endpointUrl for this skill bot with localhost:

 

 "newqnabot01": {
      "endpointUrl": https://localhost:3987/api/messages,
      "msAppId": "aa6fab21-xxxxxxxxxxxxxx"
}

 

  1. To test remote skill bot (you have published the modified skill bot to Azure successfully), please set the endpointUrl for this skill bot with azure web app link:

 

 "newqnabot01": {
      "endpointUrl": https://newqna01-bot.azurewebsites.net/api/messages,
      "msAppId": "aa6fab21-xxxxxxxxxxx"
   }

 

 

Note: In the bot composer, skillHostEndpoint will be autoset to the real azure root bot web app link on azure side during publishing. Means the local skillHostEndpoint  config is still the ngrok setting, while the same time azure side skillHostEndpoint is azure root bot app link.

 

Happy Bot Framework Development!

Co-Authors
Version history
Last update:
‎Dec 05 2022 06:50 PM
Updated by: