This sample shows how to integrate LUIS to a bot with ASP.Net Core 2.
- Clone the samples repository
git clone https://github.com/Microsoft/botbuilder-samples.git- Install the Bot CLI Tools
npm install -g chatdown msbot ludown luis-apis qnamaker botdispatch luisgen- Setup Azure Powershell (If you have never done so before)
- To login, run:
Connect-AzureRmAccount- To select your Azure subscription, run:
Select-AzureRmSubscription -Subscription "subscription-name"-
Collect your Luis Authoring Key from the the LUIS portal by selecting your name in the top right corner. Save this key for the next step.
-
Run the following command from the project directory:
msbot clone services --name "<NAME>" --luisAuthoringKey "<YOUR AUTHORING KEY>" --folder "DeploymentScripts/MsbotClone" --location "westus" --verbose --appId <YOUR APP ID> --appSecret <YOUR APP SECRET PASSWORD>NOTE: You can obtain your appId and appSecret at the Microsoft's Application Registration Portal
NOTE: By default your Luis Applications will be deployed to your free starter endpoint. An Azure LUIS service will be deployed along with your bot but you must manually add and publish to it from the luis.ai portal and update your key in the .bot file.
- Note the generated secret generated by msbot.
- The secret key is used later for
appsettings.json.
The secret used to decrypt <NAME>.bot is:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
NOTE: This secret is not recoverable and you should store this secret in a secure place according to best security practices.
Your project may be configured to rely on this secret and you should update it as appropriate.- Inspect Bot configuration file.
- The
msbot clonecommand above generates a bot configuration file. - The name of the bot configuration file is .bot, where is the name of your bot used in the
msbot clonestep. - The configuration file can be loaded by the Microsoft Bot Framework Emulator.
- Update in `botbuilder-samples\samples\csharp_dotnetcore\21.luis-with-appsinsights\Startup.cs'.
public void ConfigureServices(IServiceCollection services)
{
...
var botConfig = BotConfiguration.Load(botFilePath ?? @".\luis-with-appinsights.bot"..);
...
- Update "YOUR_LUIS_SERVICE_NAME" in `botbuilder-samples\samples\csharp_dotnetcore\21.luis-with-appsinsights\LuisBot.cs'.
public class LuisBot : IBot
{
...
public static readonly string LuisKey = "YOUR_LUIS_SERVICE_NAME";
- Right click on the generated bot configuration file, click "Properties".
- Ensure "Copy to Output Directory" is set to "Copy always".
- Update your
appsettings.jsonwith your .bot file path and .bot file secret.
- Update the
botFilePathwith the name of your generated bot configuration file. - Update the
botFileSecretwith the secret that the msbot tool generated from step 5 above.
{
"botFilePath": "<YOUR BOT CONFIG>.bot",
"botFileSecret": "<YOUR BOT SECRET>"
}-
Navigate to LUIS portal.
-
Click the
Sign inbutton. -
Click on
My Apps. -
Click on the
Import new appbutton. -
Click on the
Choose Fileand select LUIS-Reminders.json from thebotbuilder-samples\samples\csharp_dotnetcore\23.luis-with-appinsights\CognitiveModelsfolder. -
Update luis-with-appinsights.bot file with your AppId, SubscriptionKey, Region and Version. You can find this information under "Publish" tab for your LUIS application at LUIS portal. For example, for https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/XXXXXXXXXXXXX?subscription-key=YYYYYYYYYYYY&verbose=true&timezoneOffset=0&q=
- AppId = XXXXXXXXXXXXX
- SubscriptionKey = YYYYYYYYYYYY
- Region = westus
The Version is listed on the page.
-
Update luis-with-appinsights.bot file with your Authoring Key.
You can find this under your user settings at luis.ai. Click on your name in the upper right hand corner of the portal, and click on the "Settings" menu option. NOTE: Once you publish your app on LUIS portal for the first time, it takes some time for the endpoint to become available, about 5 minutes of wait should be sufficient.
- (Optional) Install the LUDown here to help describe language understanding components for your bot.
- Follow instructions here to set up your Application Insights service.
- Note: The Application Insights will automatically update the appsettings.json file.
- Navigate to the samples folder (
botbuilder-samples\samples\csharp_dotnetcore\21.luis-with-appsinsights) and openLuisBotAppInsights.csprojin Visual Studio - Run the project (press
F5key).
- Install the .NET Core CLI tools.
- Using the command line, navigate to
botbuilder-samples\samples\csharp_dotnetcore\21.luis-with-appsinsightsfolder. - Type 'dotnet run'.
Microsoft Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
- Install the Bot Framework Emulator from here.
- Launch the Bot Framework Emulator
- File -> Open bot and navigate to
botbuilder-samples\samples\csharp_dotnetcore\21.luis-with-appsinsightsfolder. - Select luis-with-appinsights.bot file.
You can use the MSBot Bot Builder CLI tool to clone and configure any services this sample depends on.
To install all Bot Builder tools -
Ensure you have Node.js version 8.5 or higher
npm i -g msbot chatdown ludown qnamaker luis-apis botdispatch luisgenTo clone this bot, run
msbot clone services -f DeploymentScripts/MsbotClone -n <BOT-NAME> -l <Azure-location, ie westus> --subscriptionId <Azure-subscription-id>