Skip to content

Commit

Permalink
[netcore][20.qna-with-appinsights] Fix readme.md and issue with DI (#689
Browse files Browse the repository at this point in the history
)

* Fix typos

* Fix dependency injection
  • Loading branch information
enzocano authored and cleemullins committed Oct 13, 2018
1 parent 24754c9 commit 7cff8fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
18 changes: 6 additions & 12 deletions samples/csharp_dotnetcore/20.qna-with-appinsights/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ information under "Settings" tab for your QnA Maker Knowledge Base at [QnAMaker.
- (Optional) Follow instructions [here](https://github.com/Microsoft/botbuilder-tools/tree/master/packages/QnAMaker) to set up the
Qna Maker CLI to deploy the model.


## Visual Studio
- Navigate to the samples folder (`botbuilder-samples/samples/csharp_dotnetcore/20.qna-with-appinsights`) and open QnABot.csproj in Visual Studio.
- Hit F5
- In Visual Studio right click on the solution and select "Restore NuGet Packages".
- Run the project (press `F5` key)

## Visual Studio Code
- Open `botbuilder-samples/samples/csharp_dotnetcore/20.qna-with-appinsights` sample folder
- Bring up a terminal, navigate to `botbuilder-samples/samples/csharp_dotnetcore/20.qna-with-appinsights` folder.
- Type 'dotnet run'.
- In the Visual Studio Code terminal type `dotnet restore`.
- Type `dotnet run`.

## Testing the bot using Bot Framework Emulator
[Microsoft Bot Framework Emulator](https://github.com/microsoft/botframework-emulator) is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
Expand All @@ -50,17 +51,10 @@ Qna Maker CLI to deploy the model.
- Select the BotConfiguration.bot file.

# Deploy this bot to Azure
You can use the [MSBot](https://github.com/microsoft/botbuilder-tools) Bot Builder CLI tool to clone and configure any services this sample depends on.

To install all Bot Builder tools -
You can use the [MSBot](https://github.com/microsoft/botbuilder-tools) Bot Builder CLI tool to clone and configure any services this sample depends on. In order to install this and other tools, you can read [Installing CLI Tools](../../../Installing_CLI_tools.md).

Ensure you have [Node.js](https://nodejs.org/) version 8.5 or higher

```bash
npm i -g msbot chatdown ludown qnamaker luis-apis botdispatch luisgen
```
To clone this bot, run
```
```bash
msbot clone services -f deploymentScripts/msbotClone -n <BOT-NAME> -l <Azure-location> --subscriptionId <Azure-subscription-id>
```

Expand Down
23 changes: 11 additions & 12 deletions samples/csharp_dotnetcore/20.qna-with-appinsights/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.Integration;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Configuration;
using Microsoft.Bot.Connector.Authentication;
Expand Down Expand Up @@ -55,19 +54,19 @@ public Startup(IHostingEnvironment env)
/// <seealso cref="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.1"/>
public void ConfigureServices(IServiceCollection services)
{
services.AddBot<QnABot>(options =>
{
var secretKey = Configuration.GetSection("botFileSecret")?.Value;
var botFilePath = Configuration.GetSection("botFilePath")?.Value;
var secretKey = Configuration.GetSection("botFileSecret")?.Value;
var botFilePath = Configuration.GetSection("botFilePath")?.Value;

// Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
var botConfig = BotConfiguration.Load(botFilePath ?? @".\BotConfiguration.bot", secretKey);
services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot config file could not be loaded. ({botConfig})"));
// Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
var botConfig = BotConfiguration.Load(botFilePath ?? @".\BotConfiguration.bot", secretKey);
services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot config file could not be loaded. ({botConfig})"));

// Initialize Bot Connected Services clients.
var connectedServices = InitBotServices(botConfig);
services.AddSingleton(sp => connectedServices);
// Initialize Bot Connected Services clients.
var connectedServices = InitBotServices(botConfig);
services.AddSingleton(sp => connectedServices);

services.AddBot<QnABot>(options =>
{
// Retrieve current endpoint.
var environment = _isProduction ? "production" : "development";
var service = botConfig.Services.Where(s => s.Type == "endpoint" && s.Name == environment).FirstOrDefault();
Expand Down Expand Up @@ -217,4 +216,4 @@ private static BotServices InitBotServices(BotConfiguration config)
return connectedServices;
}
}
}
}

0 comments on commit 7cff8fc

Please sign in to comment.