示例#1
0
        protected async Task <DialogTurnResult> IfClearPagingConditionStep(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                // Clear focus item
                state.UserSelectIndex = 0;

                // Clear search condition
                state.SenderName  = null;
                state.SearchTexts = null;

                return(await sc.NextAsync());
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
示例#2
0
        protected async Task <DialogTurnResult> PromptToHandle(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                if (state.MessageList.Count == 1)
                {
                    return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = ResponseManager.GetResponse(ShowEmailResponses.ReadOutOnlyOnePrompt) }));
                }
                else
                {
                    return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = ResponseManager.GetResponse(ShowEmailResponses.ReadOutPrompt) }));
                }
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
示例#3
0
        public async Task <DialogTurnResult> PromptToDelete(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                var skillOptions = (EmailSkillDialogOptions)sc.Options;

                var focusedMessage = state.Message?.FirstOrDefault();
                if (focusedMessage != null)
                {
                    var nameListString = DisplayHelper.ToDisplayRecipientsString_Summay(focusedMessage.ToRecipients);
                    var emailCard      = new EmailCardData
                    {
                        Subject      = string.Format(EmailCommonStrings.SubjectFormat, focusedMessage.Subject),
                        NameList     = string.Format(EmailCommonStrings.ToFormat, nameListString),
                        EmailContent = string.Format(EmailCommonStrings.ContentFormat, focusedMessage.BodyPreview),
                    };

                    var speech      = SpeakHelper.ToSpeechEmailSendDetailString(focusedMessage.Subject, nameListString, focusedMessage.BodyPreview);
                    var stringToken = new StringDictionary
                    {
                        { "EmailDetails", speech },
                    };
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(DeleteEmailResponses.DeleteConfirm, "Dialogs/Shared/Resources/Cards/EmailWithOutButtonCard.json", emailCard, ResponseBuilder, stringToken);

                    return(await sc.PromptAsync(Actions.TakeFurtherAction, new PromptOptions { Prompt = replyMessage, RetryPrompt = sc.Context.Activity.CreateReply(EmailSharedResponses.ConfirmSendFailed, ResponseBuilder), }));
                }

                skillOptions.SubFlowMode = true;
                return(await sc.BeginDialogAsync(Actions.UpdateSelectMessage, skillOptions));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
示例#4
0
        public async Task <DialogTurnResult> AfterUpdateUserName(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var userInput = sc.Result as string;
                var state     = await EmailStateAccessor.GetAsync(sc.Context);

                if (string.IsNullOrEmpty(userInput))
                {
                    await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(FindContactResponses.UserNotFoundAgain, null, new StringDictionary()
                    {
                        { "source", state.MailSourceType == Model.MailSource.Microsoft ? "Outlook" : "Gmail" }
                    }));

                    return(await sc.EndDialogAsync());
                }

                if (IsEmail(userInput))
                {
                    if (!state.EmailList.Contains(userInput))
                    {
                        state.EmailList.Add(userInput);
                    }
                }
                else
                {
                    state.NameList[state.ConfirmRecipientIndex] = userInput;
                }

                // should not return with value, next step use the return value for confirmation.
                return(await sc.EndDialogAsync());
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
示例#5
0
        public async Task <DialogTurnResult> AfterUpdateUserName(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var userInput = sc.Result as string;
                if (string.IsNullOrEmpty(userInput))
                {
                    return(await sc.EndDialogAsync());
                }

                var state = await EmailStateAccessor.GetAsync(sc.Context);

                state.NameList[state.ConfirmRecipientIndex] = userInput;

                // should not return with value, next step use the return value for confirmation.
                return(await sc.EndDialogAsync());
            }
            catch (Exception ex)
            {
                throw await HandleDialogExceptions(sc, ex);
            }
        }
示例#6
0
        public async Task <DialogTurnResult> CollectText(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                if (sc.Result != null)
                {
                    sc.Context.Activity.Properties.TryGetValue("OriginText", out var subject);
                    state.Subject = subject != null?subject.ToString() : sc.Context.Activity.Text;
                }

                if (string.IsNullOrEmpty(state.Content))
                {
                    var noMessageBodyMessage = sc.Context.Activity.CreateReply(SendEmailResponses.NoMessageBody);
                    if (sc.Result == null)
                    {
                        var recipientConfirmedMessage = sc.Context.Activity.CreateReply(EmailSharedResponses.RecipientConfirmed, null, new StringDictionary()
                        {
                            { "UserName", await GetNameListStringAsync(sc) }
                        });
                        noMessageBodyMessage.Text  = recipientConfirmedMessage.Text + " " + noMessageBodyMessage.Text;
                        noMessageBodyMessage.Speak = recipientConfirmedMessage.Speak + " " + noMessageBodyMessage.Speak;
                    }

                    return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = noMessageBodyMessage }));
                }
                else
                {
                    return(await sc.NextAsync());
                }
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
        public async Task <DialogTurnResult> CollectText(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                if (state.FindContactInfor.Contacts == null || state.FindContactInfor.Contacts.Count == 0)
                {
                    state.FindContactInfor.FirstRetryInFindContact = true;
                    return(await sc.EndDialogAsync());
                }

                if (!string.IsNullOrWhiteSpace(state.Content))
                {
                    return(await sc.NextAsync());
                }

                bool?isSkipByDefault = false;
                isSkipByDefault = Settings.DefaultValue?.SendEmail?.First(item => item.Name == "EmailMessage")?.IsSkipByDefault;
                if (isSkipByDefault.GetValueOrDefault())
                {
                    state.Subject = string.IsNullOrEmpty(EmailCommonStrings.DefaultContent) ? EmailCommonStrings.EmptyContent : EmailCommonStrings.DefaultContent;

                    return(await sc.NextAsync());
                }

                var skillOptions = (EmailSkillDialogOptions)sc.Options;
                skillOptions.SubFlowMode = true;
                return(await sc.BeginDialogAsync(Actions.UpdateContent, skillOptions));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
示例#8
0
        public async Task <DialogTurnResult> UpdateSubject(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                if (state.Recipients.Count == 0 || state.Recipients == null)
                {
                    await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(FindContactResponses.UserNotFoundAgain, null, new StringDictionary()
                    {
                        { "source", state.MailSourceType == Model.MailSource.Microsoft ? "Outlook" : "Gmail" }
                    }));

                    state.FirstRetryInFindContact = true;
                    return(await sc.EndDialogAsync());
                }

                var recipientConfirmedMessage = sc.Context.Activity.CreateReply(EmailSharedResponses.RecipientConfirmed, null, new StringDictionary()
                {
                    { "UserName", await GetNameListStringAsync(sc) }
                });
                var noSubjectMessage = sc.Context.Activity.CreateReply(SendEmailResponses.NoSubject);
                noSubjectMessage.Text  = recipientConfirmedMessage.Text + " " + noSubjectMessage.Text;
                noSubjectMessage.Speak = recipientConfirmedMessage.Speak + " " + noSubjectMessage.Speak;

                return(await sc.PromptAsync(Actions.Prompt, new PromptOptions()
                {
                    Prompt = noSubjectMessage,
                }));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
示例#9
0
        public async Task <DialogTurnResult> UpdateUserName(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                var currentRecipientName = state.NameList[state.ConfirmRecipientIndex];
                if (state.FirstRetryInFindContact)
                {
                    state.FirstRetryInFindContact = false;
                    return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(FindContactResponses.UserNotFound) }));
                }
                else
                {
                    return(await sc.CancelAllDialogsAsync());
                }
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
示例#10
0
        protected async Task ClearConversationState(WaterfallStepContext sc)
        {
            try
            {
                var skillOptions = (EmailSkillDialogOptions)sc.Options;
                var state        = await EmailStateAccessor.GetAsync(sc.Context);

                // Keep email display and focus data when in sub flow mode
                if (!skillOptions.SubFlowMode)
                {
                    state.Message.Clear();
                    state.ShowEmailIndex  = 0;
                    state.IsUnreadOnly    = true;
                    state.IsImportant     = false;
                    state.StartDateTime   = DateTime.UtcNow.Add(new TimeSpan(-7, 0, 0, 0));
                    state.EndDateTime     = DateTime.UtcNow;
                    state.DirectlyToMe    = false;
                    state.UserSelectIndex = -1;
                }

                state.NameList.Clear();
                state.Content = null;
                state.Subject = null;
                state.Recipients.Clear();
                state.ConfirmRecipientIndex     = 0;
                state.SenderName                = null;
                state.EmailList                 = new List <string>();
                state.ShowRecipientIndex        = 0;
                state.LuisResultPassedFromSkill = null;
            }
            catch (Exception)
            {
                // todo : should log error here.
                throw;
            }
        }
        public async Task <DialogTurnResult> SendEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                var token = state.Token;

                var service = ServiceManager.InitMailService(token, state.GetUserTimeZone(), state.MailSourceType);

                // send user message.
                var subject = state.Subject.Equals(EmailCommonStrings.EmptySubject) ? string.Empty : state.Subject;
                var content = state.Content.Equals(EmailCommonStrings.EmptyContent) ? string.Empty : state.Content;
                await service.SendMessageAsync(content, subject, state.FindContactInfor.Contacts);

                var replyMessage = MessageFactory.Text("Thank you! An email has been sent to the team.");

                await sc.Context.SendActivityAsync(replyMessage);
            }
            catch (SkillException ex)
            {
                await HandleDialogExceptions(sc, ex);

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

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

            await ClearConversationState(sc);

            return(await sc.EndDialogAsync(true));
        }