Ejemplo n.º 1
0
        private async Task DigestActionInputAsync(DialogContext dc, KeywordSearchInfo request, CancellationToken cancellationToken)
        {
            var state = await _stateAccessor.GetAsync(dc.Context, () => new SkillState(), cancellationToken : cancellationToken);

            state.SearchEntityName = request.Keyword;
        }
Ejemplo n.º 2
0
        // 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 SkillState());

            state.IsAction = false;

            if (a.Type == ActivityTypes.Message && !string.IsNullOrEmpty(a.Text))
            {
                // Get cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Run LUIS recognition on Skill model and store result in turn state.
                localizedServices.LuisServices.TryGetValue("BingSearchSkill", 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 <BingSearchSkillLuis>(stepContext.Context, cancellationToken);

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

                    switch (intent)
                    {
                    case BingSearchSkillLuis.Intent.GetCelebrityInfo:
                    case BingSearchSkillLuis.Intent.SearchMovieInfo:
                    case BingSearchSkillLuis.Intent.None:
                    {
                        return(await stepContext.BeginDialogAsync(nameof(SearchDialog), cancellationToken : cancellationToken));
                    }

                    default:
                    {
                        // intent was identified but not yet implemented
                        await stepContext.Context.SendActivityAsync(_templateManager.GenerateActivity(MainResponses.FeatureNotAvailable), cancellationToken);

                        break;
                    }
                    }
                }
            }
            else if (a.Type == ActivityTypes.Event)
            {
                // Handle skill actions here
                var eventActivity = a.AsEventActivity();

                if (!string.IsNullOrEmpty(eventActivity.Name))
                {
                    switch (eventActivity.Name)
                    {
                    // Each Action in the Manifest will have an associated Name which will be on incoming Event activities
                    case "BingSearch":
                    {
                        KeywordSearchInfo actionData = null;

                        var eventValue = a.Value as JObject;
                        if (eventValue != null)
                        {
                            actionData = eventValue.ToObject <KeywordSearchInfo>();
                            await DigestActionInputAsync(stepContext, actionData, cancellationToken);
                        }

                        state.IsAction = true;
                        return(await stepContext.BeginDialogAsync(nameof(SearchDialog), cancellationToken : cancellationToken));
                    }

                    default:

                        // todo: move the response to lg
                        await stepContext.Context.SendActivityAsync(new Activity(type : ActivityTypes.Trace, text : $"Unknown Event '{eventActivity.Name ?? "undefined"}' was received but not processed."), cancellationToken);

                        break;
                    }
                }
            }

            // If activity was unhandled, flow should continue to next step
            return(await stepContext.NextAsync(cancellationToken : cancellationToken));
        }