Exemplo n.º 1
0
        protected override async Task <DialogTurnResult> OnBeginDialogAsync(DialogContext dc, object options, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await EmailStateAccessor.GetAsync(dc.Context);

            await DigestEmailLuisResult(dc, state.LuisResult);

            return(await base.OnBeginDialogAsync(dc, options, cancellationToken));
        }
        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 service = ServiceManager.InitMailService(token, state.GetUserTimeZone(), state.MailSourceType);

                    // reply user message.
                    if (message != null)
                    {
                        var content = state.Content.Equals(EmailCommonStrings.EmptyContent) ? string.Empty : state.Content;
                        await service.ReplyToMessageAsync(message.Id, content);
                    }

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

                    var emailCard = new EmailCardData
                    {
                        Subject      = state.Subject.Equals(EmailCommonStrings.EmptySubject) ? null : string.Format(EmailCommonStrings.SubjectFormat, state.Subject),
                        NameList     = string.Format(EmailCommonStrings.ToFormat, nameListString),
                        EmailContent = state.Content.Equals(EmailCommonStrings.EmptyContent) ? null : string.Format(EmailCommonStrings.ContentFormat, state.Content),
                    };

                    var stringToken = new StringDictionary
                    {
                        { "Subject", state.Subject },
                    };

                    var reply = ResponseManager.GetCardResponse(
                        EmailSharedResponses.SentSuccessfully,
                        new Card("EmailWithOutButtonCard", emailCard),
                        stringToken);

                    await sc.Context.SendActivityAsync(reply);
                }
                else
                {
                    await sc.Context.SendActivityAsync(ResponseManager.GetResponse(EmailSharedResponses.CancellingMessage));
                }
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

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

            await ClearConversationState(sc);

            return(await sc.EndDialogAsync(true));
        }
Exemplo n.º 3
0
        public async Task <DialogTurnResult> ForwardEmail(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;
                    var id         = message.FirstOrDefault()?.Id;
                    var recipients = state.Recipients;

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

                    // send user message.
                    var content = state.Content.Equals(EmailCommonStrings.EmptyContent) ? string.Empty : state.Content;
                    await service.ForwardMessageAsync(id, content, recipients);

                    var emailCard = new EmailCardData
                    {
                        Subject      = state.Subject.Equals(EmailCommonStrings.EmptySubject) ? null : state.Subject,
                        EmailContent = state.Content.Equals(EmailCommonStrings.EmptyContent) ? null : state.Content,
                    };
                    emailCard = await ProcessRecipientPhotoUrl(sc.Context, emailCard, state.Recipients);

                    var stringToken = new StringDictionary
                    {
                        { "Subject", state.Subject },
                    };

                    var recipientCard = state.Recipients.Count() > 5 ? "ConfirmCard_RecipientMoreThanFive" : "ConfirmCard_RecipientLessThanFive";
                    var reply         = ResponseManager.GetCardResponse(
                        EmailSharedResponses.SentSuccessfully,
                        new Card("EmailWithOutButtonCard", emailCard),
                        stringToken,
                        "items",
                        new List <Card>().Append(new Card(recipientCard, emailCard)));

                    await sc.Context.SendActivityAsync(reply);
                }
                else
                {
                    await sc.Context.SendActivityAsync(ResponseManager.GetResponse(EmailSharedResponses.CancellingMessage));
                }
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

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

            await ClearConversationState(sc);

            return(await sc.EndDialogAsync(true));
        }
        private async Task <DialogTurnResult> CollectDescription(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await EmailStateAccessor.GetAsync(sc.Context);

            state._server = (string)sc.Result;


            return(await sc.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("Can you describe your problem briefly?") }, cancellationToken));
        }
        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 message = state.Message?.FirstOrDefault();
                if (message != null)
                {
                    var nameListString = DisplayHelper.ToDisplayRecipientsString_Summay(message.ToRecipients);
                    var senderIcon     = await GetUserPhotoUrlAsync(sc.Context, message.Sender.EmailAddress);

                    var emailCard = new EmailCardData
                    {
                        Subject          = message.Subject,
                        EmailContent     = message.BodyPreview,
                        Sender           = message.Sender.EmailAddress.Name,
                        EmailLink        = message.WebLink,
                        ReceivedDateTime = message?.ReceivedDateTime == null
                            ? CommonStrings.NotAvailable
                            : message.ReceivedDateTime.Value.UtcDateTime.ToDetailRelativeString(state.GetUserTimeZone()),
                        Speak      = SpeakHelper.ToSpeechEmailDetailOverallString(message, state.GetUserTimeZone()),
                        SenderIcon = senderIcon
                    };
                    emailCard = await ProcessRecipientPhotoUrl(sc.Context, emailCard, message.ToRecipients);

                    var speech = SpeakHelper.ToSpeechEmailSendDetailString(message.Subject, nameListString, message.BodyPreview);
                    var tokens = new StringDictionary
                    {
                        { "EmailDetails", speech },
                    };

                    var recipientCard = message.ToRecipients.Count() > 5 ? GetDivergedCardName(sc.Context, "DetailCard_RecipientMoreThanFive") : GetDivergedCardName(sc.Context, "DetailCard_RecipientLessThanFive");
                    var prompt        = ResponseManager.GetCardResponse(
                        DeleteEmailResponses.DeleteConfirm,
                        new Card("EmailDetailCard", emailCard),
                        tokens,
                        "items",
                        new List <Card>().Append(new Card(recipientCard, emailCard)));

                    var retry = ResponseManager.GetResponse(EmailSharedResponses.ConfirmSendFailed);

                    return(await sc.PromptAsync(Actions.TakeFurtherAction, new PromptOptions { Prompt = prompt, RetryPrompt = retry }));
                }

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

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 6
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);
            }
        }
        public async Task <DialogTurnResult> SendEmailAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

                sc.Context.TurnState.TryGetValue(StateProperties.APIToken, out var token);

                var service = ServiceManager.InitMailService(token as string, 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 emailCard = new EmailCardData
                {
                    Subject      = state.Subject.Equals(EmailCommonStrings.EmptySubject) ? null : string.Format(EmailCommonStrings.SubjectFormat, state.Subject),
                    EmailContent = state.Content.Equals(EmailCommonStrings.EmptyContent) ? null : string.Format(EmailCommonStrings.ContentFormat, state.Content),
                };
                emailCard = await ProcessRecipientPhotoUrlAsync(sc.Context, emailCard, state.FindContactInfor.Contacts, cancellationToken);

                var replyMessage = TemplateManager.GenerateActivityForLocale(
                    EmailSharedResponses.SentSuccessfully,
                    new
                {
                    subject      = state.Subject,
                    emailDetails = emailCard
                });

                await sc.Context.SendActivityAsync(replyMessage, cancellationToken);

                if (state.IsAction)
                {
                    var actionResult = new ActionResult(true);
                    await ClearConversationStateAsync(sc, cancellationToken);

                    return(await sc.EndDialogAsync(actionResult, cancellationToken));
                }

                await ClearConversationStateAsync(sc, cancellationToken);

                return(await sc.EndDialogAsync(true, cancellationToken));
            }
            catch (SkillException ex)
            {
                await HandleDialogExceptionsAsync(sc, ex, cancellationToken);

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

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 8
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.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.Recipients);

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

                    var emailCard = new EmailCardData
                    {
                        Subject      = state.Subject.Equals(EmailCommonStrings.EmptySubject) ? null : string.Format(EmailCommonStrings.SubjectFormat, state.Subject),
                        NameList     = string.Format(EmailCommonStrings.ToFormat, nameListString),
                        EmailContent = state.Content.Equals(EmailCommonStrings.EmptyContent) ? null : string.Format(EmailCommonStrings.ContentFormat, state.Content),
                    };

                    var stringToken = new StringDictionary
                    {
                        { "Subject", state.Subject },
                    };
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(EmailSharedResponses.SentSuccessfully, "Dialogs/Shared/Resources/Cards/EmailWithOutButtonCard.json", emailCard, tokens: stringToken);
                    await sc.Context.SendActivityAsync(replyMessage);
                }
                else
                {
                    return(await sc.ReplaceDialogAsync(Actions.GetRecreateInfo, options : sc.Options, cancellationToken : cancellationToken));
                }
            }
            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));
        }
Exemplo n.º 9
0
        public async Task <DialogTurnResult> PlayBackContent(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 content);
                    var contentInput = content != null?content.ToString() : sc.Context.Activity.Text;

                    if (!EmailCommonPhrase.GetIsSkip(contentInput))
                    {
                        state.Content = contentInput;

                        var emailCard = new EmailCardData
                        {
                            Subject      = EmailCommonStrings.MessageConfirm,
                            EmailContent = state.Content,
                        };

                        var stringToken = new StringDictionary
                        {
                            { "EmailContent", state.Content },
                        };

                        var replyMessage = ResponseManager.GetCardResponse(
                            SendEmailResponses.PlayBackMessage,
                            new Card("EmailContentPreview", emailCard),
                            stringToken);

                        await sc.Context.SendActivityAsync(replyMessage);

                        return(await sc.PromptAsync(Actions.TakeFurtherAction, new PromptOptions()
                        {
                            Prompt = ResponseManager.GetResponse(SendEmailResponses.CheckContent),
                            RetryPrompt = ResponseManager.GetResponse(SendEmailResponses.ConfirmMessageRetry),
                        }));
                    }
                    else
                    {
                        state.Content = EmailCommonStrings.EmptyContent;
                        return(await sc.EndDialogAsync(cancellationToken));
                    }
                }

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

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 10
0
        protected async Task <DialogTurnResult> HandleMore(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                var luisResult = state.LuisResult;

                var topIntent = luisResult?.TopIntent().intent;
                if (topIntent == null)
                {
                    return(await sc.EndDialogAsync(true));
                }

                await DigestFocusEmailAsync(sc);

                var skillOptions = (EmailSkillDialogOptions)sc.Options;
                skillOptions.SubFlowMode = true;

                if (topIntent == Email.Intent.Delete)
                {
                    return(await sc.BeginDialogAsync(Actions.Delete, skillOptions));
                }
                else if (topIntent == Email.Intent.Forward)
                {
                    return(await sc.BeginDialogAsync(Actions.Forward, skillOptions));
                }
                else if (topIntent == Email.Intent.Reply)
                {
                    return(await sc.BeginDialogAsync(Actions.Reply, skillOptions));
                }
                else if (topIntent == Email.Intent.ReadAloud || topIntent == Email.Intent.SelectItem)
                {
                    var message = state.Message.FirstOrDefault();

                    if (message == null)
                    {
                        return(await sc.BeginDialogAsync(Actions.Reshow, skillOptions));
                    }
                    else
                    {
                        return(await sc.BeginDialogAsync(Actions.Read, skillOptions));
                    }
                }
                else
                {
                    // return a signal for main flow need to start a new ComponentDialog.
                    return(await sc.EndDialogAsync(true));
                }
            }
            catch (Exception ex)
            {
                throw await HandleDialogExceptions(sc, ex);
            }
        }
Exemplo n.º 11
0
        protected async Task <DialogTurnResult> AfterGetAuthToken(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                // When the user authenticates interactively we pass on the tokens/Response event which surfaces as a JObject
                // When the token is cached we get a TokenResponse object.
                var skillOptions = (EmailSkillDialogOptions)sc.Options;
                ProviderTokenResponse providerTokenResponse;
                if (skillOptions != null && skillOptions.SkillMode)
                {
                    var resultType = sc.Context.Activity.Value.GetType();
                    if (resultType == typeof(ProviderTokenResponse))
                    {
                        providerTokenResponse = sc.Context.Activity.Value as ProviderTokenResponse;
                    }
                    else
                    {
                        var tokenResponseObject = sc.Context.Activity.Value as JObject;
                        providerTokenResponse = tokenResponseObject?.ToObject <ProviderTokenResponse>();
                    }
                }
                else
                {
                    providerTokenResponse = sc.Result as ProviderTokenResponse;
                }

                if (providerTokenResponse != null)
                {
                    var state = await EmailStateAccessor.GetAsync(sc.Context);

                    state.Token = providerTokenResponse.TokenResponse.Token;

                    var provider = providerTokenResponse.AuthenticationProvider;

                    if (provider == OAuthProvider.AzureAD)
                    {
                        state.MailSourceType = MailSource.Microsoft;
                    }
                    else if (provider == OAuthProvider.Google)
                    {
                        state.MailSourceType = MailSource.Google;
                    }
                    else
                    {
                        throw new Exception($"The authentication provider \"{provider.ToString()}\" is not support by the Email Skill.");
                    }
                }

                return(await sc.NextAsync());
            }
            catch (Exception ex)
            {
                throw await HandleDialogExceptions(sc, ex);
            }
        }
        public async Task <DialogTurnResult> AfterGetRecreateInfo(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

                var skillOptions = (EmailSkillDialogOptions)sc.Options;
                skillOptions.SubFlowMode = true;
                if (sc.Result != null)
                {
                    var recreateState = sc.Result as ResendEmailState?;
                    switch (recreateState.Value)
                    {
                    case ResendEmailState.Cancel:
                        var activity = TemplateEngine.GenerateActivityForLocale(EmailSharedResponses.CancellingMessage);
                        await sc.Context.SendActivityAsync(activity);
                        await ClearConversationState(sc);

                        return(await sc.EndDialogAsync(false, cancellationToken));

                    case ResendEmailState.Recipients:
                        state.ClearParticipants();
                        return(await sc.ReplaceDialogAsync(Actions.Send, options : skillOptions, cancellationToken : cancellationToken));

                    case ResendEmailState.Subject:
                        state.ClearSubject();
                        return(await sc.ReplaceDialogAsync(Actions.Send, options : skillOptions, cancellationToken : cancellationToken));

                    case ResendEmailState.Body:
                        state.ClearContent();
                        return(await sc.ReplaceDialogAsync(Actions.Send, options : skillOptions, cancellationToken : cancellationToken));

                    default:
                        // should not go to this part. place an error handling for save.
                        await HandleDialogExceptions(sc, new Exception("Get unexpect state in recreate."));

                        return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
                    }
                }
                else
                {
                    // should not go to this part. place an error handling for save.
                    await HandleDialogExceptions(sc, new Exception("Get unexpect result in recreate."));

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

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 13
0
        protected async Task DigestFocusEmailAsync(WaterfallStepContext sc)
        {
            var state = await EmailStateAccessor.GetAsync(sc.Context);

            // Get focus message if any
            if (state.MessageList != null && state.UserSelectIndex >= 0 && state.UserSelectIndex < state.MessageList.Count())
            {
                state.Message.Clear();
                state.Message.Add(state.MessageList[state.UserSelectIndex]);
            }
        }
Exemplo n.º 14
0
        private async Task <DialogTurnResult> CollectServer(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await EmailStateAccessor.GetAsync(sc.Context);



            state._platform = (string)sc.Result;


            return(await sc.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("How about the server / database?") }, cancellationToken));
        }
Exemplo n.º 15
0
        protected async Task <DialogTurnResult> ShowFilteredEmails(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                if (state.MessageList.Count > 0)
                {
                    if (state.Message.Count == 0)
                    {
                        state.Message.Add(state.MessageList[0]);

                        if (state.MessageList.Count > 1)
                        {
                            await ShowMailList(sc, state.MessageList, state.MessageList.Count(), cancellationToken);

                            return(await sc.NextAsync());
                        }
                        else if (state.MessageList.Count == 1)
                        {
                            return(await sc.ReplaceDialogAsync(Actions.Read, options : sc.Options));
                        }
                    }
                    else
                    {
                        return(await sc.ReplaceDialogAsync(Actions.Read, options : sc.Options));
                    }

                    await sc.Context.SendActivityAsync(ResponseManager.GetResponse(EmailSharedResponses.DidntUnderstandMessage));

                    return(await sc.EndDialogAsync(true));
                }
                else
                {
                    await sc.Context.SendActivityAsync(ResponseManager.GetResponse(EmailSharedResponses.EmailNotFound));
                }

                return(await sc.EndDialogAsync(true));
            }
            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));
            }
        }
Exemplo n.º 16
0
        protected async Task <DialogTurnResult> CollectSelectedEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                return(await sc.BeginDialogAsync(Actions.UpdateSelectMessage));
            }
            catch (Exception ex)
            {
                throw await HandleDialogExceptions(sc, ex);
            }
        }
        public async Task <DialogTurnResult> ReplyEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                sc.Context.TurnState.TryGetValue(StateProperties.APIToken, out var token);
                var message = state.Message.FirstOrDefault();

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

                // reply user message.
                if (message != null)
                {
                    var content = state.Content.Equals(EmailCommonStrings.EmptyContent) ? string.Empty : state.Content;
                    await service.ReplyToMessageAsync(message.Id, content);
                }

                var emailCard = new EmailCardData
                {
                    Subject      = state.Subject.Equals(EmailCommonStrings.EmptySubject) ? null : state.Subject,
                    EmailContent = state.Content.Equals(EmailCommonStrings.EmptyContent) ? null : state.Content,
                };
                emailCard = await ProcessRecipientPhotoUrl(sc.Context, emailCard, state.FindContactInfor.Contacts);

                var stringToken = new StringDictionary
                {
                    { "Subject", state.Subject },
                };

                var reply = TemplateEngine.GenerateActivityForLocale(
                    EmailSharedResponses.SentSuccessfully,
                    new
                {
                    subject      = state.Subject,
                    emailDetails = emailCard
                });

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

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

            await ClearConversationState(sc);

            return(await sc.EndDialogAsync(true));
        }
Exemplo n.º 18
0
        public async Task <DialogTurnResult> PromptToDeleteAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

                var skillOptions = (EmailSkillDialogOptions)sc.Options;

                var message = state.Message?.FirstOrDefault();
                if (message != null)
                {
                    var nameListString = DisplayHelper.ToDisplayRecipientsString_Summay(message.ToRecipients);
                    var senderIcon     = await GetUserPhotoUrlAsync(sc.Context, message.Sender.EmailAddress, cancellationToken);

                    var emailCard = new EmailCardData
                    {
                        Subject          = message.Subject,
                        EmailContent     = message.BodyPreview,
                        Sender           = message.Sender.EmailAddress.Name,
                        EmailLink        = message.WebLink,
                        ReceivedDateTime = message?.ReceivedDateTime == null
                            ? CommonStrings.NotAvailable
                            : message.ReceivedDateTime.Value.UtcDateTime.ToDetailRelativeString(state.GetUserTimeZone()),
                        Speak      = SpeakHelper.ToSpeechEmailDetailOverallString(message, state.GetUserTimeZone()),
                        SenderIcon = senderIcon
                    };
                    emailCard = await ProcessRecipientPhotoUrlAsync(sc.Context, emailCard, message.ToRecipients, cancellationToken);

                    var speech = SpeakHelper.ToSpeechEmailSendDetailString(message.Subject, nameListString, message.BodyPreview);
                    var prompt = TemplateManager.GenerateActivityForLocale(
                        DeleteEmailResponses.DeleteConfirm,
                        new
                    {
                        emailInfo    = speech,
                        emailDetails = emailCard
                    });

                    var retry = TemplateManager.GenerateActivityForLocale(EmailSharedResponses.ConfirmSendFailed);
                    return(await sc.PromptAsync(Actions.TakeFurtherAction, new PromptOptions { Prompt = prompt as Activity, RetryPrompt = retry as Activity }));
                }

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

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 19
0
        protected async Task <DialogTurnResult> DisplayAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

                var options = sc.Options as EmailSkillDialogOptions;
                if (state.IsAction)
                {
                    sc.Context.TurnState.TryGetValue(StateProperties.APIToken, out var token);
                    var serivce = ServiceManager.InitMailService(token as string, state.GetUserTimeZone(), state.MailSourceType);

                    var    isUnreadOnly  = state.IsUnreadOnly;
                    var    isImportant   = state.IsImportant;
                    var    startDateTime = state.StartDateTime;
                    var    endDateTime   = state.EndDateTime;
                    var    directlyToMe  = state.DirectlyToMe;
                    string mailAddress   = null;

                    // Get user message.
                    var emailResult = await serivce.GetMyMessagesAsync(startDateTime, endDateTime, isUnreadOnly, isImportant, directlyToMe, mailAddress);

                    var actionResult = new SummaryResult();
                    actionResult.EmailList = new List <EmailInfo>();
                    foreach (var email in emailResult)
                    {
                        var emailInfo = new EmailInfo()
                        {
                            Subject  = email.Subject,
                            Content  = email.Body.Content,
                            Sender   = email.Sender.EmailAddress.Address,
                            Reciever = email.ToRecipients.Select(li => li.EmailAddress.Address).ToList()
                        };

                        actionResult.EmailList.Add(emailInfo);
                    }

                    actionResult.ActionSuccess = true;

                    return(await sc.EndDialogAsync(actionResult, cancellationToken));
                }

                return(await sc.ReplaceDialogAsync(Actions.Display, options, cancellationToken));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptionsAsync(sc, ex, cancellationToken);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 20
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));
        }
Exemplo n.º 21
0
        private async Task <string> GetReadyToSendNameListStringAsync(WaterfallStepContext sc)
        {
            var state = await EmailStateAccessor.GetAsync(sc?.Context);

            var unionList = state.NameList.Concat(state.EmailList).ToList();

            if (unionList.Count == 1)
            {
                return(unionList.First());
            }

            var nameString = string.Join(", ", unionList.ToArray().SkipLast(1)) + string.Format(CommonStrings.SeparatorFormat, CommonStrings.And) + unionList.Last();

            return(nameString);
        }
Exemplo n.º 22
0
        public async Task <DialogTurnResult> UpdateContent(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

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

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 23
0
        protected async Task <DialogTurnResult> RetryInput(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

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

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 24
0
        protected async Task <bool> ChoiceValidator(PromptValidatorContext <FoundChoice> pc, CancellationToken cancellationToken)
        {
            var state = await EmailStateAccessor.GetAsync(pc.Context);

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

            // If user want to show more recipient end current choice dialog and return the intent to next step.
            if (generalTopIntent == General.Intent.Next || generalTopIntent == General.Intent.Previous)
            {
                // TODO: The signature of validators has been changed per the sdk team, meaning this logic will need to be executed in a different way
                if (pc.Options.Choices.Count > 5)
                {
                    // prompt.End(UpdateUserDialogOptions.UpdateReason.TooMany);
                    pc.Recognized.Succeeded = true;
                    pc.Recognized.Value     = new FoundChoice()
                    {
                        Value = UpdateUserDialogOptions.UpdateReason.TooMany.ToString()
                    };
                }
                else
                {
                    // prompt.End(topIntent);
                    pc.Recognized.Succeeded = true;
                    pc.Recognized.Value     = new FoundChoice()
                    {
                        Value = topIntent.ToString()
                    };
                }

                return(true);
            }
            else
            {
                if (!pc.Recognized.Succeeded || pc.Recognized == null)
                {
                    // do nothing when not recognized.
                    return(false);
                }
                else
                {
                    // prompt.End(prompt.Recognized.Value);
                    return(true);
                }
            }
        }
Exemplo n.º 25
0
        public async Task <DialogTurnResult> ForwardEmail(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;
                    var id         = message.FirstOrDefault()?.Id;
                    var content    = state.Content;
                    var recipients = state.Recipients;

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

                    // send user message.
                    await service.ForwardMessageAsync(id, content, recipients);

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

                    var emailCard = new EmailCardData
                    {
                        Subject      = string.Format(CommonStrings.SubjectFormat, string.Format(CommonStrings.ForwardReplyFormat, message.FirstOrDefault()?.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);
                }
                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));
        }
Exemplo n.º 26
0
        protected async Task <DialogTurnResult> PromptToHandle(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context);

                var activity = TemplateEngine.GenerateActivityForLocale(ShowEmailResponses.ReadOut, new { messageList = state.MessageList });
                return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = activity as Activity }));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 27
0
        protected async Task <DialogTurnResult> SelectEmailPromptAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await EmailStateAccessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

                var activity = TemplateManager.GenerateActivityForLocale(ShowEmailResponses.ActionPrompt);
                return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = activity as Activity }, cancellationToken));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptionsAsync(sc, ex, cancellationToken);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
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 tokens = new StringDictionary
                    {
                        { "EmailDetails", speech },
                    };

                    var prompt = ResponseManager.GetCardResponse(
                        DeleteEmailResponses.DeleteConfirm,
                        new Card("EmailWithOutButtonCard", emailCard),
                        tokens);

                    var retry = ResponseManager.GetResponse(EmailSharedResponses.ConfirmSendFailed);

                    return(await sc.PromptAsync(Actions.TakeFurtherAction, new PromptOptions { Prompt = prompt, RetryPrompt = retry }));
                }

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

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