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

Commit

Permalink
[Email] Add config for slot filling attribute skip (#1631)
Browse files Browse the repository at this point in the history
* remove read me

* add config for slot filling

* fix ut

* remove useless code

* move default value to resource

* add doc support
  • Loading branch information
DingmaomaoBJTU authored Jun 26, 2019
1 parent e7f4666 commit 5717335
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 91 deletions.
2 changes: 1 addition & 1 deletion docs/reference/skills/productivity-email.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ If you plan to use the skill as part of a Virtual Assistant the process of regis
- `People.Read`
- `Contacts.Read`

**However**, if you wish to use the Skill directly without using a Virtual Assistant please use the following steps to manually configure Authentication for the Calendar Skill. This is **not** required when using the Skill with a Virtual Assistant.
**However**, if you wish to use the Skill directly without using a Virtual Assistant please use the following steps to manually configure Authentication for the Email Skill. This is **not** required when using the Skill with a Virtual Assistant.

Follow the general instructions [here](/docs/reference/skills/manualauthsteps.md) to configure this using the scopes shown above.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,14 @@ protected override Task<DialogTurnResult> EndComponentAsync(DialogContext outerD
if (skillLuisResult == emailLuis.Intent.ShowNext || generalTopIntent == General.Intent.ShowNext)
{
state.ShowEmailIndex++;
state.ReadEmailIndex = 0;
}
else if ((skillLuisResult == emailLuis.Intent.ShowPrevious || generalTopIntent == General.Intent.ShowPrevious) && state.ShowEmailIndex >= 0)
{
state.ShowEmailIndex--;
state.ReadEmailIndex = 0;
}
else if (IsReadMoreIntent(generalTopIntent, sc.Context.Activity.Text))
{
if (state.MessageList.Count <= ConfigData.GetInstance().MaxReadSize)
{
state.ShowEmailIndex++;
state.ReadEmailIndex = 0;
}
else
{
state.ReadEmailIndex++;
}
state.ShowEmailIndex++;
}

await DigestFocusEmailAsync(sc);
Expand Down Expand Up @@ -645,7 +635,7 @@ protected override Task<DialogTurnResult> EndComponentAsync(DialogContext outerD

// Get display messages
var displayMessages = new List<Message>();
var startIndex = ConfigData.GetInstance().MaxReadSize * state.ReadEmailIndex;
var startIndex = 0;
for (var i = startIndex; i < messages.Count(); i++)
{
displayMessages.Add(messages[i]);
Expand Down
6 changes: 0 additions & 6 deletions skills/src/csharp/emailskill/emailskill/Dialogs/MainDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,11 @@ private async Task<InterruptionAction> OnLogout(DialogContext dc)
private void GetReadingDisplayConfig()
{
_settings.Properties.TryGetValue("displaySize", out var maxDisplaySize);
_settings.Properties.TryGetValue("readSize", out var maxReadSize);

if (maxDisplaySize != null)
{
ConfigData.GetInstance().MaxDisplaySize = int.Parse(maxDisplaySize as string);
}

if (maxReadSize != null)
{
ConfigData.GetInstance().MaxReadSize = int.Parse(maxReadSize as string);
}
}
}
}
60 changes: 18 additions & 42 deletions skills/src/csharp/emailskill/emailskill/Dialogs/SendEmailDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public SendEmailDialog(
GetAuthToken,
AfterGetAuthToken,
CollectRecipient,
ByPassOptionalField,
CollectSubject,
CollectText,
ConfirmBeforeSending,
Expand Down Expand Up @@ -85,47 +84,6 @@ public SendEmailDialog(
InitialDialogId = Actions.Send;
}

public async Task<DialogTurnResult> ByPassOptionalField(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
{
try
{
var state = await EmailStateAccessor.GetAsync(sc.Context);
var skillOptions = (EmailSkillDialogOptions)sc.Options;

if (!skillOptions.SubFlowMode)
{
if ((state.FindContactInfor.Contacts != null) && (state.FindContactInfor.Contacts.Count > 0))
{
// Bypass logic: Send an email to Michelle saying I will be late today -> Use “I will be late today” as subject. No need to ask for subject/content
// If information is detected as content, move to subject.
if (string.IsNullOrEmpty(state.Subject))
{
if (!string.IsNullOrEmpty(state.Content))
{
state.Subject = state.Content;
state.Content = EmailCommonStrings.EmptyContent;
}
}
else
{
if (string.IsNullOrEmpty(state.Content))
{
state.Content = EmailCommonStrings.EmptyContent;
}
}
}
}

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

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

public async Task<DialogTurnResult> CollectSubject(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
{
try
Expand All @@ -143,6 +101,15 @@ public SendEmailDialog(
return await sc.NextAsync();
}

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

return await sc.NextAsync();
}

var skillOptions = (EmailSkillDialogOptions)sc.Options;
skillOptions.SubFlowMode = true;
return await sc.BeginDialogAsync(Actions.UpdateSubject, skillOptions);
Expand Down Expand Up @@ -266,6 +233,15 @@ public SendEmailDialog(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public EmailSkillState()
IsImportant = false;
ShowEmailIndex = 0;
Token = null;
ReadEmailIndex = 0;
DirectlyToMe = false;
StartDateTime = DateTime.UtcNow.Add(new TimeSpan(-7, 0, 0, 0));
EndDateTime = DateTime.UtcNow;
Expand Down Expand Up @@ -79,7 +78,6 @@ public EmailSkillState()

public int ShowEmailIndex { get; set; }

public int ReadEmailIndex { get; set; }

public emailLuis LuisResult { get; set; }

Expand Down Expand Up @@ -137,7 +135,6 @@ public void Clear()
Subject = null;
SenderName = null;
LuisResultPassedFromSkill = null;
ReadEmailIndex = 0;
SearchTexts = null;
GeneralSenderName = null;
GeneralSearchTexts = null;
Expand All @@ -151,7 +148,6 @@ public void PartialClear()
Subject = null;
SenderName = null;
LuisResultPassedFromSkill = null;
ReadEmailIndex = 0;
SearchTexts = null;
GeneralSenderName = null;
GeneralSearchTexts = null;
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@
<data name="PageIndexerFormat" xml:space="preserve">
<value>**{0}-{1}** von {2}</value>
</data>
<data name="DefaultContent" xml:space="preserve">
<value />
</data>
<data name="DefaultSubject" xml:space="preserve">
<value />
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@
<data name="PageIndexerFormat" xml:space="preserve">
<value>**{0}-{1}** de {2}</value>
</data>
<data name="DefaultContent" xml:space="preserve">
<value />
</data>
<data name="DefaultSubject" xml:space="preserve">
<value />
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@
<data name="PageIndexerFormat" xml:space="preserve">
<value>**{0}-{1}** de {2}</value>
</data>
<data name="DefaultContent" xml:space="preserve">
<value />
</data>
<data name="DefaultSubject" xml:space="preserve">
<value />
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@
<data name="PageIndexerFormat" xml:space="preserve">
<value>**{0}-{1}** di {2}</value>
</data>
<data name="DefaultContent" xml:space="preserve">
<value />
</data>
<data name="DefaultSubject" xml:space="preserve">
<value />
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@
<data name="PageIndexerFormat" xml:space="preserve">
<value>**{0}-{1}** of {2}</value>
</data>
<data name="DefaultContent" xml:space="preserve">
<value />
</data>
<data name="DefaultSubject" xml:space="preserve">
<value />
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@
<data name="PageIndexerFormat" xml:space="preserve">
<value>**{0}-{1}** 于 {2}</value>
</data>
<data name="DefaultContent" xml:space="preserve">
<value />
</data>
<data name="DefaultSubject" xml:space="preserve">
<value />
</data>
</root>
16 changes: 15 additions & 1 deletion skills/src/csharp/emailskill/emailskill/Services/BotSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
using Microsoft.Bot.Builder.Solutions;
using System.Collections.Generic;
using Microsoft.Bot.Builder.Solutions;

namespace EmailSkill.Services
{
public class BotSettings : BotSettingsBase
{
public DefaultValueConfiguration DefaultValue { get; set; }

public class DefaultValueConfiguration
{
public List<SlotFillingConfigItem> SendEmail { get; set; }

public class SlotFillingConfigItem
{
public string Name { get; set; }

public bool IsSkipByDefault { get; set; }
}
}
}
}
13 changes: 12 additions & 1 deletion skills/src/csharp/emailskill/emailskill/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@
"cosmosDBEndpoint": "",
"authKey": ""
},
"defaultValue": {
"sendEmail": [
{
"name": "EmailSubject",
"isSkipByDefault": false
},
{
"name": "EmailMessage",
"isSkipByDefault": false
}
]
},
"properties": {
"googleAppName": "",
"googleClientId": "",
"googleClientSecret": "",
"googleScopes": "https://mail.google.com/ https://www.googleapis.com/auth/contacts",
"readSize": "3",
"displaySize": "3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,6 @@ await this.GetTestFlow()
.StartTestAsync();
}

[TestMethod]
public async Task Test_SendEmailToRecipientWithSubject()
{
string testRecipient = ContextStrings.TestRecipient;
string testEmailAddress = ContextStrings.TestEmailAdress;

StringDictionary recipientDict = new StringDictionary() { { "UserName", testRecipient }, { "EmailAddress", testEmailAddress } };
StringDictionary recipientList = new StringDictionary() { { "NameList", testRecipient + ": " + testEmailAddress } };

await this.GetTestFlow()
.Send(SendEmailUtterances.SendEmailToRecipientWithSubject)
.AssertReply(this.ShowAuth())
.Send(this.GetAuthResponse())
.AssertReplyOneOf(this.ConfirmOneNameOneAddress(recipientDict))
.Send(GeneralTestUtterances.Yes)
.AssertReplyOneOf(this.AddMoreContacts(recipientList))
.Send(GeneralTestUtterances.No)
.AssertReply(this.AssertComfirmBeforeSendingPrompt())
.Send(GeneralTestUtterances.Yes)
.AssertReply(this.AfterSendingMessage(ContextStrings.TestSubject))
.AssertReply(this.ActionEndMessage())
.StartTestAsync();
}

[TestMethod]
public async Task Test_SendEmailToRecipientWithSubjectAndContext()
{
Expand Down

0 comments on commit 5717335

Please sign in to comment.