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

Commit e10f3a1

Browse files
committed
updated calendar skill to latest from next
1 parent 8d9a4ef commit e10f3a1

File tree

10 files changed

+70
-134
lines changed

10 files changed

+70
-134
lines changed

skills/src/csharp/calendarskill/calendarskill/CalendarSkill.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.5.1" />
108108
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.5.1" />
109109
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.5.1" />
110-
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.6.0-daily6" />
111-
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.6.0-daily6" />
110+
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.6.0-rc4" />
111+
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.6.0-rc4" />
112112
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.5.1" />
113113
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.5.1" />
114114
<PackageReference Include="Microsoft.Bot.Connector" Version="4.5.1" />

skills/src/csharp/calendarskill/calendarskill/Controllers/BotController.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
using Microsoft.Bot.Builder;
33
using Microsoft.Bot.Builder.Integration.AspNet.Core;
44
using Microsoft.Bot.Builder.Skills;
5+
using Microsoft.Bot.Builder.Skills.Auth;
56
using Microsoft.Bot.Builder.Solutions;
67

78
namespace CalendarSkill.Controllers
89
{
910
[ApiController]
1011
public class BotController : SkillController
1112
{
12-
public BotController(
13-
IBot bot,
14-
BotSettingsBase botSettings,
15-
IBotFrameworkHttpAdapter botFrameworkHttpAdapter,
16-
SkillWebSocketAdapter skillWebSocketAdapter)
17-
: base(bot, botSettings, botFrameworkHttpAdapter, skillWebSocketAdapter)
18-
{
19-
}
20-
}
13+
public BotController(
14+
IBot bot,
15+
BotSettingsBase botSettings,
16+
IBotFrameworkHttpAdapter botFrameworkHttpAdapter,
17+
SkillWebSocketAdapter skillWebSocketAdapter,
18+
IWhitelistAuthenticationProvider whitelistAuthenticationProvider)
19+
: base(bot, botSettings, botFrameworkHttpAdapter, skillWebSocketAdapter, whitelistAuthenticationProvider)
20+
{
21+
}
22+
}
2123
}

skills/src/csharp/calendarskill/calendarskill/Dialogs/CalendarSkillDialogBase.cs

Lines changed: 32 additions & 40 deletions
Large diffs are not rendered by default.

skills/src/csharp/calendarskill/calendarskill/Prompts/DatePrompt.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using CalendarSkill.Prompts.Options;
65
using CalendarSkill.Responses.Shared;
76
using CalendarSkill.Utilities;
87
using Microsoft.Bot.Builder;
@@ -15,8 +14,6 @@ namespace CalendarSkill.Prompts
1514
{
1615
public class DatePrompt : Prompt<IList<DateTimeResolution>>
1716
{
18-
private static TimeZoneInfo userTimeZone = null;
19-
2017
public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> validator = null, string defaultLocale = null)
2118
: base(dialogId, validator)
2219
{
@@ -39,11 +36,6 @@ public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
3936
throw new ArgumentNullException(nameof(options));
4037
}
4138

42-
if (!(options is DatePromptOptions))
43-
{
44-
throw new Exception(nameof(options) + " should be GetEventOptions");
45-
}
46-
4739
if (isRetry && options.RetryPrompt != null)
4840
{
4941
await turnContext.SendActivityAsync(options.RetryPrompt, cancellationToken).ConfigureAwait(false);
@@ -52,8 +44,6 @@ public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
5244
{
5345
await turnContext.SendActivityAsync(options.Prompt, cancellationToken).ConfigureAwait(false);
5446
}
55-
56-
userTimeZone = ((DatePromptOptions)options).TimeZone;
5747
}
5848

5949
protected override async Task<PromptRecognizerResult<IList<DateTimeResolution>>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
@@ -97,8 +87,7 @@ private IList<DateTimeResolution> GetDateFromMessage(string message, string cult
9787

9888
private List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture)
9989
{
100-
var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone);
101-
var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, true), culture, DateTimeOptions.CalendarMode, userNow);
90+
var results = DateTimeRecognizer.RecognizeDateTime(DateTimeHelper.ConvertNumberToDateTimeString(dateTimeString, true), culture, options: DateTimeOptions.CalendarMode);
10291
if (results.Count > 0)
10392
{
10493
// Return list of resolutions from first match
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.Bot.Builder.Dialogs;
2+
using Microsoft.Bot.Schema;
3+
4+
namespace CalendarSkill.Options
5+
{
6+
public class NoSkipPromptOptions : PromptOptions
7+
{
8+
public NoSkipPromptOptions()
9+
: base()
10+
{
11+
}
12+
13+
public Activity NoSkipPrompt { get; set; }
14+
}
15+
}

skills/src/csharp/calendarskill/calendarskill/Prompts/TimePrompt.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.Collections.Generic;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using CalendarSkill.Options;
6-
using CalendarSkill.Utilities;
75
using Microsoft.Bot.Builder;
86
using Microsoft.Bot.Builder.Dialogs;
97
using Microsoft.Bot.Schema;
@@ -14,8 +12,6 @@ namespace CalendarSkill.Prompts
1412
{
1513
public class TimePrompt : Prompt<IList<DateTimeResolution>>
1614
{
17-
private static TimeZoneInfo userTimeZone = null;
18-
1915
public TimePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> validator = null, string defaultLocale = null)
2016
: base(dialogId, validator)
2117
{
@@ -36,11 +32,6 @@ public TimePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
3632
throw new ArgumentNullException(nameof(options));
3733
}
3834

39-
if (!(options is TimePromptOptions))
40-
{
41-
throw new Exception(nameof(options) + " should be GetEventOptions");
42-
}
43-
4435
if (isRetry && options.RetryPrompt != null)
4536
{
4637
await turnContext.SendActivityAsync(options.RetryPrompt, cancellationToken).ConfigureAwait(false);
@@ -49,8 +40,6 @@ public TimePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
4940
{
5041
await turnContext.SendActivityAsync(options.Prompt, cancellationToken).ConfigureAwait(false);
5142
}
52-
53-
userTimeZone = ((TimePromptOptions)options).TimeZone;
5443
}
5544

5645
protected override async Task<PromptRecognizerResult<IList<DateTimeResolution>>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
@@ -85,8 +74,7 @@ private IList<DateTimeResolution> GetTimeFromMessage(string message, string cult
8574

8675
private List<DateTimeResolution> RecognizeDateTime(string dateTimeString, string culture)
8776
{
88-
var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone);
89-
var results = DateTimeRecognizer.RecognizeDateTime(dateTimeString, culture, DateTimeOptions.CalendarMode, userNow);
77+
var results = DateTimeRecognizer.RecognizeDateTime(dateTimeString, culture);
9078
if (results.Count > 0)
9179
{
9280
// Return list of resolutions from first match

skills/src/csharp/calendarskill/calendarskill/Startup.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Microsoft.Bot.Builder.Integration.ApplicationInsights.Core;
2626
using Microsoft.Bot.Builder.Integration.AspNet.Core;
2727
using Microsoft.Bot.Builder.Skills;
28+
using Microsoft.Bot.Builder.Skills.Auth;
2829
using Microsoft.Bot.Builder.Solutions;
2930
using Microsoft.Bot.Builder.Solutions.Proactive;
3031
using Microsoft.Bot.Builder.Solutions.Responses;
@@ -130,6 +131,8 @@ public void ConfigureServices(IServiceCollection services)
130131
services.AddTransient<SkillWebSocketBotAdapter, CalendarSkillWebSocketBotAdapter>();
131132
services.AddTransient<SkillWebSocketAdapter>();
132133

134+
services.AddSingleton<IWhitelistAuthenticationProvider, WhitelistAuthenticationProvider>();
135+
133136
// Configure bot
134137
services.AddTransient<IBot, DialogBot<MainDialog>>();
135138
}

skills/src/csharp/calendarskill/calendarskilltest/Flow/Fakes/MockServiceManager.cs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,8 @@ public static IServiceManager GetCalendarService()
7777
public static IServiceManager SetMeetingsToSpecial(List<EventModel> eventList)
7878
{
7979
mockCalendarService.Setup(service => service.GetUpcomingEventsAsync(null)).Returns(Task.FromResult(eventList));
80-
mockCalendarService.Setup(service => service.GetEventsByTimeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>())).Returns((DateTime startTime, DateTime endTime) =>
81-
{
82-
var result = new List<EventModel>();
83-
foreach (var item in eventList)
84-
{
85-
if (item.StartTime >= startTime && item.StartTime <= endTime)
86-
{
87-
result.Add(item);
88-
}
89-
}
90-
91-
return Task.FromResult(result);
92-
});
93-
mockCalendarService.Setup(service => service.GetEventsByStartTimeAsync(It.IsAny<DateTime>())).Returns((DateTime startTime) =>
94-
{
95-
var result = new List<EventModel>();
96-
foreach (var item in eventList)
97-
{
98-
if (item.StartTime == startTime)
99-
{
100-
result.Add(item);
101-
}
102-
}
103-
104-
return Task.FromResult(result);
105-
});
80+
mockCalendarService.Setup(service => service.GetEventsByTimeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>())).Returns(Task.FromResult(eventList));
81+
mockCalendarService.Setup(service => service.GetEventsByStartTimeAsync(It.IsAny<DateTime>())).Returns(Task.FromResult(eventList));
10682
mockCalendarService.Setup(service => service.GetEventsByTitleAsync(It.IsAny<string>())).Returns(Task.FromResult(eventList));
10783
return mockServiceManager.Object;
10884
}

skills/src/csharp/calendarskill/calendarskilltest/Flow/SummaryCalendarFlowTests.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -173,29 +173,6 @@ await this.GetTestFlow()
173173
.StartTestAsync();
174174
}
175175

176-
[TestMethod]
177-
public async Task Test_CalendarSummaryByTimeframe()
178-
{
179-
DateTime now = DateTime.Now;
180-
DateTime startTime = new DateTime(now.Year, now.Month, now.Day, 14, 0, 0);
181-
startTime = TimeZoneInfo.ConvertTimeToUtc(startTime);
182-
this.ServiceManager = MockServiceManager.SetMeetingsToSpecial(new List<EventModel>()
183-
{
184-
MockServiceManager.CreateEventModel(
185-
startDateTime: startTime,
186-
endDateTime: startTime.AddHours(1))
187-
});
188-
189-
await this.GetTestFlow()
190-
.Send(FindMeetingTestUtterances.FindMeetingByTimeframe)
191-
.AssertReply(this.ShowAuth())
192-
.Send(this.GetAuthResponse())
193-
.AssertReplyOneOf(this.FoundOneEventPrompt(startTimeString: "at 2:00 PM"))
194-
.Send(Strings.Strings.ConfirmNo)
195-
.AssertReply(this.ActionEndMessage())
196-
.StartTestAsync();
197-
}
198-
199176
[TestMethod]
200177
public async Task Test_CalendarSummaryByStartTime()
201178
{
@@ -256,15 +233,15 @@ private string[] AskForShowOverviewAgainPrompt(string dateTime = "today")
256233
return this.ParseReplies(SummaryResponses.AskForShowOverview, responseParams);
257234
}
258235

259-
private string[] FoundOneEventPrompt(string dateString = "today", string startTimeString = "at 6:00 PM")
236+
private string[] FoundOneEventPrompt(string dateTime = "today")
260237
{
261238
var responseParams = new StringDictionary()
262239
{
263240
{ "Count", "1" },
264241
{ "EventName1", Strings.Strings.DefaultEventName },
265242
{ "EventDuration", "1 hour" },
266-
{ "DateTime", dateString },
267-
{ "EventTime1", startTimeString },
243+
{ "DateTime", dateTime },
244+
{ "EventTime1", "at 6:00 PM" },
268245
{ "Participants1", Strings.Strings.DefaultUserName }
269246
};
270247

skills/src/csharp/calendarskill/calendarskilltest/Flow/Utterances/FindMeetingTestUtterances.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ public FindMeetingTestUtterances()
1313
this.Add(FindMeetingByTimeRange, GetBaseFindMeetingIntent(
1414
FindMeetingByTimeRange,
1515
fromDate: new string[] { "next week" }));
16-
this.Add(FindMeetingByTimeframe, GetBaseFindMeetingIntent(
17-
FindMeetingByTimeframe,
18-
fromTime: new string[] { "this afternoon" },
19-
toTime: new string[] { "this afternoon" }));
2016
this.Add(FindMeetingByStartTime, GetBaseFindMeetingIntent(
2117
FindMeetingByStartTime,
2218
fromDate: new string[] { "tomorrow" },
@@ -37,8 +33,6 @@ public FindMeetingTestUtterances()
3733

3834
public static string FindMeetingByTimeRange { get; } = "What's on my schedule next week";
3935

40-
public static string FindMeetingByTimeframe { get; } = "What's on my schedule this afternoon";
41-
4236
public static string FindMeetingByStartTime { get; } = "What are my meetings at tomorrow 6 pm";
4337

4438
public static string BaseNextMeeting { get; } = "what is my next meeting";

0 commit comments

Comments
 (0)