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

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

                string nameListString;

                // this means reply confirm
                if (state.Recipients.FirstOrDefault() == null)
                {
                    await GetPreviewSubject(sc, Actions.Reply);

                    nameListString = await GetPreviewNameListString(sc, Actions.Reply);
                }
                else if (state.Subject == null)
                {
                    // this mean forward confirm
                    await GetPreviewSubject(sc, Actions.Forward);

                    nameListString = await GetPreviewNameListString(sc, Actions.Forward);
                }
                else
                {
                    nameListString = await GetPreviewNameListString(sc, Actions.Send);
                }

                var emailCard = new EmailCardData
                {
                    Subject      = string.Format(CommonStrings.SubjectFormat, state.Subject),
                    NameList     = string.Format(CommonStrings.ToFormat, nameListString),
                    EmailContent = string.Format(CommonStrings.ContentFormat, state.Content),
                };

                var speech      = SpeakHelper.ToSpeechEmailSendDetailString(emailCard.Subject, emailCard.NameList, emailCard.EmailContent);
                var stringToken = new StringDictionary
                {
                    { "EmailDetails", speech },
                };
                var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(EmailSharedResponses.ConfirmSend, "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), }));
            }
            catch (Exception ex)
            {
                throw await HandleDialogExceptions(sc, ex);
            }
        }
Example #2
0
        public async Task <DialogTurnResult> ReplyEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var confirmResult = (bool)sc.Result;
                if (confirmResult)
                {
                    var state = await EmailStateAccessor.GetAsync(sc.Context);

                    var token   = state.MsGraphToken;
                    var message = state.Message.FirstOrDefault();
                    var content = state.Content;

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

                    // reply user message.
                    if (message != null)
                    {
                        await service.ReplyToMessageAsync(message.Id, content);
                    }

                    var nameListString = $"To: {message?.From.EmailAddress.Name}";
                    if (message?.ToRecipients.Count() > 1)
                    {
                        nameListString += $" + {message.ToRecipients.Count() - 1} more";
                    }

                    var emailCard = new EmailCardData
                    {
                        Subject      = "RE: " + message?.Subject,
                        NameList     = nameListString,
                        EmailContent = state.Content,
                    };
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(EmailSharedResponses.SentSuccessfully, "Dialogs/Shared/Resources/Cards/EmailWithOutButtonCard.json", emailCard);

                    await sc.Context.SendActivityAsync(replyMessage);
                }
                else
                {
                    await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(EmailSharedResponses.CancellingMessage));
                }
            }
            catch (Exception ex)
            {
                throw await HandleDialogExceptions(sc, ex);
            }

            await ClearConversationState(sc);

            return(await sc.EndDialogAsync(true));
        }
Example #3
0
        public async Task <DialogTurnResult> ReplyEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var confirmResult = (bool)sc.Result;
                if (confirmResult)
                {
                    var state = await EmailStateAccessor.GetAsync(sc.Context);

                    var token   = state.Token;
                    var message = state.Message.FirstOrDefault();
                    var content = state.Content;

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

                    // reply user message.
                    if (message != null)
                    {
                        await service.ReplyToMessageAsync(message.Id, content);
                    }

                    var nameListString = DisplayHelper.ToDisplayRecipientsString_Summay(message?.ToRecipients);

                    var emailCard = new EmailCardData
                    {
                        Subject      = string.Format(EmailCommonStrings.ForwardReplyFormat, message?.Subject),
                        NameList     = string.Format(EmailCommonStrings.ToFormat, nameListString),
                        EmailContent = string.Format(EmailCommonStrings.ContentFormat, state.Content),
                    };
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(EmailSharedResponses.SentSuccessfully, "Dialogs/Shared/Resources/Cards/EmailWithOutButtonCard.json", emailCard);

                    await sc.Context.SendActivityAsync(replyMessage);
                }
                else
                {
                    await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(EmailSharedResponses.CancellingMessage));
                }
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

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

            await ClearConversationState(sc);

            return(await sc.EndDialogAsync(true));
        }
Example #4
0
        protected async Task ShowMailList(WaterfallStepContext sc, List <Message> messages)
        {
            var state = await EmailStateAccessor.GetAsync(sc.Context);

            var cardsData = new List <EmailCardData>();

            foreach (var message in messages)
            {
                var nameListString = $"To: {message.ToRecipients.FirstOrDefault()?.EmailAddress.Name}";
                if (message.ToRecipients != null && message.ToRecipients.Count() > 1)
                {
                    nameListString += $" + {message.ToRecipients.Count() - 1} more";
                }

                var emailCard = new EmailCardData
                {
                    Subject          = message.Subject,
                    Sender           = message.Sender.EmailAddress.Name,
                    NameList         = nameListString,
                    EmailContent     = message.BodyPreview,
                    EmailLink        = message.WebLink,
                    ReceivedDateTime = message.ReceivedDateTime == null
                    ? "Not available"
                    : message.ReceivedDateTime.Value.UtcDateTime.ToRelativeString(state.GetUserTimeZone()),
                    Speak = message?.Subject + " From " + message.Sender.EmailAddress.Name,
                };
                cardsData.Add(emailCard);
            }

            var searchType = "relevant";

            if (state.IsUnreadOnly)
            {
                searchType += " unread";
            }
            else if (state.IsImportant)
            {
                searchType += " important";
            }

            var reply = sc.Context.Activity.CreateAdaptiveCardGroupReply(EmailSharedResponses.ShowEmailPrompt, "Dialogs/Shared/Resources/Cards/EmailCard.json", AttachmentLayoutTypes.Carousel, cardsData, ResponseBuilder, new StringDictionary {
                { "SearchType", searchType }
            });
            await sc.Context.SendActivityAsync(reply);
        }
Example #5
0
        protected async Task ShowMailList(WaterfallStepContext sc, List <Message> messages)
        {
            var state = await EmailStateAccessor.GetAsync(sc.Context);

            var cardsData = new List <EmailCardData>();

            foreach (var message in messages)
            {
                var nameListString = DisplayHelper.ToDisplayRecipientsString_Summay(message.ToRecipients);

                var emailCard = new EmailCardData
                {
                    Subject          = message.Subject,
                    Sender           = message.Sender.EmailAddress.Name,
                    NameList         = string.Format(CommonStrings.ToFormat, nameListString),
                    EmailContent     = message.BodyPreview,
                    EmailLink        = message.WebLink,
                    ReceivedDateTime = message.ReceivedDateTime == null
                    ? CommonStrings.NotAvailable
                    : message.ReceivedDateTime.Value.UtcDateTime.ToRelativeString(state.GetUserTimeZone()),
                    Speak = SpeakHelper.ToSpeechEmailDetailString(message),
                };
                cardsData.Add(emailCard);
            }

            var searchType = CommonStrings.Relevant;

            if (state.IsUnreadOnly)
            {
                searchType = string.Format(CommonStrings.RelevantFormat, CommonStrings.Unread);
            }
            else if (state.IsImportant)
            {
                searchType = string.Format(CommonStrings.RelevantFormat, CommonStrings.Important);
            }

            var stringToken = new StringDictionary
            {
                { "SearchType", searchType },
                { "EmailListDetails", SpeakHelper.ToSpeechEmailListString(messages) },
            };

            var reply = sc.Context.Activity.CreateAdaptiveCardGroupReply(EmailSharedResponses.ShowEmailPrompt, "Dialogs/Shared/Resources/Cards/EmailCard.json", AttachmentLayoutTypes.Carousel, cardsData, ResponseBuilder, stringToken);
            await sc.Context.SendActivityAsync(reply);
        }
Example #6
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));
            }
        }
Example #7
0
        public async Task <DialogTurnResult> SendEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var confirmResult = (bool)sc.Result;
                if (confirmResult)
                {
                    var state = await EmailStateAccessor.GetAsync(sc.Context);

                    var token = state.MsGraphToken;

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

                    // send user message.
                    await service.SendMessageAsync(state.Content, state.Subject, state.Recipients);

                    var nameListString = DisplayHelper.ToDisplayRecipientsString_Summay(state.Recipients);

                    var emailCard = new EmailCardData
                    {
                        Subject      = string.Format(CommonStrings.SubjectFormat, state.Subject),
                        NameList     = string.Format(CommonStrings.ToFormat, nameListString),
                        EmailContent = string.Format(CommonStrings.ContentFormat, state.Content),
                    };
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(EmailSharedResponses.SentSuccessfully, "Dialogs/Shared/Resources/Cards/EmailWithOutButtonCard.json", emailCard);

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

            await ClearConversationState(sc);

            return(await sc.EndDialogAsync(true));
        }
Example #8
0
        public async Task <DialogTurnResult> ReadEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
                var userInput = content != null?content.ToString() : sc.Context.Activity.Text;

                var luisResult        = state.LuisResult;
                var topIntent         = luisResult?.TopIntent().intent;
                var generalLuisResult = state.GeneralLuisResult;
                var generalTopIntent  = generalLuisResult?.TopIntent().intent;

                if (topIntent == null)
                {
                    return(await sc.EndDialogAsync(true));
                }

                var message = state.Message.FirstOrDefault();

                var promptRecognizerResult = ConfirmRecognizerHelper.ConfirmYesOrNo(userInput, sc.Context.Activity.Locale);
                if (promptRecognizerResult.Succeeded && promptRecognizerResult.Value == false)
                {
                    await sc.Context.SendActivityAsync(
                        sc.Context.Activity.CreateReply(EmailSharedResponses.CancellingMessage));

                    return(await sc.EndDialogAsync(true));
                }
                else if (topIntent == Email.Intent.ReadAloud && message == null)
                {
                    return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(ShowEmailResponses.ReadOutPrompt), }));
                }
                else if (topIntent == Email.Intent.SelectItem || (topIntent == Email.Intent.ReadAloud && message != null))
                {
                    var nameListString = DisplayHelper.ToDisplayRecipientsString_Summay(message.ToRecipients);

                    var emailCard = new EmailCardData
                    {
                        Subject          = message.Subject,
                        Sender           = message.Sender.EmailAddress.Name,
                        NameList         = string.Format(CommonStrings.ToFormat, nameListString),
                        EmailContent     = message.BodyPreview,
                        EmailLink        = message.WebLink,
                        ReceivedDateTime = message?.ReceivedDateTime == null
                            ? CommonStrings.NotAvailable
                            : message.ReceivedDateTime.Value.UtcDateTime.ToRelativeString(state.GetUserTimeZone()),
                        Speak = SpeakHelper.ToSpeechEmailDetailString(message),
                    };

                    // Todo: workaround here to read out email details. Ignore body for now as we need a summary and filter.
                    var emailDetails = SpeakHelper.ToSpeechEmailDetailString(message);
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(ShowEmailResponses.ReadOutMessage, "Dialogs/Shared/Resources/Cards/EmailDetailCard.json", emailCard, null, new StringDictionary()
                    {
                        { "EmailDetails", emailDetails }
                    });
                    await sc.Context.SendActivityAsync(replyMessage);

                    return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(ShowEmailResponses.ReadOutMorePrompt) }));
                }
                else
                {
                    return(await sc.NextAsync());
                }
            }
            catch (Exception ex)
            {
                throw await HandleDialogExceptions(sc, ex);
            }
        }
Example #9
0
        public async Task <DialogTurnResult> ReadEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await _emailStateAccessor.GetAsync(sc.Context);

                sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
                var userInput = content != null?content.ToString() : sc.Context.Activity.Text;

                var luisResult        = state.LuisResult;
                var topIntent         = luisResult?.TopIntent().intent;
                var generalLuisResult = state.GeneralLuisResult;
                var generalTopIntent  = generalLuisResult?.TopIntent().intent;

                if (topIntent == null)
                {
                    return(await sc.EndDialogAsync(true));
                }

                var message = state.Message.FirstOrDefault();

                var promptRecognizerResult = ConfirmRecognizerHelper.ConfirmYesOrNo(userInput, sc.Context.Activity.Locale);
                if (promptRecognizerResult.Succeeded && promptRecognizerResult.Value == false)
                {
                    await sc.Context.SendActivityAsync(
                        sc.Context.Activity.CreateReply(EmailSharedResponses.CancellingMessage));

                    return(await sc.EndDialogAsync(true));
                }
                else if (topIntent == Email.Intent.ReadAloud && message == null)
                {
                    return(await sc.PromptAsync(Action.Prompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(ShowEmailResponses.ReadOutPrompt), }));
                }
                else if (topIntent == Email.Intent.SelectItem || (topIntent == Email.Intent.ReadAloud && message != null))
                {
                    var nameListString = $"To: {message?.ToRecipients.FirstOrDefault()?.EmailAddress.Name}";
                    if (message?.ToRecipients.Count() > 1)
                    {
                        nameListString += $" + {message.ToRecipients.Count() - 1} more";
                    }

                    var emailCard = new EmailCardData
                    {
                        Subject          = message?.Subject,
                        Sender           = message?.Sender.EmailAddress.Name,
                        NameList         = nameListString,
                        EmailContent     = message?.BodyPreview,
                        EmailLink        = message?.WebLink,
                        ReceivedDateTime = message?.ReceivedDateTime == null
                            ? "Not available"
                            : message.ReceivedDateTime.Value.UtcDateTime.ToRelativeString(state.GetUserTimeZone()),
                        Speak = message?.Subject + " From " + message?.Sender.EmailAddress.Name + " " + message?.BodyPreview,
                    };
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(ShowEmailResponses.ReadOutMessage, "Dialogs/Shared/Resources/Cards/EmailDetailCard.json", emailCard);
                    await sc.Context.SendActivityAsync(replyMessage);

                    return(await sc.PromptAsync(Action.Prompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(ShowEmailResponses.ReadOutMorePrompt) }));
                }
                else
                {
                    return(await sc.NextAsync());
                }
            }
            catch (Exception ex)
            {
                throw await HandleDialogExceptions(sc, ex);
            }
        }