コード例 #1
0
        public async Task StartAsync(IDialogContext ctx)
        {
            List <string> peopleList = GetPeopleList();

            if (peopleList.Count > 0)
            {
                await ctx.PostAsync(GetPeopleListMessage(peopleList));

                IEnumerable <Shared.MovieDetails> movies = await GetMovies(peopleList);

                if (movies.Count() > 0)
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (var movie in movies)
                    {
                        builder.Append($"{movie.title}\n\n");
                    }

                    //this.movieList = movies;
                    string filmText = movies.Count() > 1 ? "any of those movies" : "that film";
                    await ctx.PostAsync($"I have found {movies.Count()} films. Here is a list of them:\n\n{builder.ToString()}\n\nWould you like to know more about {filmText}?");

                    this.state = WhoWorkedState.UserPrompted;
                }
                else
                {
                    await ctx.PostAsync("There aren't any that I know.");

                    this.state = WhoWorkedState.MessageProcessed;
                    ctx.Done("No results found");
                }

                ctx.Wait(MessageReceivedAsync);
            }
            else
            {
                await ctx.PostAsync("I didn't recognise the names of any actors, could you try some others?");

                ctx.Done("Done");
            }
        }
コード例 #2
0
        public async Task MessageReceivedAsync(IDialogContext ctx, IAwaitable <IMessageActivity> argument)
        {
            var message = await argument;

            switch (this.state)
            {
            case WhoWorkedState.UserPrompted:
                Trinary carryOn = ParseReplyToPrompt(message.Text);
                this.state = WhoWorkedState.UserRepliedToPrompt;
                switch (carryOn)
                {
                case Trinary.Yes:
                    List <string> movieOptions = new List <string>();
                    IEnumerable <Shared.MovieDetails> movies = await GetMovies(GetPeopleList());

                    foreach (var movie in movies)
                    {
                        movieOptions.Add(movie.title);
                    }
                    PromptOptions <string> promptOptions = new PromptOptions <string>(prompt: "Which one?", options: movieOptions);
                    PromptDialog.Choice <string>(ctx, Resume, promptOptions);
                    break;

                case Trinary.No:
                    await ctx.PostAsync("OK, maybe another time.");

                    ctx.Done("");
                    break;

                default:
                    ctx.Done(message.Text);
                    break;
                }
                break;

            default:
                ctx.Wait(MessageReceivedAsync);
                break;
            }
        }
コード例 #3
0
 public WhoWorkedOnDialog(LUISResponse r)
 {
     this.response = r;
     this.state    = WhoWorkedState.MessageReceived;
 }