Esempio n. 1
0
        protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Get the conversation state from the turn context
            var state = await _accessors.CalendarSkillState.GetAsync(dc.Context, () => new CalendarSkillState());

            var dialogState = await _accessors.ConversationDialogState.GetAsync(dc.Context, () => new DialogState());

            Calendar luisResult = null;

            if (_skillMode && state.LuisResultPassedFromSkill != null)
            {
                // If invoked by a Skill we get the Luis IRecognizerConvert passed to us on first turn so we don't have to do that locally
                luisResult = (Calendar)state.LuisResultPassedFromSkill;
                state.LuisResultPassedFromSkill = null;
            }
            else if (_services?.LuisRecognizer != null)
            {
                // When run in normal mode or 2+ turn of a skill we use LUIS ourselves as the parent Dispatcher doesn't do this
                luisResult = await _services.LuisRecognizer.RecognizeAsync <Calendar>(dc.Context, cancellationToken);
            }
            else
            {
                throw new Exception("CalendarSkill: Could not get Luis Recognizer result.");
            }

            var intent = luisResult?.TopIntent().intent;

            var skillOptions = new CalendarSkillDialogOptions
            {
                SkillMode = _skillMode,
            };

            switch (intent)
            {
            case Calendar.Intent.Greeting:
            {
                await dc.BeginDialogAsync(GreetingDialog.Name, skillOptions);

                break;
            }

            case Calendar.Intent.FindMeetingRoom:
            case Calendar.Intent.CreateCalendarEntry:
            {
                await dc.BeginDialogAsync(CreateEventDialog.Name, skillOptions);

                break;
            }

            case Calendar.Intent.DeleteCalendarEntry:
            {
                await dc.BeginDialogAsync(DeleteEventDialog.Name, skillOptions);

                break;
            }

            case Calendar.Intent.NextMeeting:
            {
                await dc.BeginDialogAsync(NextMeetingDialog.Name, skillOptions);

                break;
            }

            case Calendar.Intent.ChangeCalendarEntry:
            {
                await dc.BeginDialogAsync(UpdateEventDialog.Name, skillOptions);

                break;
            }

            case Calendar.Intent.FindCalendarEntry:
            case Calendar.Intent.ShowNext:
            case Calendar.Intent.ShowPrevious:
            case Calendar.Intent.Summary:
            {
                await dc.BeginDialogAsync(SummaryDialog.Name, skillOptions);

                break;
            }

            case Calendar.Intent.None:
            {
                await _responder.ReplyWith(dc.Context, CalendarSkillResponses.Confused);

                if (_skillMode)
                {
                    await CompleteAsync(dc);
                }

                break;
            }

            default:
            {
                await dc.Context.SendActivityAsync("This feature is not yet available in the Calendar Skill. Please try asking something else.");

                if (_skillMode)
                {
                    await CompleteAsync(dc);
                }
                break;
            }
            }
        }
Esempio n. 2
0
        protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await _stateAccessor.GetAsync(dc.Context, () => new CalendarSkillState());

            // If dispatch result is general luis model
            _services.LuisServices.TryGetValue("calendar", out var luisService);

            if (luisService == null)
            {
                throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
            }
            else
            {
                var result = await luisService.RecognizeAsync <Calendar>(dc.Context, CancellationToken.None);

                var intent           = result?.TopIntent().intent;
                var generalTopIntent = state.GeneralLuisResult?.TopIntent().intent;

                var skillOptions = new CalendarSkillDialogOptions
                {
                    SkillMode = _skillMode,
                };

                // switch on general intents
                switch (intent)
                {
                case Calendar.Intent.FindMeetingRoom:
                case Calendar.Intent.CreateCalendarEntry:
                {
                    await dc.BeginDialogAsync(nameof(CreateEventDialog), skillOptions);

                    break;
                }

                case Calendar.Intent.DeleteCalendarEntry:
                {
                    await dc.BeginDialogAsync(nameof(DeleteEventDialog), skillOptions);

                    break;
                }

                case Calendar.Intent.NextMeeting:
                {
                    await dc.BeginDialogAsync(nameof(NextMeetingDialog), skillOptions);

                    break;
                }

                case Calendar.Intent.ChangeCalendarEntry:
                {
                    await dc.BeginDialogAsync(nameof(UpdateEventDialog), skillOptions);

                    break;
                }

                case Calendar.Intent.FindCalendarEntry:
                case Calendar.Intent.Summary:
                {
                    await dc.BeginDialogAsync(nameof(SummaryDialog), skillOptions);

                    break;
                }

                case Calendar.Intent.None:
                {
                    if (generalTopIntent == General.Intent.Next || generalTopIntent == General.Intent.Previous)
                    {
                        await dc.BeginDialogAsync(nameof(SummaryDialog), skillOptions);
                    }
                    else
                    {
                        await dc.Context.SendActivityAsync(dc.Context.Activity.CreateReply(CalendarSharedResponses.DidntUnderstandMessage));

                        if (_skillMode)
                        {
                            await CompleteAsync(dc);
                        }
                    }

                    break;
                }

                default:
                {
                    await dc.Context.SendActivityAsync(dc.Context.Activity.CreateReply(CalendarMainResponses.FeatureNotAvailable));

                    if (_skillMode)
                    {
                        await CompleteAsync(dc);
                    }

                    break;
                }
                }
            }
        }