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

Commit f6ea160

Browse files
authored
add update and delete from summary flow (#479)
1 parent e2fa9a7 commit f6ea160

File tree

4 files changed

+134
-107
lines changed

4 files changed

+134
-107
lines changed

solutions/Virtual-Assistant/src/csharp/skills/calendarskill/Dialogs/DeleteEvent/DeleteEventDialog.cs

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public DeleteEventDialog(
154154
{
155155
var state = await Accessor.GetAsync(sc.Context);
156156

157-
if (state.StartDate.Any() || state.StartTime.Any() || state.Title != null)
157+
if (state.Events.Count > 0 || state.StartDate.Any() || state.StartTime.Any() || state.Title != null)
158158
{
159159
return await sc.NextAsync();
160160
}
@@ -191,66 +191,69 @@ public DeleteEventDialog(
191191
var calendarService = ServiceManager.InitCalendarService(state.APIToken, state.EventSource);
192192
var searchByEntities = state.StartDate.Any() || state.StartTime.Any() || state.Title != null;
193193

194-
if (state.StartDate.Any() || state.StartTime.Any())
194+
if (state.Events.Count < 1)
195195
{
196-
events = await GetEventsByTime(state.StartDate, state.StartTime, state.EndDate, state.EndTime, state.GetUserTimeZone(), calendarService);
197-
state.StartDate = new List<DateTime>();
198-
state.StartTime = new List<DateTime>();
199-
}
200-
else if (state.Title != null)
201-
{
202-
events = await calendarService.GetEventsByTitle(state.Title);
203-
state.Title = null;
204-
}
205-
else
206-
{
207-
sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
208-
var userInput = content != null ? content.ToString() : sc.Context.Activity.Text;
209-
try
196+
if (state.StartDate.Any() || state.StartTime.Any())
197+
{
198+
events = await GetEventsByTime(state.StartDate, state.StartTime, state.EndDate, state.EndTime, state.GetUserTimeZone(), calendarService);
199+
state.StartDate = new List<DateTime>();
200+
state.StartTime = new List<DateTime>();
201+
}
202+
else if (state.Title != null)
203+
{
204+
events = await calendarService.GetEventsByTitle(state.Title);
205+
state.Title = null;
206+
}
207+
else
210208
{
211-
IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
212-
if (dateTimeResolutions.Count > 0)
209+
sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
210+
var userInput = content != null ? content.ToString() : sc.Context.Activity.Text;
211+
try
213212
{
214-
foreach (var resolution in dateTimeResolutions)
213+
IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
214+
if (dateTimeResolutions.Count > 0)
215215
{
216-
if (resolution.Value == null)
216+
foreach (var resolution in dateTimeResolutions)
217217
{
218-
continue;
219-
}
218+
if (resolution.Value == null)
219+
{
220+
continue;
221+
}
220222

221-
var startTimeValue = DateTime.Parse(resolution.Value);
222-
if (startTimeValue == null)
223-
{
224-
continue;
225-
}
223+
var startTimeValue = DateTime.Parse(resolution.Value);
224+
if (startTimeValue == null)
225+
{
226+
continue;
227+
}
226228

227-
var dateTimeConvertType = resolution.Timex;
228-
bool isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, dateTimeResolutions.First().Value, dateTimeResolutions.First().Timex);
229-
startTimeValue = isRelativeTime ? TimeZoneInfo.ConvertTime(startTimeValue, TimeZoneInfo.Local, state.GetUserTimeZone()) : startTimeValue;
229+
var dateTimeConvertType = resolution.Timex;
230+
bool isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, dateTimeResolutions.First().Value, dateTimeResolutions.First().Timex);
231+
startTimeValue = isRelativeTime ? TimeZoneInfo.ConvertTime(startTimeValue, TimeZoneInfo.Local, state.GetUserTimeZone()) : startTimeValue;
230232

231-
startTimeValue = TimeConverter.ConvertLuisLocalToUtc(startTimeValue, state.GetUserTimeZone());
232-
events = await calendarService.GetEventsByStartTime(startTimeValue);
233-
if (events != null && events.Count > 0)
234-
{
235-
break;
233+
startTimeValue = TimeConverter.ConvertLuisLocalToUtc(startTimeValue, state.GetUserTimeZone());
234+
events = await calendarService.GetEventsByStartTime(startTimeValue);
235+
if (events != null && events.Count > 0)
236+
{
237+
break;
238+
}
236239
}
237240
}
238241
}
239-
}
240-
catch
241-
{
242-
}
242+
catch
243+
{
244+
}
243245

244-
if (events == null || events.Count <= 0)
245-
{
246-
state.Title = userInput;
247-
events = await calendarService.GetEventsByTitle(userInput);
246+
if (events == null || events.Count <= 0)
247+
{
248+
state.Title = userInput;
249+
events = await calendarService.GetEventsByTitle(userInput);
250+
}
248251
}
249-
}
250252

251-
state.Events = events;
253+
state.Events = events;
254+
}
252255

253-
if (events.Count <= 0)
256+
if (state.Events.Count <= 0)
254257
{
255258
if (searchByEntities)
256259
{
@@ -263,16 +266,16 @@ public DeleteEventDialog(
263266
return await sc.BeginDialogAsync(Actions.UpdateStartTime, new UpdateDateTimeDialogOptions(UpdateDateTimeDialogOptions.UpdateReason.NoEvent));
264267
}
265268
}
266-
else if (events.Count > 1)
269+
else if (state.Events.Count > 1)
267270
{
268271
var options = new PromptOptions()
269272
{
270273
Choices = new List<Choice>(),
271274
};
272275

273-
for (var i = 0; i < events.Count; i++)
276+
for (var i = 0; i < state.Events.Count; i++)
274277
{
275-
var item = events[i];
278+
var item = state.Events[i];
276279
var choice = new Choice()
277280
{
278281
Value = string.Empty,
@@ -286,7 +289,7 @@ public DeleteEventDialog(
286289
replyToConversation.Attachments = new List<Microsoft.Bot.Schema.Attachment>();
287290

288291
var cardsData = new List<CalendarCardData>();
289-
foreach (var item in events)
292+
foreach (var item in state.Events)
290293
{
291294
var meetingCard = item.ToAdaptiveCardData(state.GetUserTimeZone());
292295
var replyTemp = sc.Context.Activity.CreateAdaptiveCardReply(CalendarMainResponses.GreetingMessage, item.OnlineMeetingUrl == null ? "Dialogs/Shared/Resources/Cards/CalendarCardNoJoinButton.json" : "Dialogs/Shared/Resources/Cards/CalendarCard.json", meetingCard);

solutions/Virtual-Assistant/src/csharp/skills/calendarskill/Dialogs/Shared/CalendarSkillDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected async Task<DialogTurnResult> GetAuthToken(WaterfallStepContext sc, Can
129129
// When the token is cached we get a TokenResponse object.
130130
var skillOptions = (CalendarSkillDialogOptions)sc.Options;
131131
ProviderTokenResponse providerTokenResponse;
132-
if (skillOptions.SkillMode)
132+
if (skillOptions != null && skillOptions.SkillMode)
133133
{
134134
var resultType = sc.Context.Activity.Value.GetType();
135135
if (resultType == typeof(ProviderTokenResponse))

solutions/Virtual-Assistant/src/csharp/skills/calendarskill/Dialogs/Summary/SummaryDialog.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public SummaryDialog(
5151
// Define the conversation flow using a waterfall model.
5252
AddDialog(new WaterfallDialog(Actions.ShowEventsSummary, showSummary) { TelemetryClient = telemetryClient });
5353
AddDialog(new WaterfallDialog(Actions.Read, readEvent) { TelemetryClient = telemetryClient });
54+
AddDialog(new UpdateEventDialog(services, accessor, serviceManager, telemetryClient));
55+
AddDialog(new DeleteEventDialog(services, accessor, serviceManager, telemetryClient));
5456

5557
// Set starting dialog for component
5658
InitialDialogId = Actions.ShowEventsSummary;
@@ -264,7 +266,7 @@ public SummaryDialog(
264266
}
265267
}
266268

267-
if (eventItem != null)
269+
if (eventItem != null && topIntent != Luis.Calendar.Intent.ChangeCalendarEntry && topIntent != Luis.Calendar.Intent.DeleteCalendarEntry)
268270
{
269271
var speakString = SpeakHelper.ToSpeechMeetingDetail(eventItem.Title, TimeConverter.ConvertUtcToUserTime(eventItem.StartTime, state.GetUserTimeZone()), eventItem.IsAllDay == true);
270272

@@ -303,7 +305,25 @@ public SummaryDialog(
303305
return await sc.EndDialogAsync(true);
304306
}
305307

306-
if (topIntent == Luis.Calendar.Intent.ReadAloud)
308+
if (topIntent == Luis.Calendar.Intent.ChangeCalendarEntry)
309+
{
310+
if (state.ReadOutEvents.Count > 0)
311+
{
312+
state.Events.Add(state.ReadOutEvents[0]);
313+
}
314+
315+
return await sc.BeginDialogAsync(nameof(UpdateEventDialog));
316+
}
317+
else if (topIntent == Luis.Calendar.Intent.DeleteCalendarEntry)
318+
{
319+
if (state.ReadOutEvents.Count > 0)
320+
{
321+
state.Events.Add(state.ReadOutEvents[0]);
322+
}
323+
324+
return await sc.BeginDialogAsync(nameof(DeleteEventDialog));
325+
}
326+
else if (topIntent == Luis.Calendar.Intent.ReadAloud)
307327
{
308328
return await sc.BeginDialogAsync(Actions.Read);
309329
}

solutions/Virtual-Assistant/src/csharp/skills/calendarskill/Dialogs/UpdateEvent/UpdateEventDialog.cs

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public UpdateEventDialog(
369369
{
370370
var state = await Accessor.GetAsync(sc.Context);
371371

372-
if (state.OriginalStartDate.Any() || state.OriginalStartTime.Any() || state.Title != null)
372+
if (state.Events.Count > 0 || state.OriginalStartDate.Any() || state.OriginalStartTime.Any() || state.Title != null)
373373
{
374374
return await sc.NextAsync();
375375
}
@@ -406,67 +406,71 @@ public UpdateEventDialog(
406406
var calendarService = ServiceManager.InitCalendarService(state.APIToken, state.EventSource);
407407
var searchByEntities = state.OriginalStartDate.Any() || state.OriginalStartTime.Any() || state.Title != null;
408408

409-
if (state.OriginalStartDate.Any() || state.OriginalStartTime.Any())
409+
if (state.Events.Count < 1)
410410
{
411-
events = await GetEventsByTime(state.OriginalStartDate, state.OriginalStartTime, state.OriginalEndDate, state.OriginalEndTime, state.GetUserTimeZone(), calendarService);
412-
state.OriginalStartDate = new List<DateTime>();
413-
state.OriginalStartTime = new List<DateTime>();
414-
state.OriginalEndDate = new List<DateTime>();
415-
state.OriginalStartTime = new List<DateTime>();
416-
}
417-
else if (state.Title != null)
418-
{
419-
events = await calendarService.GetEventsByTitle(state.Title);
420-
state.Title = null;
421-
}
422-
else
423-
{
424-
sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
425-
var userInput = content != null ? content.ToString() : sc.Context.Activity.Text;
426-
try
411+
if (state.OriginalStartDate.Any() || state.OriginalStartTime.Any())
412+
{
413+
events = await GetEventsByTime(state.OriginalStartDate, state.OriginalStartTime, state.OriginalEndDate, state.OriginalEndTime, state.GetUserTimeZone(), calendarService);
414+
state.OriginalStartDate = new List<DateTime>();
415+
state.OriginalStartTime = new List<DateTime>();
416+
state.OriginalEndDate = new List<DateTime>();
417+
state.OriginalStartTime = new List<DateTime>();
418+
}
419+
else if (state.Title != null)
427420
{
428-
IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
429-
if (dateTimeResolutions.Count > 0)
421+
events = await calendarService.GetEventsByTitle(state.Title);
422+
state.Title = null;
423+
}
424+
else
425+
{
426+
sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
427+
var userInput = content != null ? content.ToString() : sc.Context.Activity.Text;
428+
try
430429
{
431-
foreach (var resolution in dateTimeResolutions)
430+
IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
431+
if (dateTimeResolutions.Count > 0)
432432
{
433-
if (resolution.Value == null)
433+
foreach (var resolution in dateTimeResolutions)
434434
{
435-
continue;
436-
}
437-
438-
var startTimeValue = DateTime.Parse(resolution.Value);
439-
if (startTimeValue == null)
440-
{
441-
continue;
442-
}
443-
444-
var dateTimeConvertType = resolution.Timex;
445-
bool isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, dateTimeResolutions.First().Value, dateTimeResolutions.First().Timex);
446-
startTimeValue = isRelativeTime ? TimeZoneInfo.ConvertTime(startTimeValue, TimeZoneInfo.Local, state.GetUserTimeZone()) : startTimeValue;
447-
448-
startTimeValue = TimeConverter.ConvertLuisLocalToUtc(startTimeValue, state.GetUserTimeZone());
449-
events = await calendarService.GetEventsByStartTime(startTimeValue);
450-
if (events != null && events.Count > 0)
451-
{
452-
break;
435+
if (resolution.Value == null)
436+
{
437+
continue;
438+
}
439+
440+
var startTimeValue = DateTime.Parse(resolution.Value);
441+
if (startTimeValue == null)
442+
{
443+
continue;
444+
}
445+
446+
var dateTimeConvertType = resolution.Timex;
447+
bool isRelativeTime = IsRelativeTime(sc.Context.Activity.Text, dateTimeResolutions.First().Value, dateTimeResolutions.First().Timex);
448+
startTimeValue = isRelativeTime ? TimeZoneInfo.ConvertTime(startTimeValue, TimeZoneInfo.Local, state.GetUserTimeZone()) : startTimeValue;
449+
450+
startTimeValue = TimeConverter.ConvertLuisLocalToUtc(startTimeValue, state.GetUserTimeZone());
451+
events = await calendarService.GetEventsByStartTime(startTimeValue);
452+
if (events != null && events.Count > 0)
453+
{
454+
break;
455+
}
453456
}
454457
}
455458
}
456-
}
457-
catch
458-
{
459-
}
459+
catch
460+
{
461+
}
460462

461-
if (events == null || events.Count <= 0)
462-
{
463-
state.Title = userInput;
464-
events = await calendarService.GetEventsByTitle(userInput);
463+
if (events == null || events.Count <= 0)
464+
{
465+
state.Title = userInput;
466+
events = await calendarService.GetEventsByTitle(userInput);
467+
}
465468
}
469+
470+
state.Events = events;
466471
}
467472

468-
state.Events = events;
469-
if (events.Count <= 0)
473+
if (state.Events.Count <= 0)
470474
{
471475
if (searchByEntities)
472476
{
@@ -479,16 +483,16 @@ public UpdateEventDialog(
479483
return await sc.BeginDialogAsync(Actions.UpdateStartTime, new UpdateDateTimeDialogOptions(UpdateDateTimeDialogOptions.UpdateReason.NoEvent));
480484
}
481485
}
482-
else if (events.Count > 1)
486+
else if (state.Events.Count > 1)
483487
{
484488
var options = new PromptOptions()
485489
{
486490
Choices = new List<Choice>(),
487491
};
488492

489-
for (var i = 0; i < events.Count; i++)
493+
for (var i = 0; i < state.Events.Count; i++)
490494
{
491-
var item = events[i];
495+
var item = state.Events[i];
492496
var choice = new Choice()
493497
{
494498
Value = string.Empty,
@@ -502,7 +506,7 @@ public UpdateEventDialog(
502506
replyToConversation.Attachments = new List<Microsoft.Bot.Schema.Attachment>();
503507

504508
var cardsData = new List<CalendarCardData>();
505-
foreach (var item in events)
509+
foreach (var item in state.Events)
506510
{
507511
var meetingCard = item.ToAdaptiveCardData(state.GetUserTimeZone());
508512
var replyTemp = sc.Context.Activity.CreateAdaptiveCardReply(CalendarMainResponses.GreetingMessage, item.OnlineMeetingUrl == null ? "Dialogs/Shared/Resources/Cards/CalendarCardNoJoinButton.json" : "Dialogs/Shared/Resources/Cards/CalendarCard.json", meetingCard);

0 commit comments

Comments
 (0)