Example #1
0
        private async Task <DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var luisResult = (Movies4Anyone)stepContext?.Options;

            PromptOptions opts = null;

            switch (luisResult.TopIntent().intent)
            {
            case Movies4Anyone.Intent.movieVideos:
                if (luisResult.Entities.movie != null)
                {
                    var lookupJson = await _tmdbService
                                     .FetchInformation(TMDBEndpoints.APIEndpoints[Movies4Anyone.Intent.searchMovie.ToString()], luisResult.Entities.movie.FirstOrDefault(), null);

                    var movieResult   = JsonConvert.DeserializeObject <SearchResult <MovieResult> >(lookupJson);
                    var recommendJson = await _tmdbService
                                        .FetchInformation(TMDBEndpoints.APIEndpoints[Movies4Anyone.Intent.movieVideos.ToString()], "", movieResult.Results.FirstOrDefault().Id);

                    var recommendationResult = JsonConvert.DeserializeObject <Videos>(recommendJson);
                    opts = new AdaptiveCardGenerator().GenerateVideosAttachment(recommendationResult);
                }
                else
                {
                    var promptMessage = MessageFactory.Text("Please repeat the name of the movie", "Please repeat the name of the movie", InputHints.ExpectingInput);
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
                }
                break;

            case Movies4Anyone.Intent.tvVideos:
                if (luisResult.Entities.tv_show != null)
                {
                    var lookupJson = await _tmdbService
                                     .FetchInformation(TMDBEndpoints.APIEndpoints[Movies4Anyone.Intent.searchTV.ToString()], luisResult.Entities.tv_show.FirstOrDefault(), null);

                    var tvResult      = JsonConvert.DeserializeObject <SearchResult <TvResult> >(lookupJson);
                    var recommendJson = await _tmdbService
                                        .FetchInformation(TMDBEndpoints.APIEndpoints[Movies4Anyone.Intent.tvVideos.ToString()], "", tvResult.Results.FirstOrDefault().Id);

                    var recommendationResult = JsonConvert.DeserializeObject <Videos>(recommendJson);
                    opts = new AdaptiveCardGenerator().GenerateVideosAttachment(recommendationResult);
                }
                else
                {
                    var promptMessage = MessageFactory.Text("Please repeat the name of the show", "Please repeat the name of the movie", InputHints.ExpectingInput);
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
                }

                break;
            }

            if (opts != null)
            {
                await stepContext.Context.SendActivityAsync(opts.Prompt);

                opts.Prompt = new Activity(type: ActivityTypes.Typing);
                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            return(await stepContext.NextAsync(0, cancellationToken));
        }
Example #2
0
        private async Task <DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var luisResult = (Movies4Anyone)stepContext?.Options;

            PromptOptions opts = null;

            switch (luisResult.TopIntent().intent)
            {
            case Movies4Anyone.Intent.searchMovie:
                if (luisResult.Entities.movie != null)
                {
                    var lookupJson = await _tmdbService
                                     .FetchInformation(TMDBEndpoints.APIEndpoints[Movies4Anyone.Intent.searchMovie.ToString()], luisResult.Entities.movie.FirstOrDefault(), null);

                    var movieResult = JsonConvert.DeserializeObject <SearchResult <MovieResult> >(lookupJson);
                    opts = new AdaptiveCardGenerator().GenerateMovieSearchAttachment(movieResult);
                }
                else
                {
                    var promptMessage = MessageFactory.Text("I didn't get the name of the movie. Could you repeat please?", "I didn't get the name of the movie. Could you repeat please?", InputHints.ExpectingInput);
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
                }
                break;

            case Movies4Anyone.Intent.searchTV:
                if (luisResult.Entities.tv_show != null)
                {
                    var lookupJson = await _tmdbService
                                     .FetchInformation(TMDBEndpoints.APIEndpoints[Movies4Anyone.Intent.searchTV.ToString()], luisResult.Entities.tv_show.FirstOrDefault(), null);

                    var tvResult = JsonConvert.DeserializeObject <SearchResult <TvResult> >(lookupJson);
                    opts = new AdaptiveCardGenerator().GenerateTvSearchAttachment(tvResult);
                }
                else
                {
                    var promptMessage = MessageFactory.Text("I didn't get the name of the tv show. Could you repeat please?", "I didn't get the name of the tv show. Could you repeat please?", InputHints.ExpectingInput);
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
                }
                break;

            case Movies4Anyone.Intent.searchPeople:
                if (luisResult.Entities.person != null)
                {
                    var lookupJson = await _tmdbService
                                     .FetchInformation(TMDBEndpoints.APIEndpoints[Movies4Anyone.Intent.searchPeople.ToString()], luisResult.Entities.person.FirstOrDefault(), null);

                    var peopleResult = JsonConvert.DeserializeObject <SearchResult <PersonResult> >(lookupJson);
                    opts = new AdaptiveCardGenerator().GeneratePersonSearchAttachment(peopleResult);
                }
                else
                {
                    var promptMessage = MessageFactory.Text("I didn't get the name of this person. Could you repeat please?", "I didn't get the name of this person. Could you repeat please?", InputHints.ExpectingInput);
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
                }
                break;
            }

            if (opts != null)
            {
                await stepContext.Context.SendActivityAsync(opts.Prompt);

                opts.Prompt = new Activity(type: ActivityTypes.Typing);
                return(await stepContext.PromptAsync("Prompt", opts, cancellationToken));
            }

            return(await stepContext.NextAsync(0, cancellationToken));
        }