示例#1
0
        private async Task <PromptOptions> GenerateOptionsForEmail(WaterfallStepContext sc, CustomizedPerson confirmedPerson, ITurnContext context, bool isSinglePage = true)
        {
            var state = await Accessor.GetAsync(context);

            var pageIndex = state.ShowAttendeesIndex;
            var pageSize  = 3;
            var skip      = pageSize * pageIndex;
            var emailList = confirmedPerson.Emails.ToList();

            // Go back to the last page when reaching the end.
            if (skip >= emailList.Count && pageIndex > 0)
            {
                state.ShowAttendeesIndex--;
                pageIndex = state.ShowAttendeesIndex;
                skip      = pageSize * pageIndex;
                await sc.Context.SendActivityAsync(ResponseManager.GetResponse(FindContactResponses.AlreadyLastPage));
            }

            var options = new PromptOptions
            {
                Choices = new List <Choice>(),
                Prompt  = ResponseManager.GetResponse(FindContactResponses.ConfirmMultiplContactEmailSinglePage, new StringDictionary()
                {
                    { "UserName", confirmedPerson.DisplayName }
                })
            };

            if (!isSinglePage)
            {
                options.Prompt = ResponseManager.GetResponse(FindContactResponses.ConfirmMultiplContactEmailMultiPage, new StringDictionary()
                {
                    { "UserName", confirmedPerson.DisplayName }
                });
            }

            for (var i = 0; i < emailList.Count; i++)
            {
                var user        = confirmedPerson;
                var mailAddress = emailList[i].Address ?? user.UserPrincipalName;

                var choice = new Choice()
                {
                    Value    = $"{user.DisplayName}: {mailAddress}",
                    Synonyms = new List <string> {
                        (options.Choices.Count + 1).ToString(), user.DisplayName, user.DisplayName.ToLower(), mailAddress
                    },
                };
                var userName = user.UserPrincipalName?.Split("@").FirstOrDefault() ?? user.UserPrincipalName;
                if (!string.IsNullOrEmpty(userName))
                {
                    choice.Synonyms.Add(userName);
                    choice.Synonyms.Add(userName.ToLower());
                }

                if (skip <= 0)
                {
                    if (options.Choices.Count >= pageSize)
                    {
                        options.Prompt.Speak = SpeakHelper.ToSpeechSelectionDetailString(options, Common.ConfigData.GetInstance().MaxDisplaySize);
                        options.Prompt.Text += "\r\n" + GetSelectPromptEmailString(options, true);
                        options.RetryPrompt  = ResponseManager.GetResponse(CalendarSharedResponses.DidntUnderstandMessage);
                        return(options);
                    }

                    options.Choices.Add(choice);
                }
                else
                {
                    skip--;
                }
            }

            options.Prompt.Speak = SpeakHelper.ToSpeechSelectionDetailString(options, Common.ConfigData.GetInstance().MaxDisplaySize);
            options.Prompt.Text += "\r\n" + GetSelectPromptEmailString(options, true);
            options.RetryPrompt  = ResponseManager.GetResponse(CalendarSharedResponses.DidntUnderstandMessage);
            return(options);
        }
示例#2
0
        private async Task <PromptOptions> GenerateOptionsForName(WaterfallStepContext sc, List <Person> unionList, ITurnContext context, bool isSinglePage = true)
        {
            var state = await EmailStateAccessor.GetAsync(context);

            var pageIndex            = state.ShowRecipientIndex;
            var pageSize             = ConfigData.GetInstance().MaxDisplaySize;
            var skip                 = pageSize * pageIndex;
            var currentRecipientName = state.NameList[state.ConfirmRecipientIndex];

            // Go back to the last page when reaching the end.
            if (skip >= unionList.Count && pageIndex > 0)
            {
                state.ShowRecipientIndex--;
                state.ReadRecipientIndex = 0;
                pageIndex = state.ShowRecipientIndex;
                skip      = pageSize * pageIndex;
                await sc.Context.SendActivityAsync(ResponseManager.GetResponse(FindContactResponses.AlreadyLastPage));
            }

            var options = new PromptOptions
            {
                Choices = new List <Choice>(),
                Prompt  = ResponseManager.GetResponse(FindContactResponses.ConfirmMultipleContactNameSinglePage, new StringDictionary()
                {
                    { "UserName", currentRecipientName }
                })
            };

            if (!isSinglePage)
            {
                options.Prompt = ResponseManager.GetResponse(FindContactResponses.ConfirmMultipleContactNameMultiPage, new StringDictionary()
                {
                    { "UserName", currentRecipientName }
                });
            }

            for (var i = 0; i < unionList.Count; i++)
            {
                var user = unionList[i];

                var choice = new Choice()
                {
                    Value    = $"**{user.DisplayName}**",
                    Synonyms = new List <string> {
                        (options.Choices.Count + 1).ToString(), user.DisplayName, user.DisplayName.ToLower()
                    },
                };
                var userName = user.UserPrincipalName?.Split("@").FirstOrDefault() ?? user.UserPrincipalName;
                if (!string.IsNullOrEmpty(userName))
                {
                    choice.Synonyms.Add(userName);
                    choice.Synonyms.Add(userName.ToLower());
                }

                if (skip <= 0)
                {
                    if (options.Choices.Count >= pageSize)
                    {
                        options.Prompt.Speak = SpeakHelper.ToSpeechSelectionDetailString(options, ConfigData.GetInstance().MaxReadSize);
                        options.Prompt.Text += "\r\n" + GetSelectPromptString(options, true);
                        options.RetryPrompt  = ResponseManager.GetResponse(EmailSharedResponses.NoChoiceOptionsRetry);
                        return(options);
                    }

                    options.Choices.Add(choice);
                }
                else
                {
                    skip--;
                }
            }

            options.Prompt.Speak = SpeakHelper.ToSpeechSelectionDetailString(options, ConfigData.GetInstance().MaxReadSize);
            options.Prompt.Text += "\r\n" + GetSelectPromptString(options, true);
            options.RetryPrompt  = ResponseManager.GetResponse(EmailSharedResponses.NoChoiceOptionsRetry);
            return(options);
        }
示例#3
0
        public async Task <DialogTurnResult> ConfirmRecipient(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                if ((state.NameList == null) || (state.NameList.Count == 0))
                {
                    return(await sc.NextAsync());
                }

                var currentRecipientName = state.NameList[state.ConfirmRecipientIndex];

                var originPersonList = await GetPeopleWorkWithAsync(sc, currentRecipientName);

                var originContactList = await GetContactsAsync(sc, currentRecipientName);

                originPersonList.AddRange(originContactList);

                // msa account can not get user from your org. and token type is not jwt.
                // TODO: find a way to check the account is msa or aad.
                var handler        = new JwtSecurityTokenHandler();
                var originUserList = new List <Person>();
                try
                {
                    originUserList = await GetUserAsync(sc, currentRecipientName);
                }
                catch
                {
                    // do nothing when get user failed. because can not use token to ensure user use a work account.
                }

                (var personList, var userList) = DisplayHelper.FormatRecipientList(originPersonList, originUserList);

                // todo: should set updatename reason in stepContext.Result
                if (personList.Count > 10)
                {
                    return(await sc.BeginDialogAsync(Actions.UpdateRecipientName, new UpdateUserDialogOptions(UpdateUserDialogOptions.UpdateReason.TooMany)));
                }

                // if cannot find related user's name and cannot take user input as email address, send not found
                if ((personList.Count < 1) && (userList.Count < 1) && (state.EmailList.Count < 1))
                {
                    return(await sc.BeginDialogAsync(Actions.UpdateRecipientName, new UpdateUserDialogOptions(UpdateUserDialogOptions.UpdateReason.NotFound)));
                }

                if (personList.Count == 1)
                {
                    var user = personList.FirstOrDefault();
                    if (user != null)
                    {
                        var result =
                            new FoundChoice()
                        {
                            Value =
                                $"{user.DisplayName}: {user.ScoredEmailAddresses.FirstOrDefault()?.Address ?? user.UserPrincipalName}",
                        };

                        return(await sc.NextAsync(result));
                    }
                }

                if (state.EmailList.Count == 1)
                {
                    var email = state.EmailList.FirstOrDefault();
                    if (email != null)
                    {
                        var result =
                            new FoundChoice()
                        {
                            Value =
                                $"{email}: {email}",
                        };

                        return(await sc.NextAsync(result));
                    }
                }

                if (sc.Options is UpdateUserDialogOptions updateUserDialogOptions)
                {
                    state.ShowRecipientIndex = 0;
                    state.ReadRecipientIndex = 0;
                    return(await sc.BeginDialogAsync(Actions.UpdateRecipientName, updateUserDialogOptions));
                }

                // TODO: should be simplify
                var selectOption = await GenerateOptions(personList, userList, sc);

                var startIndex = ConfigData.GetInstance().MaxReadSize *state.ReadRecipientIndex;
                var choices    = new List <Choice>();
                for (int i = startIndex; i < selectOption.Choices.Count; i++)
                {
                    choices.Add(selectOption.Choices[i]);
                }

                selectOption.Choices      = choices;
                state.RecipientChoiceList = choices;

                // If no more recipient to show, start update name flow and reset the recipient paging index.
                if (selectOption.Choices.Count == 0)
                {
                    state.ShowRecipientIndex = 0;
                    state.ReadRecipientIndex = 0;
                    state.RecipientChoiceList.Clear();
                    return(await sc.BeginDialogAsync(Actions.UpdateRecipientName, new UpdateUserDialogOptions(UpdateUserDialogOptions.UpdateReason.NotFound)));
                }

                selectOption.Prompt.Speak = SpeakHelper.ToSpeechSelectionDetailString(selectOption, ConfigData.GetInstance().MaxReadSize);

                // Update prompt string to include the choices because the list style is none;
                // TODO: should be removed if use adaptive card show choices.
                var choiceString = GetSelectPromptString(selectOption, true);
                selectOption.Prompt.Text = choiceString;

                return(await sc.PromptAsync(Actions.Choice, selectOption));
            }
            catch (SkillException skillEx)
            {
                await HandleDialogExceptions(sc, skillEx);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }