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

Commit

Permalink
[Calendar] support search meeting by title/attendee/location (#2494)
Browse files Browse the repository at this point in the history
* support search meeting by title/attendee/location

* add test case

* remove question when only find one meeting

* update test cases

* fix code style
  • Loading branch information
KayMKM committed Oct 18, 2019
1 parent 1057d98 commit 5610685
Show file tree
Hide file tree
Showing 21 changed files with 441 additions and 84 deletions.
88 changes: 87 additions & 1 deletion skills/csharp/calendarskill/Dialogs/CalendarSkillDialogBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected async Task<DialogTurnResult> GetAuthToken(WaterfallStepContext sc, Can
if (item.IsCancelled != true)
{
state.ShowMeetingInfor.ShowingMeetings.Add(item);
state.ShowMeetingInfor.Condition = CalendarSkillState.ShowMeetingInformation.SearchMeetingCondition.Time;
}
}
}
Expand All @@ -186,6 +187,49 @@ protected async Task<DialogTurnResult> GetAuthToken(WaterfallStepContext sc, Can
if (item.IsCancelled != true)
{
state.ShowMeetingInfor.ShowingMeetings.Add(item);
state.ShowMeetingInfor.Condition = CalendarSkillState.ShowMeetingInformation.SearchMeetingCondition.Title;
}
}
}

// search by participants without cancelled meeting
if (!state.ShowMeetingInfor.ShowingMeetings.Any() && state.MeetingInfor.ContactInfor.ContactsNameList.Any())
{
var utcNow = DateTime.UtcNow;
var searchedMeeting = await calendarService.GetEventsByTimeAsync(utcNow, utcNow.AddDays(14));

foreach (var item in searchedMeeting)
{
var containsAllContacts = true;
foreach (var contactName in state.MeetingInfor.ContactInfor.ContactsNameList)
{
if (!item.ContainsAttendee(contactName))
{
containsAllContacts = false;
break;
}
}

if (containsAllContacts && item.IsCancelled != true)
{
state.ShowMeetingInfor.ShowingMeetings.Add(item);
state.ShowMeetingInfor.Condition = CalendarSkillState.ShowMeetingInformation.SearchMeetingCondition.Attendee;
}
}
}

// search by location without cancelled meeting
if (!state.ShowMeetingInfor.ShowingMeetings.Any() && !string.IsNullOrEmpty(state.MeetingInfor.Location))
{
var utcNow = DateTime.UtcNow;
var searchedMeeting = await calendarService.GetEventsByTimeAsync(utcNow, utcNow.AddDays(14));

foreach (var item in searchedMeeting)
{
if (item.Location.Contains(state.MeetingInfor.Location) && item.IsCancelled != true)
{
state.ShowMeetingInfor.ShowingMeetings.Add(item);
state.ShowMeetingInfor.Condition = CalendarSkillState.ShowMeetingInformation.SearchMeetingCondition.Location;
}
}
}
Expand Down Expand Up @@ -527,7 +571,7 @@ protected async Task<Activity> GetOverviewMeetingListResponseAsync(
OverlapEventCount = state.ShowMeetingInfor.TotalConflictCount.ToString(),
TotalEventCountUnit = string.Format(
state.ShowMeetingInfor.ShowingMeetings.Count == 1 ? CalendarCommonStrings.OverviewTotalMeetingOne : CalendarCommonStrings.OverviewTotalMeetingPlural,
state.MeetingInfor.StartDateString ?? CalendarCommonStrings.TodayLower),
GetSearchConditionString(state)),
OverlapEventCountUnit = CalendarCommonStrings.OverviewOverlapMeeting,
Provider = string.Format(CalendarCommonStrings.OverviewEventSource, currentEvents[0].SourceString()),
UserPhoto = await GetMyPhotoUrlAsync(context),
Expand Down Expand Up @@ -622,6 +666,33 @@ protected async Task<Activity> GetDetailMeetingResponseAsync(DialogContext dc, E
return ResponseManager.GetCardResponse(templateId, detailCard, tokens, "CalendarDetailContainer", participantContainerList);
}

protected string GetSearchConditionString(CalendarSkillState state)
{
switch (state.ShowMeetingInfor.Condition)
{
case CalendarSkillState.ShowMeetingInformation.SearchMeetingCondition.Time:
{
if (string.IsNullOrEmpty(state.MeetingInfor.StartDateString) ||
state.MeetingInfor.StartDateString.Equals(CalendarCommonStrings.TodayLower, StringComparison.InvariantCultureIgnoreCase) ||
state.MeetingInfor.StartDateString.Equals(CalendarCommonStrings.TomorrowLower, StringComparison.InvariantCultureIgnoreCase))
{
return (state.MeetingInfor.StartDateString ?? CalendarCommonStrings.TodayLower).ToLower();
}

return string.Format(CalendarCommonStrings.ShowEventDateCondition, state.MeetingInfor.StartDateString);
}

case CalendarSkillState.ShowMeetingInformation.SearchMeetingCondition.Title:
return string.Format(CalendarCommonStrings.ShowEventTitleCondition, state.MeetingInfor.Title);
case CalendarSkillState.ShowMeetingInformation.SearchMeetingCondition.Attendee:
return string.Format(CalendarCommonStrings.ShowEventContactCondition, string.Join(", ", state.MeetingInfor.ContactInfor.ContactsNameList));
case CalendarSkillState.ShowMeetingInformation.SearchMeetingCondition.Location:
return string.Format(CalendarCommonStrings.ShowEventLocationCondition, state.MeetingInfor.Location);
}

return null;
}

protected List<EventModel> GetFilteredEvents(CalendarSkillState state, string userInput, string locale, out string showingCardTitle)
{
var luisResult = state.LuisResult;
Expand Down Expand Up @@ -1106,6 +1177,21 @@ protected async Task DigestCalendarLuisResult(DialogContext dc, CalendarLuis lui
state.MeetingInfor.OrderReference = GetOrderReferenceFromEntity(entity);
}

if (entity.Subject != null)
{
state.MeetingInfor.Title = GetSubjectFromEntity(entity);
}

if (entity.personName != null)
{
state.MeetingInfor.ContactInfor.ContactsNameList = GetAttendeesFromEntity(entity, luisResult.Text, state.MeetingInfor.ContactInfor.ContactsNameList);
}

if (entity.Location != null)
{
state.MeetingInfor.Location = GetLocationFromEntity(entity);
}

if (entity.FromDate != null)
{
var dateString = GetDateTimeStringFromInstanceData(luisResult.Text, entity._instance.FromDate[0]);
Expand Down
56 changes: 28 additions & 28 deletions skills/csharp/calendarskill/Dialogs/FindContactDialog.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
 using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using CalendarSkill.Models;
using CalendarSkill.Models.DialogOptions;
using CalendarSkill.Responses.CreateEvent;
using CalendarSkill.Responses.FindContact;
using CalendarSkill.Responses.Shared;
using CalendarSkill.Services;
using CalendarSkill.Utilities;
using Luis;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Choices;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Extensions;
using Microsoft.Bot.Builder.Solutions.Resources;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Util;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Graph;
using static CalendarSkill.Models.CalendarSkillState;

namespace CalendarSkill.Dialogs
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using CalendarSkill.Models;
using CalendarSkill.Models.DialogOptions;
using CalendarSkill.Responses.CreateEvent;
using CalendarSkill.Responses.FindContact;
using CalendarSkill.Responses.Shared;
using CalendarSkill.Services;
using CalendarSkill.Utilities;
using Luis;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Choices;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Extensions;
using Microsoft.Bot.Builder.Solutions.Resources;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Util;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Graph;
using static CalendarSkill.Models.CalendarSkillState;

namespace CalendarSkill.Dialogs
{
public class FindContactDialog : CalendarSkillDialogBase
{
Expand Down
Loading

0 comments on commit 5610685

Please sign in to comment.