private async Task <IList <EventModel> > GetEventsWithStartTime(IList <DateTimeResolution> dateTimeResolutions, string message) { IList <EventModel> events = new List <EventModel>(); if (dateTimeResolutions.Count > 0) { foreach (var resolution in dateTimeResolutions) { if (resolution.Value == null && resolution.Start == null && resolution.End == null) { continue; } var startDateList = new List <DateTime>(); var startTimeList = new List <DateTime>(); var endDateList = new List <DateTime>(); var endTimeList = new List <DateTime>(); if (resolution.Value == null) { var startTimeValue = DateTime.Parse(resolution.Start); var endTimeValue = DateTime.Parse(resolution.End); if (startTimeValue == null || endTimeValue == null) { continue; } startDateList.Add(startTimeValue); startTimeList.Add(startTimeValue); endDateList.Add(endTimeValue); endTimeList.Add(endTimeValue); } else { var startTimeValue = DateTime.Parse(resolution.Value); if (startTimeValue == null) { continue; } var dateTimeConvertType = resolution.Timex; if (CalendarCommonUtil.ContainsTime(dateTimeConvertType)) { startTimeList.Add(startTimeValue); } startDateList.Add(startTimeValue); } events = await CalendarCommonUtil.GetEventsByTimeAsync(startDateList, startTimeList, endDateList, endTimeList, userTimeZone, calendarService); if (events != null && events.Count > 0) { break; } } } return(events); }
// Runs on every turn of the conversation to check if the conversation should be interrupted. protected async Task <bool> InterruptDialogAsync(DialogContext innerDc, CancellationToken cancellationToken) { var interrupted = false; var activity = innerDc.Context.Activity; if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text)) { // Get connected LUIS result from turn state. var state = await _stateAccessor.GetAsync(innerDc.Context, () => new CalendarSkillState()); var generalResult = innerDc.Context.TurnState.Get <General>(StateProperties.GeneralLuisResultKey); (var generalIntent, var generalScore) = generalResult.TopIntent(); if (generalScore > 0.5) { switch (generalIntent) { case General.Intent.Cancel: { await innerDc.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale(CalendarMainResponses.CancelMessage)); await innerDc.CancelAllDialogsAsync(); await innerDc.BeginDialogAsync(InitialDialogId); interrupted = true; break; } case General.Intent.Help: { await innerDc.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale(CalendarMainResponses.HelpMessage)); await innerDc.RepromptDialogAsync(); interrupted = true; break; } case General.Intent.Logout: { // Log user out of all accounts. await LogUserOut(innerDc); await innerDc.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale(CalendarMainResponses.LogOut)); await innerDc.CancelAllDialogsAsync(); await innerDc.BeginDialogAsync(InitialDialogId); interrupted = true; break; } } if (!interrupted && innerDc.ActiveDialog != null) { var calendarLuisResult = innerDc.Context.TurnState.Get <CalendarLuis>(StateProperties.CalendarLuisResultKey); var topCalendarIntent = calendarLuisResult.TopIntent(); if (topCalendarIntent.score > 0.9 && !CalendarCommonUtil.IsFindEventsDialog(state.InitialIntent)) { var intentSwitchingResult = CalendarCommonUtil.CheckIntentSwitching(topCalendarIntent.intent); var newFlowOptions = new CalendarSkillDialogOptions() { SubFlowMode = false }; if (intentSwitchingResult != CalendarLuis.Intent.None) { state.Clear(); await innerDc.CancelAllDialogsAsync(); state.InitialIntent = intentSwitchingResult; switch (intentSwitchingResult) { case CalendarLuis.Intent.DeleteCalendarEntry: await innerDc.BeginDialogAsync(nameof(ChangeEventStatusDialog), new ChangeEventStatusDialogOptions(newFlowOptions, EventStatus.Cancelled)); interrupted = true; break; case CalendarLuis.Intent.AcceptEventEntry: await innerDc.BeginDialogAsync(nameof(ChangeEventStatusDialog), new ChangeEventStatusDialogOptions(newFlowOptions, EventStatus.Accepted)); interrupted = true; break; case CalendarLuis.Intent.ChangeCalendarEntry: await innerDc.BeginDialogAsync(nameof(UpdateEventDialog), newFlowOptions); interrupted = true; break; case CalendarLuis.Intent.CheckAvailability: await innerDc.BeginDialogAsync(nameof(CheckPersonAvailableDialog), newFlowOptions); interrupted = true; break; case CalendarLuis.Intent.ConnectToMeeting: await innerDc.BeginDialogAsync(nameof(JoinEventDialog), newFlowOptions); interrupted = true; break; case CalendarLuis.Intent.CreateCalendarEntry: await innerDc.BeginDialogAsync(nameof(CreateEventDialog), newFlowOptions); interrupted = true; break; case CalendarLuis.Intent.FindCalendarDetail: case CalendarLuis.Intent.FindCalendarEntry: case CalendarLuis.Intent.FindCalendarWhen: case CalendarLuis.Intent.FindCalendarWhere: case CalendarLuis.Intent.FindCalendarWho: case CalendarLuis.Intent.FindDuration: await innerDc.BeginDialogAsync(nameof(ShowEventsDialog), new ShowMeetingsDialogOptions(ShowMeetingsDialogOptions.ShowMeetingReason.FirstShowOverview, newFlowOptions)); interrupted = true; break; case CalendarLuis.Intent.TimeRemaining: await innerDc.BeginDialogAsync(nameof(TimeRemainingDialog), newFlowOptions); interrupted = true; break; } } } } } } return(interrupted); }
// Handles routing to additional dialogs logic. private async Task <DialogTurnResult> RouteStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var a = stepContext.Context.Activity; var state = await _stateAccessor.GetAsync(stepContext.Context, () => new CalendarSkillState()); if (a.Type == ActivityTypes.Message && !string.IsNullOrEmpty(a.Text)) { var luisResult = stepContext.Context.TurnState.Get <CalendarLuis>(StateProperties.CalendarLuisResultKey); var intent = luisResult?.TopIntent().intent; state.InitialIntent = intent.Value; var generalResult = stepContext.Context.TurnState.Get <General>(StateProperties.GeneralLuisResultKey); var generalIntent = generalResult?.TopIntent().intent; InitializeConfig(state); var options = new CalendarSkillDialogOptions() { SubFlowMode = false }; // switch on general intents switch (intent) { case CalendarLuis.Intent.FindMeetingRoom: { // check whether the meeting room feature supported. if (!string.IsNullOrEmpty(_settings.AzureSearch?.SearchServiceName)) { return(await stepContext.BeginDialogAsync(_bookMeetingRoomDialog.Id, options)); } else { var activity = _templateEngine.GenerateActivityForLocale(CalendarMainResponses.FeatureNotAvailable); await stepContext.Context.SendActivityAsync(activity); } break; } case CalendarLuis.Intent.AddCalendarEntryAttribute: { // Determine the exact intent using entities if (luisResult.Entities.MeetingRoom != null || luisResult.Entities.MeetingRoomPatternAny != null || CalendarCommonUtil.ContainMeetingRoomSlot(luisResult)) { if (!string.IsNullOrEmpty(_settings.AzureSearch?.SearchServiceName)) { return(await stepContext.BeginDialogAsync(_updateMeetingRoomDialog.Id, options)); } else { var activity = _templateEngine.GenerateActivityForLocale(CalendarMainResponses.FeatureNotAvailable); await stepContext.Context.SendActivityAsync(activity); } } else { var activity = _templateEngine.GenerateActivityForLocale(CalendarMainResponses.FeatureNotAvailable); await stepContext.Context.SendActivityAsync(activity); } break; } case CalendarLuis.Intent.CreateCalendarEntry: { return(await stepContext.BeginDialogAsync(_createEventDialog.Id, options)); } case CalendarLuis.Intent.AcceptEventEntry: { return(await stepContext.BeginDialogAsync(_changeEventStatusDialog.Id, new ChangeEventStatusDialogOptions(options, EventStatus.Accepted))); } case CalendarLuis.Intent.DeleteCalendarEntry: { if (luisResult.Entities.MeetingRoom != null || luisResult.Entities.MeetingRoomPatternAny != null || CalendarCommonUtil.ContainMeetingRoomSlot(luisResult)) { if (!string.IsNullOrEmpty(_settings.AzureSearch?.SearchServiceName)) { return(await stepContext.BeginDialogAsync(_updateMeetingRoomDialog.Id, options)); } else { var activity = _templateEngine.GenerateActivityForLocale(CalendarMainResponses.FeatureNotAvailable); await stepContext.Context.SendActivityAsync(activity); } } else { return(await stepContext.BeginDialogAsync(_changeEventStatusDialog.Id, new ChangeEventStatusDialogOptions(options, EventStatus.Cancelled))); } break; } case CalendarLuis.Intent.ChangeCalendarEntry: { if (luisResult.Entities.MeetingRoom != null || luisResult.Entities.MeetingRoomPatternAny != null || CalendarCommonUtil.ContainMeetingRoomSlot(luisResult)) { if (!string.IsNullOrEmpty(_settings.AzureSearch?.SearchServiceName)) { return(await stepContext.BeginDialogAsync(_updateMeetingRoomDialog.Id, options)); } else { var activity = _templateEngine.GenerateActivityForLocale(CalendarMainResponses.FeatureNotAvailable); await stepContext.Context.SendActivityAsync(activity); } } else { return(await stepContext.BeginDialogAsync(_updateEventDialog.Id, options)); } break; } case CalendarLuis.Intent.ConnectToMeeting: { return(await stepContext.BeginDialogAsync(_joinEventDialog.Id, options)); } case CalendarLuis.Intent.FindCalendarEntry: case CalendarLuis.Intent.FindCalendarDetail: case CalendarLuis.Intent.FindCalendarWhen: case CalendarLuis.Intent.FindCalendarWhere: case CalendarLuis.Intent.FindCalendarWho: case CalendarLuis.Intent.FindDuration: { return(await stepContext.BeginDialogAsync(_showEventsDialog.Id, new ShowMeetingsDialogOptions(ShowMeetingsDialogOptions.ShowMeetingReason.FirstShowOverview, options))); } case CalendarLuis.Intent.TimeRemaining: { return(await stepContext.BeginDialogAsync(_timeRemainingDialog.Id)); } case CalendarLuis.Intent.CheckAvailability: { if (luisResult.Entities.MeetingRoom != null || luisResult.Entities.MeetingRoomPatternAny != null || CalendarCommonUtil.ContainMeetingRoomSlot(luisResult)) { if (!string.IsNullOrEmpty(_settings.AzureSearch?.SearchServiceName)) { state.InitialIntent = CalendarLuis.Intent.FindMeetingRoom; return(await stepContext.BeginDialogAsync(_bookMeetingRoomDialog.Id, options)); } else { var activity = _templateEngine.GenerateActivityForLocale(CalendarMainResponses.FeatureNotAvailable); await stepContext.Context.SendActivityAsync(activity); } } else { return(await stepContext.BeginDialogAsync(_checkPersonAvailableDialog.Id)); } break; } case CalendarLuis.Intent.ShowNextCalendar: case CalendarLuis.Intent.ShowPreviousCalendar: { return(await stepContext.BeginDialogAsync(_showEventsDialog.Id, new ShowMeetingsDialogOptions(ShowMeetingsDialogOptions.ShowMeetingReason.FirstShowOverview, options))); } case CalendarLuis.Intent.None: { if (generalIntent == General.Intent.ShowNext || generalIntent == General.Intent.ShowPrevious) { return(await stepContext.BeginDialogAsync(_showEventsDialog.Id, new ShowMeetingsDialogOptions(ShowMeetingsDialogOptions.ShowMeetingReason.FirstShowOverview, options))); } else { var activity = _templateEngine.GenerateActivityForLocale(CalendarSharedResponses.DidntUnderstandMessage); await stepContext.Context.SendActivityAsync(activity); } break; } default: { var activity = _templateEngine.GenerateActivityForLocale(CalendarMainResponses.FeatureNotAvailable); await stepContext.Context.SendActivityAsync(activity); break; } } } else if (a.Type == ActivityTypes.Event) { var ev = a.AsEventActivity(); switch (stepContext.Context.Activity.Name) { case Events.DeviceStart: { return(await stepContext.BeginDialogAsync(_upcomingEventDialog.Id)); } default: { await stepContext.Context.SendActivityAsync(new Activity(type : ActivityTypes.Trace, text : $"Unknown Event '{ev.Name ?? "undefined"}' was received but not processed.")); break; } } } // If activity was unhandled, flow should continue to next step return(await stepContext.NextAsync()); }
private RecreateMeetingRoomState?GetStateFromMessage(ITurnContext turnContext) { RecreateMeetingRoomState?result = null; var luisResult = turnContext.TurnState.Get <CalendarLuis>(StateProperties.CalendarLuisResultKey); var intent = luisResult.TopIntent().intent; switch (intent) { case CalendarLuis.Intent.CancelCalendar: { result = RecreateMeetingRoomState.Cancel; return(result); } case CalendarLuis.Intent.FindMeetingRoom: { result = RecreateMeetingRoomState.ChangeMeetingRoom; return(result); } case CalendarLuis.Intent.CheckAvailability: { if (luisResult.Entities.MeetingRoom != null) { result = RecreateMeetingRoomState.ChangeMeetingRoom; return(result); } break; } case CalendarLuis.Intent.ChangeCalendarEntry: { if (luisResult.Entities.ToDate != null || luisResult.Entities.ToTime != null || CalendarCommonUtil.ContainTimeSlot(luisResult)) { result = RecreateMeetingRoomState.ChangeTime; return(result); } if (luisResult.Entities.Building != null || luisResult.Entities.FloorNumber != null || luisResult.Entities.MeetingRoom != null || luisResult.Entities.MeetingRoomPatternAny != null || CalendarCommonUtil.ContainMeetingRoomSlot(luisResult)) { result = RecreateMeetingRoomState.ChangeMeetingRoom; return(result); } if (CalendarCommonUtil.ContainBuildingSlot(luisResult)) { result = RecreateMeetingRoomState.ChangeBuilding; return(result); } if (CalendarCommonUtil.ContainFloorSlot(luisResult)) { result = RecreateMeetingRoomState.ChangeFloorNumber; return(result); } break; } default: { break; } } return(result); }