Hello,
Thanks for reaching out to us, I haven't found any official guidance about this topic but I found below steps which may work for you, please take a look and have a try, all code you need to change according to your scenario -
You can use the Microsoft.Bot.Components.Recognizers.CustomQuestionAnsweringRecognizer in Bot Framework Composer to integrate your bot with Language Studio's custom question and answer.
To use this recognizer, you'll need to create a custom component in your Composer project. Here are the steps:
Create a new folder named CustomComponents in your Composer project's src folder.
Create a new file named CustomQnAMakerRecognizerComponent.ts in the CustomComponents folder.
Paste the following code into the CustomQnAMakerRecognizerComponent.ts file:
typescript
import * as path from 'path';
import { Recognizer } from 'botbuilder-dialogs';
import { CustomQuestionAnsweringRecognizer } from 'microsoft.bot.components.recognizers';
const defaultLocale = 'en-us';
const defaultConfiguration = 'default';
export class CustomQnAMakerRecognizerComponent extends Recognizer {
constructor() {
super();
this.id = 'CustomQnAMakerRecognizer';
}
public async onRecognize(context, options) {
const recognizerResult = {
$kind: 'Microsoft.CustomQnAMakerRecognizer',
intents: {},
entities: {},
};
const utterance = context.activity.text;
const locale = context.activity.locale || defaultLocale;
const configuration = options.configuration || defaultConfiguration;
const recognizer = new CustomQuestionAnsweringRecognizer({
endpointUrl: process.env.QNA_ENDPOINT_URL,
endpointKey: process.env.QNA_ENDPOINT_KEY,
kbId: process.env.QNA_KB_ID,
endpointHost: process.env.QNA_ENDPOINT_HOST,
});
const result = await recognizer.recognize(utterance, locale, configuration);
recognizerResult.intents = result.intents;
recognizerResult.entities = result.entities;
return recognizerResult;
}
}
Save the file.
In your Composer project, click the "Add component" button in the "Components" pane.
In the "Add Component" dialog, select "Custom" as the component type.
Enter "CustomQnAMakerRecognizer" as the name and "CustomComponents/CustomQnAMakerRecognizerComponent.ts" as the path.
Click "Add" to add the component to your project.
Now you can use the CustomQnAMakerRecognizer in your Bot Framework Composer dialog. To use it in combination with Intent Recognizer, you can add a Switch action in your dialog that checks if any matching recognizer is found, and if not, it triggers the CustomQnAMakerRecognizer. Here's an example:
{
"$kind": "Microsoft.AdaptiveDialog",
"autoEndDialog": true,
"defaultResultProperty": "dialog.result",
"recognizer": {
"$kind": "Microsoft.RegexRecognizer",
"intents": [
{
"intent": "Greeting",
"patterns": [
"hi",
"hello"
]
}
]
},
"triggers": [
{
"$kind": "Microsoft.OnIntent",
"intent": "Greeting",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "${SendActivity('Hi there! How can I help you today?')}"
}
]
},
{
"$kind": "Microsoft.OnUnknownIntent",
"actions": [
{
"$kind": "Microsoft.Switch",
"condition": "count(recognizerResult.intents) > 0",
"default": [
{
"$kind": "Microsoft.SendActivity",
"activity
I hope this helps. Thanks.
Regards,
Yutong
-Please kindly accept the answer if you feel helpful to support the community, thanks a lot.