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

Commit d43b0d7

Browse files
DingmaomaoBJTUlzc850612
authored andcommitted
[Future to Next] Fallback Lib change (#2012)
* [Part 1, lib change in future branch] Add fallback event support (#1875) * add fallback events in lib * update with new design * fix warning * fix warning * fix issue * fix indentation * remove dll * fix comments * fix warning * fix as comments * fix after discussion * fix comments * remove extra line * fix as comment * [Lib] Fallback lib change (#1976) * simplify lib change * fix as comments * fix as comments * fix as comments * fix merge error
1 parent 6dae291 commit d43b0d7

File tree

21 files changed

+344
-51
lines changed

21 files changed

+344
-51
lines changed

lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills.Tests/Mocks/MockSkillTransport.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@
66

77
namespace Microsoft.Bot.Builder.Skills.Tests.Mocks
88
{
9-
public class MockSkillTransport : ISkillTransport
10-
{
11-
private Activity _activityForwarded;
9+
public class MockSkillTransport : ISkillTransport
10+
{
11+
private Activity _activityForwarded;
1212

1313
public Task CancelRemoteDialogsAsync(SkillManifest skillManifest, IServiceClientCredentials serviceClientCredentials, ITurnContext turnContext)
1414
{
1515
return Task.CompletedTask;
1616
}
1717

18-
public void Disconnect()
19-
{
20-
}
18+
public void Disconnect()
19+
{
20+
}
2121

22-
public Task<bool> ForwardToSkillAsync(SkillManifest skillManifest, IServiceClientCredentials serviceClientCredentials, ITurnContext dialogContext, Activity activity, Action<Activity> tokenRequestHandler = null)
22+
public Task<bool> ForwardToSkillAsync(SkillManifest skillManifest, IServiceClientCredentials serviceClientCredentials, ITurnContext dialogContext, Activity activity, Action<Activity> tokenRequestHandler = null, Action<Activity> fallbackHandler = null)
2323
{
2424
_activityForwarded = activity;
2525

26-
return Task.FromResult(true);
27-
}
26+
return Task.FromResult(true);
27+
}
2828

29-
public bool CheckIfSkillInvoked()
30-
{
31-
return _activityForwarded != null;
32-
}
29+
public bool CheckIfSkillInvoked()
30+
{
31+
return _activityForwarded != null;
32+
}
3333

34-
public void VerifyActivityForwardedCorrectly(Action<Activity> assertion)
35-
{
36-
assertion(_activityForwarded);
37-
}
38-
}
34+
public void VerifyActivityForwardedCorrectly(Action<Activity> assertion)
35+
{
36+
assertion(_activityForwarded);
37+
}
38+
}
3939
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.Bot.Builder.Skills.Tests
77
internal class SkillDialogTest : SkillDialog
88
{
99
public SkillDialogTest(SkillManifest skillManifest, IServiceClientCredentials serviceClientCredentials, IBotTelemetryClient telemetryClient, UserState userState, ISkillTransport skillTransport = null)
10-
: base(skillManifest, serviceClientCredentials, telemetryClient, userState, null, skillTransport)
10+
: base(skillManifest, serviceClientCredentials, telemetryClient, userState, null, null, skillTransport)
1111
{
1212
}
1313
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Microsoft.Bot.Builder.Dialogs;
4+
using Microsoft.Bot.Builder.Skills.Models.Manifest;
5+
6+
namespace Microsoft.Bot.Builder.Skills
7+
{
8+
public interface ISkillIntentRecognizer
9+
{
10+
Func<DialogContext, Task<string>> RecognizeSkillIntentAsync { get; }
11+
12+
bool ConfirmIntentSwitch { get; }
13+
}
14+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.Bot.Builder.Skills
88
{
99
public interface ISkillTransport
1010
{
11-
Task<bool> ForwardToSkillAsync(SkillManifest skillManifest, IServiceClientCredentials serviceClientCredentials, ITurnContext dialogContext, Activity activity, Action<Activity> tokenRequestHandler = null);
11+
Task<bool> ForwardToSkillAsync(SkillManifest skillManifest, IServiceClientCredentials serviceClientCredentials, ITurnContext dialogContext, Activity activity, Action<Activity> tokenRequestHandler = null, Action<Activity> fallbackHandler = null);
1212

1313
Task CancelRemoteDialogsAsync(SkillManifest skillManifest, IServiceClientCredentials serviceClientCredentials, ITurnContext turnContext);
1414

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
public class SkillEvents
44
{
55
public const string CancelAllSkillDialogsEventName = "skill/cancelallskilldialogs";
6+
public const string FallbackEventName = "skill/fallbackrequest";
7+
public const string FallbackHandledEventName = "skill/fallbackhandled";
68
}
79
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Text;
44
using System.Threading;
55
using System.Threading.Tasks;
6+
using Microsoft.Bot.Builder.Skills.Models;
67
using Microsoft.Bot.Builder.Skills.Protocol;
78
using Microsoft.Bot.Builder.Solutions;
89
using Microsoft.Bot.Schema;
@@ -18,13 +19,20 @@ public class SkillCallingRequestHandler : RequestHandler
1819
private readonly ITurnContext _turnContext;
1920
private readonly IBotTelemetryClient _botTelemetryClient;
2021
private readonly Action<Activity> _tokenRequestHandler;
22+
private readonly Action<Activity> _fallbackRequestHandler;
2123
private readonly Action<Activity> _handoffActivityHandler;
2224

23-
public SkillCallingRequestHandler(ITurnContext turnContext, IBotTelemetryClient botTelemetryClient, Action<Activity> tokenRequestHandler = null, Action<Activity> handoffActivityHandler = null)
25+
public SkillCallingRequestHandler(
26+
ITurnContext turnContext,
27+
IBotTelemetryClient botTelemetryClient,
28+
Action<Activity> tokenRequestHandler = null,
29+
Action<Activity> fallbackRequestHandler = null,
30+
Action<Activity> handoffActivityHandler = null)
2431
{
2532
_turnContext = turnContext ?? throw new ArgumentNullException(nameof(turnContext));
2633
_botTelemetryClient = botTelemetryClient;
2734
_tokenRequestHandler = tokenRequestHandler;
35+
_fallbackRequestHandler = fallbackRequestHandler;
2836
_handoffActivityHandler = handoffActivityHandler;
2937

3038
var routes = new RouteTemplate[]
@@ -54,6 +62,19 @@ public SkillCallingRequestHandler(ITurnContext turnContext, IBotTelemetryClient
5462
throw new ArgumentNullException("TokenRequestHandler", "Skill is requesting for token but there's no handler on the calling side!");
5563
}
5664
}
65+
else if (activity.Type == ActivityTypes.Event && activity.Name == SkillEvents.FallbackEventName)
66+
{
67+
if (_fallbackRequestHandler != null)
68+
{
69+
_fallbackRequestHandler(activity);
70+
71+
return new ResourceResponse();
72+
}
73+
else
74+
{
75+
throw new ArgumentNullException("FallbackRequestHandler", "Skill is asking for fallback but there is no handler on the calling side!");
76+
}
77+
}
5778
else if (activity.Type == ActivityTypes.EndOfConversation)
5879
{
5980
if (_handoffActivityHandler != null)

0 commit comments

Comments
 (0)