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

Commit 2cc8216

Browse files
DingmaomaoBJTUlzc850612
authored andcommitted
[Lib] Fallback lib change (#1976)
* simplify lib change * fix as comments * fix as comments * fix as comments
1 parent 1d36b85 commit 2cc8216

File tree

6 files changed

+48
-159
lines changed

6 files changed

+48
-159
lines changed

lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/Dialogs/DispatchDialog.cs

Lines changed: 0 additions & 133 deletions
This file was deleted.

lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/Models/DispatchIntent.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillDialog.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
using Microsoft.Bot.Builder.Dialogs;
77
using Microsoft.Bot.Builder.Dialogs.Choices;
88
using Microsoft.Bot.Builder.Skills.Auth;
9-
using Microsoft.Bot.Builder.Skills.Dialogs;
109
using Microsoft.Bot.Builder.Skills.Models;
1110
using Microsoft.Bot.Builder.Skills.Models.Manifest;
1211
using Microsoft.Bot.Builder.Solutions;
1312
using Microsoft.Bot.Builder.Solutions.Authentication;
13+
using Microsoft.Bot.Builder.Solutions.Dialogs;
1414
using Microsoft.Bot.Builder.Solutions.Resources;
1515
using Microsoft.Bot.Schema;
1616
using Microsoft.Recognizers.Text;
@@ -76,8 +76,8 @@ public SkillDialog(
7676
AddDialog(authDialog);
7777
}
7878

79-
AddDialog(new WaterfallDialog(DialogIds.ConfirmFlow, intentSwitching));
80-
AddDialog(new ConfirmPrompt(DialogIds.CancelPrompt));
79+
AddDialog(new WaterfallDialog(DialogIds.ConfirmSkillSwitchFlow, intentSwitching));
80+
AddDialog(new ConfirmPrompt(DialogIds.ConfirmSkillSwitchPrompt));
8181
}
8282

8383
public async Task<DialogTurnResult> ConfirmIntentSwitch(WaterfallStepContext sc, CancellationToken cancellationToken)
@@ -86,7 +86,7 @@ public async Task<DialogTurnResult> ConfirmIntentSwitch(WaterfallStepContext sc,
8686
{
8787
var newIntentName = skillSwitchConfirmOption.TargetIntent;
8888
var intentResponse = string.Format(CommonStrings.ConfirmSkillSwitch, newIntentName);
89-
return await sc.PromptAsync(DialogIds.CancelPrompt, new PromptOptions()
89+
return await sc.PromptAsync(DialogIds.ConfirmSkillSwitchPrompt, new PromptOptions()
9090
{
9191
Prompt = new Activity(type: ActivityTypes.Message, text: intentResponse, speak: intentResponse),
9292
});
@@ -109,12 +109,8 @@ public async Task<DialogTurnResult> FinishIntentSwitch(WaterfallStepContext sc,
109109
sc.Context.Activity.Text = skillSwitchConfirmOption.UserInputActivity.Text;
110110
sc.Context.Activity.Speak = skillSwitchConfirmOption.UserInputActivity.Speak;
111111

112-
// 3) End dialog with target intent
113-
var intent = new DispatchIntent()
114-
{
115-
Intent = skillSwitchConfirmOption.TargetIntent,
116-
};
117-
return await sc.EndDialogAsync(intent);
112+
// 3) End dialog
113+
return await sc.EndDialogAsync(true);
118114
}
119115

120116
// Cancel skill switching
@@ -239,7 +235,7 @@ enabling the Skill to perform it's own action identification. */
239235
}
240236
}
241237

242-
if (innerDc.ActiveDialog != null)
238+
if (innerDc.ActiveDialog?.Id == DialogIds.ConfirmSkillSwitchPrompt)
243239
{
244240
var result = await base.OnContinueDialogAsync(innerDc, cancellationToken);
245241

@@ -250,8 +246,14 @@ enabling the Skill to perform it's own action identification. */
250246
else
251247
{
252248
// SkillDialog only truely end when confirm skill switch.
249+
if (result.Result is bool dispatchResult && dispatchResult)
250+
{
251+
// Restart and redispatch
252+
result.Result = new RouterDialogTurnResult(RouterDialogTurnStatus.Restart);
253+
}
254+
253255
// If confirm dialog is ended without skill switch, means previous activity has been resent and SkillDialog can continue to work
254-
if (!(result.Result is DispatchIntent))
256+
else
255257
{
256258
result.Status = DialogTurnStatus.Waiting;
257259
}
@@ -346,7 +348,7 @@ private async Task<DialogTurnResult> ForwardToSkillAsync(DialogContext innerDc,
346348
UserInputActivity = innerDc.Context.Activity,
347349
};
348350

349-
return await innerDc.BeginDialogAsync(DialogIds.ConfirmFlow, options);
351+
return await innerDc.BeginDialogAsync(DialogIds.ConfirmSkillSwitchFlow, options);
350352
}
351353

352354
await _skillTransport.CancelRemoteDialogsAsync(innerDc.Context);
@@ -414,8 +416,8 @@ private Action<Activity> GetFallbackCallback(DialogContext dialogContext)
414416

415417
private class DialogIds
416418
{
417-
public const string CancelPrompt = "cancelPrompt";
418-
public const string ConfirmFlow = "confirmFlow";
419+
public const string ConfirmSkillSwitchPrompt = "confirmSkillSwitchPrompt";
420+
public const string ConfirmSkillSwitchFlow = "confirmSkillSwitchFlow";
419421
}
420422
}
421423
}

lib/csharp/microsoft.bot.builder.solutions/microsoft.bot.builder.solutions/Dialogs/RouterDialog.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public RouterDialog(string dialogId, IBotTelemetryClient telemetryClient)
6666

6767
case DialogTurnStatus.Complete:
6868
{
69+
if (result.Result is RouterDialogTurnResult routerDialogTurnResult && routerDialogTurnResult.Status == RouterDialogTurnStatus.Restart)
70+
{
71+
await RouteAsync(innerDc).ConfigureAwait(false);
72+
break;
73+
}
74+
6975
await CompleteAsync(innerDc).ConfigureAwait(false);
7076

7177
// End active dialog
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Microsoft.Bot.Builder.Solutions.Dialogs
2+
{
3+
/// <summary>
4+
/// Define router dialog turn result.
5+
/// </summary>
6+
public class RouterDialogTurnResult
7+
{
8+
public RouterDialogTurnResult(RouterDialogTurnStatus status)
9+
{
10+
this.Status = status;
11+
}
12+
13+
public RouterDialogTurnStatus Status { get; set; }
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Microsoft.Bot.Builder.Solutions.Dialogs
2+
{
3+
/// <summary>
4+
/// Define router dialog turn status.
5+
/// </summary>
6+
public enum RouterDialogTurnStatus
7+
{
8+
Restart = 0,
9+
}
10+
}

0 commit comments

Comments
 (0)