Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

[Email] Fix as designer's suggestion #2512

Merged
merged 3 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions skills/csharp/emailskill/Dialogs/EmailSkillDialogBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,21 @@ protected override Task<DialogTurnResult> EndComponentAsync(DialogContext outerD
try
{
var state = await EmailStateAccessor.GetAsync(sc.Context);

// End when there is no message.
if (state.MessageList.Count == 0)
{
return await sc.EndDialogAsync(true);
}

// Set focus when there is only one message.
if (state.MessageList.Count == 1)
{
state.Message.Add(state.MessageList[0]);

return await sc.NextAsync();
}

return await sc.PromptAsync(
Actions.Prompt,
new PromptOptions() { Prompt = ResponseManager.GetResponse(EmailSharedResponses.NoFocusMessage) });
Expand Down Expand Up @@ -490,18 +500,23 @@ protected override Task<DialogTurnResult> EndComponentAsync(DialogContext outerD
if (string.IsNullOrEmpty(state.Content))
{
var noEmailContentMessage = ResponseManager.GetResponse(EmailSharedResponses.NoEmailContent);
if (sc.ActiveDialog.Id == nameof(ForwardEmailDialog))
if (sc.ActiveDialog.Id == Actions.Forward)
{
noEmailContentMessage = ResponseManager.GetResponse(EmailSharedResponses.NoEmailContentForForward);
if (state.FindContactInfor.Contacts.Count == 0 || state.FindContactInfor.Contacts == null)
{
state.FindContactInfor.FirstRetryInFindContact = true;
return await sc.EndDialogAsync();
}

var recipientConfirmedMessage = ResponseManager.GetResponse(EmailSharedResponses.RecipientConfirmed, new StringDictionary() { { "UserName", await GetNameListStringAsync(sc) } });
var recipientConfirmedMessage = ResponseManager.GetResponse(EmailSharedResponses.RecipientConfirmed, new StringDictionary() { { "UserName", await GetNameListStringAsync(sc, false) } });
noEmailContentMessage.Text = recipientConfirmedMessage.Text + " " + noEmailContentMessage.Text;
noEmailContentMessage.Speak = recipientConfirmedMessage.Speak + " " + noEmailContentMessage.Speak;
}
else if (sc.ActiveDialog.Id == Actions.Reply)
{
noEmailContentMessage = ResponseManager.GetResponse(EmailSharedResponses.NoEmailContentForReply);
}

return await sc.PromptAsync(
Actions.Prompt,
Expand Down Expand Up @@ -762,7 +777,7 @@ protected Task<bool> AuthPromptValidator(PromptValidatorContext<TokenResponse> p
}

// Helpers
protected async Task<string> GetNameListStringAsync(WaterfallStepContext sc)
protected async Task<string> GetNameListStringAsync(WaterfallStepContext sc, bool isWithEmailDetail = true)
{
var state = await EmailStateAccessor.GetAsync(sc?.Context);
var recipients = state.FindContactInfor.Contacts;
Expand All @@ -773,15 +788,15 @@ protected async Task<string> GetNameListStringAsync(WaterfallStepContext sc)
}
else if (recipients.Count == 1)
{
return recipients.FirstOrDefault()?.EmailAddress.Name + ": " + recipients.FirstOrDefault()?.EmailAddress.Address;
return recipients.FirstOrDefault()?.EmailAddress.Name + (isWithEmailDetail ? ": " + recipients.FirstOrDefault()?.EmailAddress.Address : string.Empty);
}

var result = recipients.FirstOrDefault()?.EmailAddress.Name + ": " + recipients.FirstOrDefault()?.EmailAddress.Address;
var result = recipients.FirstOrDefault()?.EmailAddress.Name + (isWithEmailDetail ? ": " + recipients.FirstOrDefault()?.EmailAddress.Address : string.Empty);
for (var i = 1; i < recipients.Count; i++)
{
if (i == recipients.Count - 1)
{
result += string.Format(CommonStrings.SeparatorFormat, CommonStrings.And) + recipients[i].EmailAddress.Name + ": " + recipients[i].EmailAddress.Address;
result += string.Format(CommonStrings.SeparatorFormat, CommonStrings.And) + recipients[i].EmailAddress.Name + (isWithEmailDetail ? ": " + recipients[i].EmailAddress.Address : string.Empty);
}
else
{
Expand Down
46 changes: 24 additions & 22 deletions skills/csharp/emailskill/Dialogs/FindContactDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,27 +459,6 @@ public FindContactDialog(
var currentRecipientName = string.IsNullOrEmpty(userInput) ? state.FindContactInfor.CurrentContactName : userInput;
state.FindContactInfor.CurrentContactName = currentRecipientName;

// if it's an email, add to attendee and keep the state.ConfirmedPerson null
if (!string.IsNullOrEmpty(currentRecipientName) && Utilities.Util.IsEmail(currentRecipientName))
{
var attendee = new Recipient
{
EmailAddress = new EmailAddress
{
Name = currentRecipientName,
Address = currentRecipientName
}
};
if (state.FindContactInfor.Contacts.All(r => r.EmailAddress.Address != attendee.EmailAddress.Address))
{
state.FindContactInfor.Contacts.Add(attendee);
}

state.FindContactInfor.CurrentContactName = string.Empty;
state.FindContactInfor.ConfirmedContact = null;
return await sc.EndDialogAsync();
}

var unionList = new List<PersonModel>();

var originPersonList = await GetPeopleWorkWithAsync(sc, currentRecipientName);
Expand Down Expand Up @@ -545,6 +524,27 @@ public FindContactDialog(

if (unionList.Count == 0)
{
// If the query is an email address, confirm it directly
if (!string.IsNullOrEmpty(currentRecipientName) && Utilities.Util.IsEmail(currentRecipientName))
{
var attendee = new Recipient
{
EmailAddress = new EmailAddress
{
Name = currentRecipientName,
Address = currentRecipientName
}
};
if (state.FindContactInfor.Contacts.All(r => r.EmailAddress.Address != attendee.EmailAddress.Address))
{
state.FindContactInfor.Contacts.Add(attendee);
}

state.FindContactInfor.CurrentContactName = string.Empty;
state.FindContactInfor.ConfirmedContact = null;
return await sc.EndDialogAsync();
}

options.UpdateUserNameReason = FindContactDialogOptions.UpdateUserNameReasonType.NotFound;
return await sc.ReplaceDialogAsync(FindContactAction.UpdateName, options);
}
Expand Down Expand Up @@ -740,7 +740,9 @@ public FindContactDialog(
try
{
var state = await Accessor.GetAsync(sc.Context);
var nameString = state.FindContactInfor.Contacts.ToSpeechString(CommonStrings.And, li => $"{li.EmailAddress.Name ?? li.EmailAddress.Name}: {li.EmailAddress.Address}");
var nameString = state.FindContactInfor.Contacts.ToSpeechString(
CommonStrings.And,
li => !string.IsNullOrEmpty(li.EmailAddress.Name) && Util.IsEmail(li.EmailAddress.Name) ? li.EmailAddress.Name : $"{li.EmailAddress.Name ?? li.EmailAddress.Name}: {li.EmailAddress.Address}");
return await sc.PromptAsync(FindContactAction.TakeFurtherAction, new PromptOptions
{
Prompt = ResponseManager.GetResponse(FindContactResponses.AddMoreContactsPrompt, new StringDictionary() { { "NameList", nameString } }),
Expand Down
21 changes: 4 additions & 17 deletions skills/csharp/emailskill/Dialogs/SendEmailDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public SendEmailDialog(
return await sc.EndDialogAsync();
}

var recipientConfirmedMessage = ResponseManager.GetResponse(EmailSharedResponses.RecipientConfirmed, new StringDictionary() { { "UserName", await GetNameListStringAsync(sc) } });
var recipientConfirmedMessage = ResponseManager.GetResponse(EmailSharedResponses.RecipientConfirmed, new StringDictionary() { { "UserName", await GetNameListStringAsync(sc, false) } });
var noSubjectMessage = ResponseManager.GetResponse(SendEmailResponses.NoSubject);
noSubjectMessage.Text = recipientConfirmedMessage.Text + " " + noSubjectMessage.Text;
noSubjectMessage.Speak = recipientConfirmedMessage.Speak + " " + noSubjectMessage.Speak;
Expand Down Expand Up @@ -283,27 +283,14 @@ public SendEmailDialog(
{
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(GetDivergedCardName(sc.Context, "EmailContentPreview"), emailCard),
stringToken);

await sc.Context.SendActivityAsync(replyMessage);

return await sc.PromptAsync(Actions.TakeFurtherAction, new PromptOptions()
{
Prompt = ResponseManager.GetResponse(SendEmailResponses.CheckContent),
Prompt = ResponseManager.GetResponse(SendEmailResponses.PlayBackMessage, stringToken),
RetryPrompt = ResponseManager.GetResponse(SendEmailResponses.ConfirmMessageRetry),
});
}
Expand Down Expand Up @@ -440,13 +427,13 @@ public SendEmailDialog(
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(EmailSharedResponses.CancellingMessage));
await ClearConversationState(sc);
return await sc.EndDialogAsync(false, cancellationToken);
case ResendEmailState.Participants:
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.Content:
case ResendEmailState.Body:
state.ClearContent();
return await sc.ReplaceDialogAsync(Actions.Send, options: skillOptions, cancellationToken: cancellationToken);
default:
Expand Down
6 changes: 3 additions & 3 deletions skills/csharp/emailskill/Models/SendEmailStateModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public enum ResendEmailState
Cancel = 0,

/// <summary>
/// Change the Participants and recerate.
/// Change the Recipients and recerate.
/// </summary>
Participants = 1,
Recipients = 1,

/// <summary>
/// Change the subject and recerate.
Expand All @@ -20,6 +20,6 @@ public enum ResendEmailState
/// <summary>
/// Change the content and recerate.
/// </summary>
Content = 3
Body = 3
}
}
6 changes: 3 additions & 3 deletions skills/csharp/emailskill/Prompts/GetRecreateInfoPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ public GetRecreateInfoPrompt(string dialogId, PromptValidator<ResendEmailState?>
{
ResendEmailState? result = null;

if (message.ToLowerInvariant().Equals(EmailCommonStrings.Participants))
if (message.ToLowerInvariant().Equals(EmailCommonStrings.Recipients))
{
result = ResendEmailState.Participants;
result = ResendEmailState.Recipients;
}
else if (message.ToLowerInvariant().Equals(EmailCommonStrings.Subject))
{
result = ResendEmailState.Subject;
}
else if (message.ToLowerInvariant().Equals(EmailCommonStrings.Content))
{
result = ResendEmailState.Content;
result = ResendEmailState.Body;
}

return result;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
"DeleteConfirm": {
"replies": [
{
"text": "Are you sure you want to delete?",
"speak": "Are you sure you want to delete? Details of email: {EmailDetails}"
"text": "Are you sure you want to delete this email?",
"speak": "Are you sure you want to delete this email? Details of email: {EmailDetails}"
}
],
"inputHint": "expectingInput"
},
"DeleteSuccessfully": {
"replies": [
{
"text": "Your email has been successfully deleted.",
"speak": "Your email has been successfully deleted."
"text": "Your email has been deleted.",
"speak": "Your email has been deleted."
}
],
"inputHint": "acceptingInput"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"NoMessageBody": {
"replies": [
{
"text": "What content do you want to add to the email? You can say skip to bypass it.",
"speak": "What content do you want to add to the email? You can say skip to bypass it."
"text": "What would you like to say in the body of the email? Say skip if you want to keep it blank.",
"speak": "What would you like to say in the body of the email? Say skip if you want to keep it blank."
}
],
"inputHint": "expectingInput"
Expand All @@ -29,25 +29,12 @@
"PlayBackMessage": {
"replies": [
{
"text": "I will repeat the message for you to confirm:",
"speak": "I will repeat the message for you to confirm: {EmailContent}"
"text": "Okay, here's what I've got. Do you want to include it in the email? \n {EmailContent}",
"speak": "Okay, here's what I've got. Do you want to include it in the email? {EmailContent}"
}
],
"inputHint": "expectingInput"
},
"CheckContent": {
"replies": [
{
"text": "Do you want to include this in the email?",
"speak": "Do you want to include this in the email?"
}
],
"suggestedActions": [
"Yes",
"No"
],
"inputHint": "expectingInput"
},
"RetryContent": {
"replies": [
{
Expand All @@ -60,22 +47,22 @@
"GetRecreateInfo": {
"replies": [
{
"text": "Would you like to change the Participants, Subject or the Content?",
"speak": "Would you like to change the Participants, Subject or the Content?"
"text": "Would you like to change the Recipients, Subject or the Body?",
"speak": "Would you like to change the Recipients, Subject or the Body?"
}
],
"suggestedActions": [
"Participants",
"Recipients",
"Subject",
"Content"
"Body"
],
"inputHint": "expectingInput"
},
"GetRecreateInfoRetry": {
"replies": [
{
"text": "You can try Participants, Subject, or Content. Or say cancel.",
"speak": "You can try Participants, Subject, or Content. Or say cancel."
"text": "You can try Recipients, Subject, or Body. Or say cancel.",
"speak": "You can try Recipients, Subject, or Body. Or say cancel."
}
],
"inputHint": "expectingInput"
Expand Down
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading