Exemplo n.º 1
0
        private async Task <DialogTurnResult> AskForDuration(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string result = (string)stepContext.Context.TurnState["data"]; //gets attendees' names

            var tokenResponse = (TokenResponse)stepContext.Result;         //gets token

            if (tokenResponse?.Token != null)
            {
                var      client        = new SimpleGraphClient(tokenResponse.Token);
                string[] attendeeNames = string.Concat(result.Where(c => !char.IsWhiteSpace(c))).Split(","); //splits comma separated names of attendees

                List <string> attendeeTableStorage = new List <string>();
                foreach (string name in attendeeNames)
                {
                    List <string> attendeeEmails = await client.GetAttendeeEmailFromName(name); //gets email from attendee's name

                    if (attendeeEmails.Count > 1)                                               //there can be multiple people having same first name, ask user to start again and enter email instead to be more specific
                    {
                        await stepContext.Context.SendActivityAsync("There are " + attendeeEmails.Count + " people whose name start with " + name + ". Please type hi to start again, and instead of first name, enter email to avoid ambiguity.");

                        return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
                    }
                    else if (attendeeEmails.Count == 1)  // attendee found
                    {
                        attendeeTableStorage.Add(attendeeEmails[0]);
                    }
                    else //attendee not found in organization
                    {
                        await stepContext.Context.SendActivityAsync("Attendee not found, please type anything to start again");

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

                var sb = new System.Text.StringBuilder();
                foreach (string email in attendeeTableStorage)
                {
                    sb.Append(email + ","); //converts emails to comma separated string to store in table
                }
                string finalString = sb.ToString().Remove(sb.Length - 1);
                if (result != null)
                {
                    MeetingDetail meetingDetail = new MeetingDetail(stepContext.Context.Activity.Conversation.Id, userEmail);
                    meetingDetail.Attendees = finalString;

                    await InsertOrMergeEntityAsync(table, meetingDetail); //inserts attendees' emails in table

                    return(await stepContext.PromptAsync(nameof(NumberPrompt <double>), new PromptOptions { Prompt = MessageFactory.Text("What will be duration of the meeting? (in hours)"), RetryPrompt = MessageFactory.Text("Invalid value, please enter a proper value") }, cancellationToken));
                }
            }
            await stepContext.Context.SendActivityAsync("Something went wrong. Please type anything to get started again.");

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