// 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());
        }
Esempio n. 2
0
        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);
        }