I have a new bot using SDK 4.3 which does not have a bot file, however I need to integrate LUIS and QnA Maker. If I understand correctly from the documentation I should add entries in my appsettings.json file for the various keys and ids. I have checked the latest sample for .NET Core for QnA maker and it still refers to using a .bot file, see https://github.com/Microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/11.qnamaker/Startup.cs.
I have also looked into the latest versions of the BotConfiguration class in 4.3 (https://github.com/Microsoft/botbuilder-dotnet/blob/4.3/libraries/Microsoft.Bot.Configuration/BotConfiguration.cs) and 4.Next (https://github.com/Microsoft/botbuilder-dotnet/blob/4.next/libraries/Microsoft.Bot.Configuration/BotConfiguration.cs) and they both still only provide a way to create a bot configuration (which is required to make an instance of BotServices which in turn LUIS and QnA services are added to) using a .bot file.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
An update for these will be coming shortly to the live docs, as soon as all the samples are up to date with this new method.
To unblock you, though, here's the way we suggest doing so:
In your appsettings.json, add entries for the following (they can be named whatever you like, but if you change the names make sure you update the code following)
"LuisAppId": "",
"LuisAPIKey": "",
"LuisAPIHostName": ""
Note that the API host name should be in the format <your region>.api.cognitive.microsoft.com.
Then, in code, set up your luis app, define the recognizer, and get the result. Here's the complete code for all of that - once you have the intent it can be used just as it has in the past.
// Create the LUIS settings from configuration.
var luisApplication = new LuisApplication(
configuration["LuisAppId"],
configuration["LuisAPIKey"],
"https://" + configuration["LuisAPIHostName"]
);
var recognizer = new LuisRecognizer(luisApplication);
// The actual call to LUIS
var recognizerResult = await recognizer.RecognizeAsync(turnContext, cancellationToken);
var (intent, score) = recognizerResult.GetTopScoringIntent();
Hope that helps!
Thanks for those snippets @ivorb! You are correct that I can configure a bot to use LUIS using them, however, if I want to do something a little more complex like integrate a dispatcher to choose between LUIS or a QnA service the samples still rely on a BotConfiguration which is built using a .bot file in Startup.cs.
Are you able to provide guidance on the following:
1) A more precise timeline on when the update for the docs will be coming.
2) A sample on what code will replace the existing reading of a .bot file in Startup.cs in order to have some kind of object that we can configure services for.
Regarding 1) I see that you commented two weeks ago that the new docs were coming shortly. Another comment four days ago from a different person said they are also coming "shortly", but then on the same day they also said that the updated docs are coming in the first week of May.
In regards to 2) usually you will have something like:
public void ConfigureServices(IServiceCollection services)
{
var secretKey = Configuration.GetSection("botFileSecret")?.Value;
var botFilePath = Configuration.GetSection("botFilePath")?.Value;
// This is the problematic line because the only way to create a BotConfiguration is to use
// one of the static Load methods which all read in a .bot file
var botConfig = BotConfiguration.Load(botFilePath ?? @".\qnamaker.bot", secretKey);
var connectedServices = new BotServices(botConfig);
services.AddSingleton(sp => connectedServices);
services.AddSingleton(sp => botConfig);
services.AddBot<QnABot>(...)
services.AddBot<LuisBot>(...)
}
Thanks again for responding so promptly.
An update for these will be coming shortly to the live docs, as soon as all the samples are up to date with this new method.
To unblock you, though, here's the way we suggest doing so:
In your appsettings.json, add entries for the following (they can be named whatever you like, but if you change the names make sure you update the code following)
"LuisAppId": "", "LuisAPIKey": "", "LuisAPIHostName": ""Note that the API host name should be in the format
<your region>.api.cognitive.microsoft.com.Then, in code, set up your luis app, define the recognizer, and get the result. Here's the complete code for all of that - once you have the intent it can be used just as it has in the past.
// Create the LUIS settings from configuration. var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], "https://" + configuration["LuisAPIHostName"] ); var recognizer = new LuisRecognizer(luisApplication); // The actual call to LUIS var recognizerResult = await recognizer.RecognizeAsync(turnContext, cancellationToken); var (intent, score) = recognizerResult.GetTopScoringIntent();Hope that helps!
Hi @ivorb,
I agree with BeigeBadger there's not enough documentation on how to migrate BotServices to this new model.
The example provided is ok for a simple test but what happens with a more complex implementation? I used to load all services from BotConfiguration file and passing to a new BotServices class in the past:
services.AddSingleton(sp => new BotServices(botConfig, Configuration));
Now it's not clear within Microsoft documentation on how to adjust this configuration after 4.3 version as BotServices has been deprecated, now it is not possible to inject all these services into IServiceCollection object and be able to consume from dialogs as I was used to.
I'd appreciate any assistance you may provide on this matter.
Thanks!
Most helpful comment
Hi @ivorb,
I agree with BeigeBadger there's not enough documentation on how to migrate BotServices to this new model.
The example provided is ok for a simple test but what happens with a more complex implementation? I used to load all services from BotConfiguration file and passing to a new BotServices class in the past:
services.AddSingleton(sp => new BotServices(botConfig, Configuration));
Now it's not clear within Microsoft documentation on how to adjust this configuration after 4.3 version as BotServices has been deprecated, now it is not possible to inject all these services into IServiceCollection object and be able to consume from dialogs as I was used to.
I'd appreciate any assistance you may provide on this matter.
Thanks!