Introduction
In my previous article, I discussed the language understanding tool for the chatbot. We will continue here by adding some services of LUIS to our ChatBot, by using Visual Studio. Also, we will see how to add visual responses using adaptive cards with the chatbot. All the lab tools are remaining the same, we will just move with the coding section using Microsoft Visual Studio as an IDE. Natural interfaces are the same as to understand the voice, text, and touch. In this article, I'll show you a user clicking on an item from an image carousel. Adaptive cards enable a developer to define the user interface element using JSON by the host platform in order to build an intelligent bot.
Before moving towards the visual response, we have to add a service to our bot.
Install LUIS package
Step 1
Click FILE from Visual Studio.
Step 2
Click Open Project/ Solution.
Step 3
Select the Solution file Downloads\buildanintelligentbot\src\TalkToMyBot.sln wait until it's loaded.
Step 4
Click the Solution and then click Restore NuGet Packages.
Check out this image:

Now, we will...
Install the LUIS package from NuGet
Step 1
Right-click on the ChatBot project and click Manage NuGet Packages.

Step 2
Select the Browse tab and search for Microsoft.Bot.Builder.AI.Luis
Step 3
Click on the NuGet package. Select Version 4.4 and click install. Higher or latest versions might raise errors.
These steps are both shown in this image:

Add the LUIS recognizer to our Bot
LUIS is a cognitive service that is accessible through RESTful endpoints. This Bot Builder SDK has inbuilt middleware that integrates the code processing for this intent, not on natural language.
We have to follow these steps:
Step 1
Go to Visual Studio, Open the appsettings.json file
Step 2
Update the following configuration values.
Replace
<your_luis_app_id> and <your_luis_api_key> with the values that you had stored in Notepad previously from the LUIS Portal.Step 3
Now open the Startup.cs file.
Step 4
Add the following namespace at the top of this file.
- using Microsoft.Bot.Builder.AI.Luis;
Step 5
Find the comment // and create Luis recognizer around line 67, then replace it with this code snippet:
- var luisApplication = new LuisApplication(
- Configuration["LuisAppId"],
- Configuration["LuisAPIKey"],
- "https://" + Configuration["LuisAPIHostName"]);
- services.AddSingleton(new LuisRecognizer(luisApplication));
Adjust our Bot to process the Results
Do some modifications in the code and get the results from LUIS.
Step 1
Open EchoBot.cs
Add the following namespace at the top of this file.
- using Microsoft.Bot.Builder.AI.Luis;
Go to this comment:
// Add Luis Recognizerand replace it with this line:- protected LuisRecognizer _luis;
Constructor header is replaced with:
- public EchoBot(EchoBotAccessors accessors, IOptions<MySettings> config, LuisRecognizer luisRecognizer)
Step 4
Goto the comment line:
// Initialize the LUIS recognizer and replace it with this line:- _luis = luisRecognizer;
Step 5
Check for the comment:
// Handle LUIS intents recognition and replace it with this code snippet:- // Perform a call to LUIS to retrieve results for the current activity message.
- var luisResults = await _luis.RecognizeAsync(turnContext, cancellationToken).ConfigureAwait(false);
- var topScoringIntent = luisResults?.GetTopScoringIntent();
- var topIntent = topScoringIntent.Value.score > 0.5 ? topScoringIntent.Value.intent : string.Empty;
- // Your code goes here





Join the conversation! Your thoughts help the community grow.