Skip to content

Commit

Permalink
Revert #2 files to match originals in Samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce Haley committed Jan 19, 2022
1 parent 9efac23 commit 82b6757
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v$templateversion$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ private Attachment CreateAdaptiveCardAttachment()
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FlightBookingRecognizer(IConfiguration configuration)
configuration["LuisAppId"],
configuration["LuisAPIKey"],
"https://" + configuration["LuisAPIHostName"]);

// Set the recognizer options depending on which endpoint version you want to use.
// More details can be found in https://docs.microsoft.com/en-gb/azure/cognitive-services/luis/luis-migration-api-v3
var recognizerOptions = new LuisRecognizerOptionsV3(luisApplication)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Bot.Connector.Authentication;

using $safeprojectname$.Bots;
using $safeprojectname$.Dialogs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected BotTestBase(ITestOutputHelper output)
/// having to put them in git.
/// If you use launch settings, make sure you set the Copy to Output Directory property to Copy Always.
/// </summary>
/// <param name="launchSettingsFile">The relative path to the launch settings file (i.e.: "Properties//launchSettings.json").</param>
/// <param name="launchSettingsFile">The relative path to the launch settings file (i.e.: "Properties//launchSettings.json")</param>
private static void LoadLaunchSettingsIntoEnvVariables(string launchSettingsFile)
{
if (!File.Exists(launchSettingsFile))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v$templateversion$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ private Attachment CreateAdaptiveCardAttachment()
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v$templateversion$
Expand All @@ -20,12 +20,10 @@ namespace $ext_safeprojectname$.Bots
public class DialogBot<T> : ActivityHandler
where T : Dialog
{
#pragma warning disable SA1401 // Fields should be private
protected readonly Dialog Dialog;
protected readonly BotState ConversationState;
protected readonly BotState UserState;
protected readonly ILogger Logger;
#pragma warning restore SA1401 // Fields should be private

public DialogBot(ConversationState conversationState, UserState userState, T dialog, ILogger<DialogBot<T>> logger)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v$templateversion$
Expand All @@ -17,22 +17,21 @@ namespace $ext_safeprojectname$.Controllers
[ApiController]
public class BotController : ControllerBase
{
private readonly IBotFrameworkHttpAdapter _adapter;
private readonly IBot _bot;
private readonly IBotFrameworkHttpAdapter Adapter;
private readonly IBot Bot;

public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
{
_adapter = adapter;
_bot = bot;
Adapter = adapter;
Bot = bot;
}

[HttpPost]
[HttpGet]
[HttpPost, HttpGet]
public async Task PostAsync()
{
// Delegate the processing of the HTTP POST to the adapter.
// The adapter will invoke the bot.
await _adapter.ProcessAsync(Request, Response, _bot);
await Adapter.ProcessAsync(Request, Response, Bot);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v$templateversion$
Expand All @@ -23,28 +23,19 @@ public BookingDialog()
AddDialog(new TextPrompt(nameof(TextPrompt)));
AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
AddDialog(new DateResolverDialog());

var waterfallSteps = new WaterfallStep[]
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
DestinationStepAsync,
OriginStepAsync,
TravelDateStepAsync,
ConfirmStepAsync,
FinalStepAsync,
};

AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
DestinationStepAsync,
OriginStepAsync,
TravelDateStepAsync,
ConfirmStepAsync,
FinalStepAsync,
}));

// The initial child Dialog to run.
InitialDialogId = nameof(WaterfallDialog);
}

private static bool IsAmbiguous(string timex)
{
var timexProperty = new TimexProperty(timex);
return !timexProperty.Types.Contains(Constants.TimexTypes.Definite);
}

private async Task<DialogTurnResult> DestinationStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var bookingDetails = (BookingDetails)stepContext.Options;
Expand Down Expand Up @@ -110,5 +101,11 @@ private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepCon

return await stepContext.EndDialogAsync(null, cancellationToken);
}

private static bool IsAmbiguous(string timex)
{
var timexProperty = new TimexProperty(timex);
return !timexProperty.Types.Contains(Constants.TimexTypes.Definite);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v$templateversion$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v$templateversion$
Expand All @@ -22,37 +22,16 @@ public DateResolverDialog(string id = null)
: base(id ?? nameof(DateResolverDialog))
{
AddDialog(new DateTimePrompt(nameof(DateTimePrompt), DateTimePromptValidator));

var waterfallSteps = new WaterfallStep[]
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
InitialStepAsync,
FinalStepAsync,
};

AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
InitialStepAsync,
FinalStepAsync,
}));

// The initial child Dialog to run.
InitialDialogId = nameof(WaterfallDialog);
}

private static Task<bool> DateTimePromptValidator(PromptValidatorContext<IList<DateTimeResolution>> promptContext, CancellationToken cancellationToken)
{
if (promptContext.Recognized.Succeeded)
{
// This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.
// TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.
var timex = promptContext.Recognized.Value[0].Timex.Split('T')[0];

// If this is a definite Date including year, month and day we are good otherwise reprompt.
// A better solution might be to let the user know what part is actually missing.
var isDefinite = new TimexProperty(timex).Types.Contains(Constants.TimexTypes.Definite);

return Task.FromResult(isDefinite);
}

return Task.FromResult(false);
}

private async Task<DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var timex = (string)stepContext.Options;
Expand All @@ -63,8 +42,7 @@ private async Task<DialogTurnResult> InitialStepAsync(WaterfallStepContext stepC
if (timex == null)
{
// We were not given any date at all so prompt the user.
return await stepContext.PromptAsync(
nameof(DateTimePrompt),
return await stepContext.PromptAsync(nameof(DateTimePrompt),
new PromptOptions
{
Prompt = promptMessage,
Expand All @@ -77,8 +55,7 @@ private async Task<DialogTurnResult> InitialStepAsync(WaterfallStepContext stepC
if (!timexProperty.Types.Contains(Constants.TimexTypes.Definite))
{
// This is essentially a "reprompt" of the data we were given up front.
return await stepContext.PromptAsync(
nameof(DateTimePrompt),
return await stepContext.PromptAsync(nameof(DateTimePrompt),
new PromptOptions
{
Prompt = repromptMessage,
Expand All @@ -93,5 +70,23 @@ private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepCon
var timex = ((List<DateTimeResolution>)stepContext.Result)[0].Timex;
return await stepContext.EndDialogAsync(timex, cancellationToken);
}

private static Task<bool> DateTimePromptValidator(PromptValidatorContext<IList<DateTimeResolution>> promptContext, CancellationToken cancellationToken)
{
if (promptContext.Recognized.Succeeded)
{
// This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.
// TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.
var timex = promptContext.Recognized.Value[0].Timex.Split('T')[0];

// If this is a definite Date including year, month and day we are good otherwise reprompt.
// A better solution might be to let the user know what part is actually missing.
var isDefinite = new TimexProperty(timex).Types.Contains(Constants.TimexTypes.Definite);

return Task.FromResult(isDefinite);
}

return Task.FromResult(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v$templateversion$
Expand All @@ -21,59 +21,29 @@ namespace $ext_safeprojectname$.Dialogs
{
public class MainDialog : ComponentDialog
{
private readonly ILogger _logger;
private readonly FlightBookingRecognizer _luisRecognizer;
protected readonly ILogger Logger;

// Dependency injection uses this constructor to instantiate MainDialog
public MainDialog(FlightBookingRecognizer luisRecognizer, BookingDialog bookingDialog, ILogger<MainDialog> logger)
: base(nameof(MainDialog))
{
_luisRecognizer = luisRecognizer;
_logger = logger;
Logger = logger;

AddDialog(new TextPrompt(nameof(TextPrompt)));
AddDialog(bookingDialog);

var waterfallSteps = new WaterfallStep[]
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
IntroStepAsync,
ActStepAsync,
FinalStepAsync,
};

AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
IntroStepAsync,
ActStepAsync,
FinalStepAsync,
}));

// The initial child Dialog to run.
InitialDialogId = nameof(WaterfallDialog);
}

// Shows a warning if the requested From or To cities are recognized as entities but they are not in the Airport entity list.
// In some cases LUIS will recognize the From and To composite entities as a valid cities but the From and To Airport values
// will be empty if those entity values can't be mapped to a canonical item in the Airport.
private static async Task ShowWarningForUnsupportedCities(ITurnContext context, FlightBooking luisResult, CancellationToken cancellationToken)
{
var unsupportedCities = new List<string>();

var fromEntities = luisResult.FromEntities;
if (!string.IsNullOrEmpty(fromEntities.From) && string.IsNullOrEmpty(fromEntities.Airport))
{
unsupportedCities.Add(fromEntities.From);
}

var toEntities = luisResult.ToEntities;
if (!string.IsNullOrEmpty(toEntities.To) && string.IsNullOrEmpty(toEntities.Airport))
{
unsupportedCities.Add(toEntities.To);
}

if (unsupportedCities.Any())
{
var messageText = $"Sorry but the following airports are not supported: {string.Join(',', unsupportedCities)}";
var message = MessageFactory.Text(messageText, messageText, InputHints.IgnoringInput);
await context.SendActivityAsync(message, cancellationToken);
}
}

private async Task<DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
if (!_luisRecognizer.IsConfigured)
Expand Down Expand Up @@ -135,6 +105,33 @@ private async Task<DialogTurnResult> ActStepAsync(WaterfallStepContext stepConte
return await stepContext.NextAsync(null, cancellationToken);
}

// Shows a warning if the requested From or To cities are recognized as entities but they are not in the Airport entity list.
// In some cases LUIS will recognize the From and To composite entities as a valid cities but the From and To Airport values
// will be empty if those entity values can't be mapped to a canonical item in the Airport.
private static async Task ShowWarningForUnsupportedCities(ITurnContext context, FlightBooking luisResult, CancellationToken cancellationToken)
{
var unsupportedCities = new List<string>();

var fromEntities = luisResult.FromEntities;
if (!string.IsNullOrEmpty(fromEntities.From) && string.IsNullOrEmpty(fromEntities.Airport))
{
unsupportedCities.Add(fromEntities.From);
}

var toEntities = luisResult.ToEntities;
if (!string.IsNullOrEmpty(toEntities.To) && string.IsNullOrEmpty(toEntities.Airport))
{
unsupportedCities.Add(toEntities.To);
}

if (unsupportedCities.Any())
{
var messageText = $"Sorry but the following airports are not supported: {string.Join(',', unsupportedCities)}";
var message = MessageFactory.Text(messageText, messageText, InputHints.IgnoringInput);
await context.SendActivityAsync(message, cancellationToken);
}
}

private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
// If the child dialog ("BookingDialog") was cancelled, the user failed to confirm or if the intent wasn't BookFlight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Bot.Connector.Authentication;

using $safeprojectname$.Bots;
using $safeprojectname$.Dialogs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v$templateversion$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
Expand Down

0 comments on commit 82b6757

Please sign in to comment.