Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
[POI] update flow (#2511)
Browse files Browse the repository at this point in the history
* use reject/select none to reprompt set current location
* use reject/select none to cancel poi selection
  • Loading branch information
xieofxie authored and ryanisgrig committed Oct 21, 2019
1 parent 9024d71 commit 95938c2
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ protected async Task<DialogTurnResult> SendEvent(WaterfallStepContext sc, Cancel
// Update the destination state with user choice.
userSelectIndex = (sc.Result as FoundChoice).Index;

if (userSelectIndex < 0 || userSelectIndex >= state.LastFoundPointOfInterests.Count)
{
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(POISharedResponses.CancellingMessage));
return await sc.EndDialogAsync();
}

state.Destination = state.LastFoundPointOfInterests[userSelectIndex];
state.LastFoundPointOfInterests = null;
}
Expand Down
6 changes: 6 additions & 0 deletions skills/csharp/pointofinterestskill/Dialogs/MainDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ public MainDialog(
else
{
var luisResult = await luisService.RecognizeAsync<General>(dc.Context, cancellationToken);
var state = await _stateAccessor.GetAsync(dc.Context, () => new PointOfInterestSkillState());
var topIntent = luisResult.TopIntent();

if (topIntent.score > 0.5)
{
state.GeneralIntent = topIntent.intent;
switch (topIntent.intent)
{
case General.Intent.Cancel:
Expand All @@ -225,6 +227,10 @@ public MainDialog(
}
}
}
else
{
state.GeneralIntent = General.Intent.None;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public PointOfInterestDialogBase(

AddDialog(new TextPrompt(Actions.CurrentLocationPrompt));
AddDialog(new ConfirmPrompt(Actions.ConfirmPrompt) { Style = ListStyle.Auto, });
AddDialog(new ChoicePrompt(Actions.SelectPointOfInterestPrompt, InterruptablePromptValidator) { Style = ListStyle.None });
AddDialog(new ChoicePrompt(Actions.SelectPointOfInterestPrompt, CanNoInterruptablePromptValidator) { Style = ListStyle.None });
AddDialog(new ChoicePrompt(Actions.SelectActionPrompt, InterruptablePromptValidator) { Style = ListStyle.None });
AddDialog(new ChoicePrompt(Actions.SelectRoutePrompt) { ChoiceOptions = new ChoiceFactoryOptions { InlineSeparator = string.Empty, InlineOr = string.Empty, InlineOrMore = string.Empty, IncludeNumbers = true } });
}
Expand Down Expand Up @@ -226,16 +226,19 @@ protected async Task<DialogTurnResult> ProcessCurrentLocationSelection(Waterfall
}
else
{
await sc.Context.SendActivityAsync(cancelMessage);

return await sc.EndDialogAsync();
return await sc.ReplaceDialogAsync(Actions.CheckForCurrentLocation);
}
}
else if (sc.Result is FoundChoice)
{
// Update the current coordinates state with user choice.
userSelectIndex = (sc.Result as FoundChoice).Index;

if (userSelectIndex < 0 || userSelectIndex >= state.LastFoundPointOfInterests.Count)
{
return await sc.ReplaceDialogAsync(Actions.CheckForCurrentLocation);
}

state.CurrentCoordinates = state.LastFoundPointOfInterests[userSelectIndex].Geolocation;
state.LastFoundPointOfInterests = null;
}
Expand Down Expand Up @@ -377,6 +380,12 @@ protected async Task<DialogTurnResult> ProcessPointOfInterestSelection(Waterfall
// Update the destination state with user choice.
userSelectIndex = (sc.Result as FoundChoice).Index;

if (userSelectIndex < 0 || userSelectIndex >= state.LastFoundPointOfInterests.Count)
{
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(POISharedResponses.CancellingMessage));
return await sc.EndDialogAsync();
}

state.Destination = state.LastFoundPointOfInterests[userSelectIndex];
state.LastFoundPointOfInterests = null;
}
Expand Down Expand Up @@ -892,6 +901,27 @@ private async Task<bool> InterruptablePromptValidator<T>(PromptValidatorContext<
}
}

private async Task<bool> CanNoInterruptablePromptValidator(PromptValidatorContext<FoundChoice> promptContext, CancellationToken cancellationToken)
{
if (promptContext.Recognized.Succeeded)
{
return true;
}
else
{
var state = await Accessor.GetAsync(promptContext.Context);
if (state.GeneralIntent == General.Intent.Reject || state.GeneralIntent == General.Intent.SelectNone)
{
promptContext.Recognized.Value = new FoundChoice { Index = -1 };
return true;
}
else
{
return await InterruptablePromptValidator(promptContext, cancellationToken);
}
}
}

private class ImageSize
{
public const int RouteWidth = 440;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public PointOfInterestSkillState()

public int UserSelectIndex { get; set; }

// from OnInterruptDialogAsync
public General.Intent GeneralIntent { get; set; }

public void Clear()
{
Destination = null;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@
"PromptForCurrentLocation": {
"replies": [
{
"text": "What's your address?",
"speak": "What's your address?"
"text": "What's your current address?",
"speak": "What's your current address?"
},
{
"text": "Where are you? Try providing a city or address.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@
"PromptForCurrentLocation": {
"replies": [
{
"speak": "你的地址是什么?",
"text": "你的地址是什么?"
"speak": "你目前的地址是什么?",
"text": "你目前的地址是什么?"
},
{
"speak": "你在哪里?尝试提供城市或地址。",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ await GetTestFlow()
.StartTestAsync();
}

/// <summary>
/// Reprompt current location and find nearest points of interest nearby.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[TestMethod]
public async Task RepromptForCurrentAndRouteToNearestPointOfInterestTest()
{
await GetTestFlow()
.Send(FindPointOfInterestUtterances.FindNearestPoi)
.AssertReply(AssertContains(POISharedResponses.PromptForCurrentLocation, null))
.Send(ContextStrings.Ave)
.AssertReply(AssertContains(POISharedResponses.CurrentLocationMultipleSelection, new string[] { CardStrings.Overview }))
.Send(BaseTestUtterances.No)
.AssertReply(AssertContains(POISharedResponses.PromptForCurrentLocation, null))
.Send(ContextStrings.Ave)
.AssertReply(AssertContains(POISharedResponses.CurrentLocationMultipleSelection, new string[] { CardStrings.Overview }))
.Send(BaseTestUtterances.OptionOne)
.AssertReply(AssertContains(null, new string[] { CardStrings.DetailsNoCall }))
.Send(BaseTestUtterances.ShowDirections)
.AssertReply(AssertContains(null, new string[] { CardStrings.Route }))
.Send(BaseTestUtterances.StartNavigation)
.AssertReply(CheckForEvent())
.AssertReply(CompleteDialog())
.StartTestAsync();
}

/// <summary>
/// Find points of interest nearby and get directions to one by index number.
/// </summary>
Expand Down Expand Up @@ -81,6 +107,23 @@ await GetTestFlow()
.StartTestAsync();
}

/// <summary>
/// Find points of interest nearby and select none to cancel.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[TestMethod]
public async Task RouteToPointOfInterestAndSelectNoneTest()
{
await GetTestFlow()
.Send(BaseTestUtterances.LocationEvent)
.Send(FindPointOfInterestUtterances.WhatsNearby)
.AssertReply(AssertContains(POISharedResponses.MultipleLocationsFound, new string[] { CardStrings.Overview }))
.Send(GeneralTestUtterances.SelectNone)
.AssertReply(AssertContains(POISharedResponses.CancellingMessage, null))
.AssertReply(CompleteDialog())
.StartTestAsync();
}

/// <summary>
/// Find points of interest nearby then call.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ namespace PointOfInterestSkill.Tests.Flow.Utterances
{
public class GeneralTestUtterances : Dictionary<string, General>
{
public GeneralTestUtterances()
{
AddIntent(BaseTestUtterances.No, Intent.Reject);
AddIntent(SelectNone, Intent.SelectNone);
}

public static string UnknownIntent { get; } = "what's the weather?";

public static string SelectNone { get; } = "none of these";

public static double TopIntentScore { get; } = 0.9;

public General GetBaseNoneIntent()
Expand All @@ -23,5 +31,19 @@ public General GetBaseNoneIntent()

return generalIntent;
}

protected void AddIntent(
string userInput,
Intent intent)
{
var generalIntent = new General
{
Text = userInput,
Intents = new Dictionary<Intent, IntentScore>()
};
generalIntent.Intents.Add(intent, new IntentScore() { Score = TopIntentScore });

Add(userInput, generalIntent);
}
}
}

0 comments on commit 95938c2

Please sign in to comment.