Ejemplo n.º 1
0
        protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var routeResult = EndOfTurn;

            // get current activity locale
            var locale       = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
            var localeConfig = _services.LocaleConfigurations[locale];

            // If dispatch result is general luis model
            localeConfig.LuisServices.TryGetValue("pointofinterest", 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 <PointOfInterest>(dc, true, CancellationToken.None);

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

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

                // switch on general intents
                switch (intent)
                {
                case PointOfInterest.Intent.NAVIGATION_ROUTE_FROM_X_TO_Y:
                {
                    routeResult = await dc.BeginDialogAsync(nameof(RouteDialog), skillOptions);

                    break;
                }

                case PointOfInterest.Intent.NAVIGATION_CANCEL_ROUTE:
                {
                    routeResult = await dc.BeginDialogAsync(nameof(CancelRouteDialog), skillOptions);

                    break;
                }

                case PointOfInterest.Intent.NAVIGATION_FIND_POINTOFINTEREST:
                {
                    routeResult = await dc.BeginDialogAsync(nameof(FindPointOfInterestDialog), skillOptions);

                    break;
                }

                case PointOfInterest.Intent.None:
                {
                    await dc.Context.SendActivityAsync(dc.Context.Activity.CreateReply(POISharedResponses.DidntUnderstandMessage));

                    if (_skillMode)
                    {
                        routeResult = new DialogTurnResult(DialogTurnStatus.Complete);
                    }

                    break;
                }

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

                    if (_skillMode)
                    {
                        routeResult = new DialogTurnResult(DialogTurnStatus.Complete);
                    }

                    break;
                }
                }
            }

            if (routeResult.Status == DialogTurnStatus.Complete)
            {
                await CompleteAsync(dc);
            }
        }
Ejemplo n.º 2
0
        protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Get the conversation state from the turn context
            var state = await _accessors.PointOfInterestSkillState.GetAsync(dc.Context, () => new PointOfInterestSkillState());

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

            PointOfInterest luisResult = null;

            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 <PointOfInterest>(dc.Context, cancellationToken);
            }
            else 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 = (PointOfInterest)state.LuisResultPassedFromSkill;
            }
            else
            {
                throw new Exception("PointOfInterestSkill: Could not get Luis Recognizer result.");
            }

            await DigestPointOfInterestLuisResult(dc, luisResult);

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

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

            var result = EndOfTurn;

            switch (intent)
            {
            case PointOfInterest.Intent.NAVIGATION_ROUTE_FROM_X_TO_Y:
            {
                result = await dc.BeginDialogAsync(nameof(RouteDialog), skillOptions);

                break;
            }

            case PointOfInterest.Intent.NAVIGATION_CANCEL_ROUTE:
            {
                result = await dc.BeginDialogAsync(nameof(CancelRouteDialog), skillOptions);

                break;
            }

            case PointOfInterest.Intent.NAVIGATION_FIND_POINTOFINTEREST:
            {
                result = await dc.BeginDialogAsync(nameof(FindPointOfInterestDialog), skillOptions);

                break;
            }

            case PointOfInterest.Intent.None:
            case null:
            default:
            {
                result = new DialogTurnResult(DialogTurnStatus.Complete);
                await _responder.ReplyWith(dc.Context, PointOfInterestSkillResponses.Confused);

                break;
            }
            }

            if (result.Status == DialogTurnStatus.Complete)
            {
                await CompleteAsync(dc);
            }
        }