Skip to content

Commit

Permalink
updated msbotClone and removed .bot file
Browse files Browse the repository at this point in the history
  • Loading branch information
lauren-mills committed Sep 21, 2018
1 parent e1305eb commit d538ca2
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public BotServices(BotConfiguration botConfiguration)
{
var luis = service as LuisService;
var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
LuisServices.Add(service.Name, new TelemetryLuisRecognizer(luisApp));
LuisServices.Add(service.Id, new TelemetryLuisRecognizer(luisApp));
break;
}

Expand All @@ -65,7 +65,7 @@ public BotServices(BotConfiguration botConfiguration)
Host = qna.Hostname,
};
var qnaMaker = new TelemetryQnAMaker(qnaEndpoint);
QnAServices.Add(qna.Name, qnaMaker);
QnAServices.Add(qna.Id, qnaMaker);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@
},
{
"type": "luis",
"id": "120",
"id": "general",
"name": "General"
},
{
"type": "qna",
"id": "85",
"id": "faq",
"name": "FAQ"
},
{
"type": "dispatch",
"id": "152",
"id": "dispatch",
"name": "Dispatch",
"serviceIds": [
"120",
"85"
"general",
"faq"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,55 @@
namespace $safeprojectname$
{
public class MainDialog : RouterDialog
{
private BotServices _services;
private UserState _userState;
private ConversationState _conversationState;
private MainResponses _responder = new MainResponses();
{
private BotServices _services;
private UserState _userState;
private ConversationState _conversationState;
private MainResponses _responder = new MainResponses();

public MainDialog(BotServices services, ConversationState conversationState, UserState userState)
: base(nameof(MainDialog))
{
_services = services ?? throw new ArgumentNullException(nameof(services));
_conversationState = conversationState;
_userState = userState;
public MainDialog(BotServices services, ConversationState conversationState, UserState userState)
: base(nameof(MainDialog))
{
_services = services ?? throw new ArgumentNullException(nameof(services));
_conversationState = conversationState;
_userState = userState;

AddDialog(new OnboardingDialog(_services, _userState.CreateProperty<OnboardingState>(nameof(OnboardingState))));
AddDialog(new EscalateDialog(_services));
}
AddDialog(new OnboardingDialog(_services, _userState.CreateProperty<OnboardingState>(nameof(OnboardingState))));
AddDialog(new EscalateDialog(_services));
}

protected override async Task OnStartAsync(DialogContext innerDc, CancellationToken cancellationToken = default(CancellationToken))
{
var onboardingAccessor = _userState.CreateProperty<OnboardingState>(nameof(OnboardingState));
var onboardingState = await onboardingAccessor.GetAsync(innerDc.Context, () => new OnboardingState());
protected override async Task OnStartAsync(DialogContext innerDc, CancellationToken cancellationToken = default(CancellationToken))
{
var onboardingAccessor = _userState.CreateProperty<OnboardingState>(nameof(OnboardingState));
var onboardingState = await onboardingAccessor.GetAsync(innerDc.Context, () => new OnboardingState());

var view = new MainResponses();
await view.ReplyWith(innerDc.Context, MainResponses.Intro);
var view = new MainResponses();
await view.ReplyWith(innerDc.Context, MainResponses.Intro);

if (string.IsNullOrEmpty(onboardingState.Name))
{
// This is the first time the user is interacting with the bot, so gather onboarding information.
await innerDc.BeginDialogAsync(nameof(OnboardingDialog));
}
if (string.IsNullOrEmpty(onboardingState.Name))
{
// This is the first time the user is interacting with the bot, so gather onboarding information.
await innerDc.BeginDialogAsync(nameof(OnboardingDialog));
}
}

protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
// Check dispatch result
var dispatchResult = await _services.DispatchRecognizer.RecognizeAsync<Dispatch>(dc.Context, CancellationToken.None);
var intent = dispatchResult.TopIntent().intent;

if (intent == Dispatch.Intent.l_General)
{
// Check dispatch result
var dispatchResult = await _services.DispatchRecognizer.RecognizeAsync<Dispatch>(dc.Context, CancellationToken.None);
var intent = dispatchResult.TopIntent().intent;
// If dispatch result is general luis model
_services.LuisServices.TryGetValue("general", out var luisService);

if (intent == Dispatch.Intent.l_General)
if (luisService == null)
{
throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
}
else
{
// If dispatch result is general luis model
var luisService = _services.LuisServices["$safeprojectname$_General"];
var result = await luisService.RecognizeAsync<General>(dc.Context, CancellationToken.None);

var generalIntent = result?.TopIntent().intent;
Expand Down Expand Up @@ -100,10 +107,18 @@ public MainDialog(BotServices services, ConversationState conversationState, Use
break;
}
}
}
}
else if (intent == Dispatch.Intent.q_FAQ)
{
_services.QnAServices.TryGetValue("faq", out var qnaService);

if(qnaService == null)
{
throw new Exception("The specified QnAMaker Service could not be found in your Bot Services configuration.");
}
else if (intent == Dispatch.Intent.q_FAQ)
else
{
var qnaService = _services.QnAServices["FAQ"];
var answers = await qnaService.GetAnswersAsync(dc.Context);

if (answers != null && answers.Count() > 0)
Expand All @@ -112,11 +127,12 @@ public MainDialog(BotServices services, ConversationState conversationState, Use
}
}
}
}

protected override async Task CompleteAsync(DialogContext innerDc, CancellationToken cancellationToken = default(CancellationToken))
{
// The active dialog's stack ended with a complete status
await _responder.ReplyWith(innerDc.Context, MainResponses.Completed);
}
protected override async Task CompleteAsync(DialogContext innerDc, CancellationToken cancellationToken = default(CancellationToken))
{
// The active dialog's stack ended with a complete status
await _responder.ReplyWith(innerDc.Context, MainResponses.Completed);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Luis;
Expand All @@ -27,24 +28,32 @@ public EnterpriseDialog(BotServices botServices, string dialogId)
protected override async Task<InterruptionStatus> OnDialogInterruptionAsync(DialogContext dc, CancellationToken cancellationToken)
{
// check luis intent
var luisService = _services.LuisServices["$safeprojectname$_General"];
var luisResult = await luisService.RecognizeAsync<General>(dc.Context, cancellationToken);
var intent = luisResult.TopIntent().intent;
_services.LuisServices.TryGetValue("general", out var luisService);

// Add the luis result (intent and entities) for further processing in the derived dialog
dc.Context.TurnState.Add(LuisResultKey, luisResult);

switch (intent)
if (luisService == null)
{
throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
}
else
{
case General.Intent.Cancel:
{
return await OnCancel(dc);
}

case General.Intent.Help:
{
return await OnHelp(dc);
}
var luisResult = await luisService.RecognizeAsync<General>(dc.Context, cancellationToken);
var intent = luisResult.TopIntent().intent;

// Add the luis result (intent and entities) for further processing in the derived dialog
dc.Context.TurnState.Add(LuisResultKey, luisResult);

switch (intent)
{
case General.Intent.Cancel:
{
return await OnCancel(dc);
}

case General.Intent.Help:
{
return await OnHelp(dc);
}
}
}

return InterruptionStatus.NoAction;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
</ItemGroup>

<ItemGroup>
<Folder Include="DeploymentScripts\msbotClone\" />
<Folder Include="Dialogs\Shared\Resources\" />
</ItemGroup>

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="EnterpriseBotTemplate.vsix" />
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
Expand Down

0 comments on commit d538ca2

Please sign in to comment.