コード例 #1
0
        private async Task <DialogTurnResult> ShowMeetingTimeSuggestions(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            double duration      = Convert.ToDouble(stepContext.Context.TurnState["data"]);
            var    tokenResponse = (TokenResponse)stepContext.Result;

            if (tokenResponse?.Token != null)
            {
                // Pull in the data from the Microsoft Graph.
                var           client        = new SimpleGraphClient(tokenResponse.Token);
                MeetingDetail meetingDetail = await RetrieveMeetingDetailsAsync(table, userEmail, stepContext.Context.Activity.Conversation.Id); //retrives data from table

                timeSuggestions = await client.FindMeetingTimes(meetingDetail.Attendees, duration);                                              //returns meeting times

                if (timeSuggestions.Count == 0)
                {
                    await stepContext.Context.SendActivityAsync("No appropriate meeting slot found. Please try again by typing 'hi' and change date this time");

                    return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
                }
                var cardOptions = new List <Choice>();
                for (int i = 0; i < timeSuggestions.Count; i++)
                {
                    cardOptions.Add(new Choice()
                    {
                        Value = timeSuggestions[i].Start.DateTime + " - " + timeSuggestions[i].End.DateTime
                    });                                                                                                                    //creates list of meeting time choices
                }



                return(await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions
                {
                    Prompt = MessageFactory.Text("These are the time suggestions. Click on the time slot for when you want the meeting to be set."),
                    RetryPrompt = MessageFactory.Text("Sorry, Please the valid choice"),
                    Choices = cardOptions,
                    Style = ListStyle.HeroCard, //displays choices as buttons
                }, cancellationToken));
            }
            await stepContext.Context.SendActivityAsync("Something went wrong. Please type anything to get started again.");

            return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
        }