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

[Skills& VA] Fallback rule support #1971

Merged
merged 8 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.5.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.5.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.5.1" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.5.3" />
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.5.3" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.6.0-daily6" />
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.6.0-daily6" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.5.1" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.5.1" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.5.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private async Task PopulateStateFromSemanticAction(ITurnContext context)
switch (dc.Context.Activity.Name)
{
case TokenEvents.TokenResponseEventName:
case SkillEvents.FallbackHandledEventName:
{
// Auth dialog completion
var result = await dc.ContinueDialogAsync();
Expand Down
145 changes: 104 additions & 41 deletions skills/src/csharp/calendarskill/calendarskill/Dialogs/SummaryDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CalendarSkill.Adapters;
using CalendarSkill.Models;
using CalendarSkill.Responses.Shared;
using CalendarSkill.Responses.Summary;
Expand All @@ -13,6 +14,8 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Skills.Models;
using Microsoft.Bot.Builder.Solutions;
using Microsoft.Bot.Builder.Solutions.Resources;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Util;
Expand Down Expand Up @@ -69,13 +72,22 @@ public SummaryDialog(
AfterReadOutEvent,
};

var retryUnknown = new WaterfallStep[]
{
SendFallback,
RetryInput,
HandleActions,
};

// Define the conversation flow using a waterfall model.
AddDialog(new WaterfallDialog(Actions.GetEventsInit, initStep) { TelemetryClient = telemetryClient });
AddDialog(new WaterfallDialog(Actions.ShowNextEvent, showNext) { TelemetryClient = telemetryClient });
AddDialog(new WaterfallDialog(Actions.ShowEventsSummary, showSummary) { TelemetryClient = telemetryClient });
AddDialog(new WaterfallDialog(Actions.Read, readEvent) { TelemetryClient = telemetryClient });
AddDialog(updateEventDialog ?? throw new ArgumentNullException(nameof(updateEventDialog)));
AddDialog(changeEventStatusDialog ?? throw new ArgumentNullException(nameof(changeEventStatusDialog)));
AddDialog(new WaterfallDialog(Actions.RetryUnknown, retryUnknown) { TelemetryClient = telemetryClient });
AddDialog(new EventPrompt(Actions.FallbackEventPrompt, SkillEvents.FallbackHandledEventName, ResponseValidatorAsync));

// Set starting dialog for component
InitialDialogId = Actions.GetEventsInit;
Expand Down Expand Up @@ -590,58 +602,57 @@ await sc.Context.SendActivityAsync(await GetOverviewMeetingListResponseAsync(
if (state.FocusEvents.Count <= 0)
{
var currentList = GetCurrentPageMeetings(state.SummaryEvents, state);
if (state.UserSelectIndex < currentList.Count)
if (state.UserSelectIndex >= 0 && state.UserSelectIndex < currentList.Count)
{
state.FocusEvents.Add(currentList[state.UserSelectIndex]);
}
else
{
return await sc.EndDialogAsync();
}
}

var focusEvent = state.FocusEvents.First();
if (focusEvent.IsOrganizer)
if (state.FocusEvents != null && state.FocusEvents.Count > 0)
{
if (topIntent == CalendarLuis.Intent.ChangeCalendarEntry)
var focusEvent = state.FocusEvents.First();
if (focusEvent != null)
{
state.Events.Add(focusEvent);
state.IsActionFromSummary = true;
return await sc.BeginDialogAsync(nameof(UpdateEventDialog), sc.Options);
}
if (focusEvent.IsOrganizer)
{
if (topIntent == CalendarLuis.Intent.ChangeCalendarEntry)
{
state.Events.Add(focusEvent);
state.IsActionFromSummary = true;
return await sc.BeginDialogAsync(nameof(UpdateEventDialog), sc.Options);
}

if (topIntent == CalendarLuis.Intent.DeleteCalendarEntry)
{
state.Events.Add(focusEvent);
state.IsActionFromSummary = true;
return await sc.BeginDialogAsync(nameof(ChangeEventStatusDialog), sc.Options);
}
}
else if (focusEvent.IsAccepted)
{
if (topIntent == CalendarLuis.Intent.DeleteCalendarEntry)
{
state.Events.Add(focusEvent);
state.IsActionFromSummary = true;
return await sc.BeginDialogAsync(nameof(ChangeEventStatusDialog), sc.Options);
}
}
else
{
if (topIntent == CalendarLuis.Intent.DeleteCalendarEntry || topIntent == CalendarLuis.Intent.AcceptEventEntry)
{
state.Events.Add(focusEvent);
state.IsActionFromSummary = true;
return await sc.BeginDialogAsync(nameof(ChangeEventStatusDialog), sc.Options);
}
}
if (topIntent == CalendarLuis.Intent.DeleteCalendarEntry)
{
state.Events.Add(focusEvent);
state.IsActionFromSummary = true;
return await sc.BeginDialogAsync(nameof(ChangeEventStatusDialog), sc.Options);
}
}
else if (focusEvent.IsAccepted)
{
if (topIntent == CalendarLuis.Intent.DeleteCalendarEntry)
{
state.Events.Add(focusEvent);
state.IsActionFromSummary = true;
return await sc.BeginDialogAsync(nameof(ChangeEventStatusDialog), sc.Options);
}
}
else
{
if (topIntent == CalendarLuis.Intent.DeleteCalendarEntry || topIntent == CalendarLuis.Intent.AcceptEventEntry)
{
state.Events.Add(focusEvent);
state.IsActionFromSummary = true;
return await sc.BeginDialogAsync(nameof(ChangeEventStatusDialog), sc.Options);
}
}

if (state.FocusEvents != null)
{
return await sc.BeginDialogAsync(Actions.Read, sc.Options);
return await sc.BeginDialogAsync(Actions.Read, sc.Options);
}
}

return await sc.NextAsync();
return await sc.ReplaceDialogAsync(Actions.RetryUnknown, sc.Options);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -831,5 +842,57 @@ private bool SearchesTodayMeeting(CalendarSkillState state)
!state.EndTime.Any() &&
EventModel.IsSameDate(searchDate, userNow);
}

protected Task<bool> ResponseValidatorAsync(PromptValidatorContext<Activity> pc, CancellationToken cancellationToken)
{
var activity = pc.Recognized.Value;
if (activity != null && activity.Type == ActivityTypes.Event && activity.Name == SkillEvents.FallbackHandledEventName)
{
return Task.FromResult(true);
}

return Task.FromResult(false);
}

protected async Task<DialogTurnResult> SendFallback(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
{
try
{
var state = await Accessor.GetAsync(sc.Context);

// Send Fallback Event
if (sc.Context.Adapter is CalendarSkillWebSocketBotAdapter remoteInvocationAdapter)
{
await remoteInvocationAdapter.SendRemoteFallbackEventAsync(sc.Context, cancellationToken).ConfigureAwait(false);

// Wait for the FallbackHandle event
return await sc.PromptAsync(Actions.FallbackEventPrompt, new PromptOptions()).ConfigureAwait(false);
}

return await sc.NextAsync();
}
catch (Exception ex)
{
await HandleDialogExceptions(sc, ex);

return new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs);
}
}

protected async Task<DialogTurnResult> RetryInput(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
{
try
{
var state = await Accessor.GetAsync(sc.Context);

return await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = ResponseManager.GetResponse(CalendarSharedResponses.RetryInput) });
}
catch (Exception ex)
{
await HandleDialogExceptions(sc, ex);

return new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public class CalendarSharedResponses : IResponseIdCollection
public const string ActionEnded = "ActionEnded";
public const string CalendarErrorMessage = "CalendarErrorMessage";
public const string CalendarErrorMessageBotProblem = "CalendarErrorMessageBotProblem";
public const string RetryInput = "RetryInput";
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading