From ff383ae21c66e18b334d08833275a5f4a0a2ef60 Mon Sep 17 00:00:00 2001 From: Qi Kang Date: Wed, 20 May 2020 15:12:17 +0800 Subject: [PATCH 1/3] add RemoveRecipientMention config --- .../src/models/settings/defaultSettingManager.ts | 1 + runtime/dotnet/azurefunctions/Startup.cs | 5 ++++- runtime/dotnet/azurewebapp/Startup.cs | 5 ++++- runtime/dotnet/core/ComposerBot.cs | 10 +++++++++- runtime/dotnet/core/Settings/BotFeatureSettings.cs | 3 +++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Composer/packages/server/src/models/settings/defaultSettingManager.ts b/Composer/packages/server/src/models/settings/defaultSettingManager.ts index 1d8f13d652..21db6b8c94 100644 --- a/Composer/packages/server/src/models/settings/defaultSettingManager.ts +++ b/Composer/packages/server/src/models/settings/defaultSettingManager.ts @@ -22,6 +22,7 @@ export class DefaultSettingManager extends FileSettingManager { feature: { UseShowTypingMiddleware: false, UseInspectionMiddleware: false, + RemoveRecipientMention: false }, MicrosoftAppPassword: '', MicrosoftAppId: '', diff --git a/runtime/dotnet/azurefunctions/Startup.cs b/runtime/dotnet/azurefunctions/Startup.cs index 95b706e5c8..0641c70d30 100644 --- a/runtime/dotnet/azurefunctions/Startup.cs +++ b/runtime/dotnet/azurefunctions/Startup.cs @@ -174,6 +174,8 @@ public override void Configure(IFunctionsHostBuilder builder) var defaultLocale = rootConfiguration.GetValue("defaultLocale") ?? "en-us"; + var removeRecipientMention = settings?.Feature?.RemoveRecipientMention ?? false; + // Bot services.AddSingleton(s => new ComposerBot( @@ -184,7 +186,8 @@ public override void Configure(IFunctionsHostBuilder builder) s.GetService(), s.GetService(), GetRootDialog(Path.Combine(rootDirectory, settings.Bot)), - defaultLocale)); + defaultLocale, + removeRecipientMention)); } public void ConfigureTranscriptLoggerMiddleware(BotFrameworkHttpAdapter adapter, BotSettings settings) diff --git a/runtime/dotnet/azurewebapp/Startup.cs b/runtime/dotnet/azurewebapp/Startup.cs index 6ac3668f6e..fbdd6a153c 100644 --- a/runtime/dotnet/azurewebapp/Startup.cs +++ b/runtime/dotnet/azurewebapp/Startup.cs @@ -177,6 +177,8 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton((s) => GetBotAdapter(storage, settings, userState, conversationState, s, s.GetService())); + var removeRecipientMention = settings?.Feature?.RemoveRecipientMention ?? false; + services.AddSingleton(s => new ComposerBot( s.GetService(), @@ -186,7 +188,8 @@ public void ConfigureServices(IServiceCollection services) s.GetService(), s.GetService(), rootDialog, - defaultLocale)); + defaultLocale, + removeRecipientMention)); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/runtime/dotnet/core/ComposerBot.cs b/runtime/dotnet/core/ComposerBot.cs index c6a50d5002..6dec73aebe 100644 --- a/runtime/dotnet/core/ComposerBot.cs +++ b/runtime/dotnet/core/ComposerBot.cs @@ -13,6 +13,7 @@ using Microsoft.Bot.Builder.Dialogs.Declarative.Resources; using Microsoft.Bot.Builder.Skills; using Microsoft.Bot.Connector.Authentication; +using Microsoft.Bot.Schema; namespace Microsoft.BotFramework.Composer.Core { @@ -26,8 +27,9 @@ public class ComposerBot : ActivityHandler private readonly string rootDialogFile; private readonly IBotTelemetryClient telemetryClient; private readonly string defaultLocale; + private readonly bool removeRecipientMention; - public ComposerBot(ConversationState conversationState, UserState userState, ResourceExplorer resourceExplorer, BotFrameworkClient skillClient, SkillConversationIdFactoryBase conversationIdFactory, IBotTelemetryClient telemetryClient, string rootDialog, string defaultLocale) + public ComposerBot(ConversationState conversationState, UserState userState, ResourceExplorer resourceExplorer, BotFrameworkClient skillClient, SkillConversationIdFactoryBase conversationIdFactory, IBotTelemetryClient telemetryClient, string rootDialog, string defaultLocale, bool removeRecipientMention = false) { this.conversationState = conversationState; this.userState = userState; @@ -36,6 +38,7 @@ public ComposerBot(ConversationState conversationState, UserState userState, Res this.rootDialogFile = rootDialog; this.defaultLocale = defaultLocale; this.telemetryClient = telemetryClient; + this.removeRecipientMention = removeRecipientMention; LoadRootDialogAsync(); this.dialogManager.InitialTurnState.Set(skillClient); @@ -54,6 +57,11 @@ public ComposerBot(ConversationState conversationState, UserState userState, Res rootDialog.AutoEndDialog = false; } + if (this.removeRecipientMention && turnContext?.Activity?.Type == "message") + { + turnContext.Activity.RemoveRecipientMention(); + } + await this.dialogManager.OnTurnAsync(turnContext, cancellationToken: cancellationToken); await this.conversationState.SaveChangesAsync(turnContext, false, cancellationToken); await this.userState.SaveChangesAsync(turnContext, false, cancellationToken); diff --git a/runtime/dotnet/core/Settings/BotFeatureSettings.cs b/runtime/dotnet/core/Settings/BotFeatureSettings.cs index b36afc2c56..3d3b47ee71 100644 --- a/runtime/dotnet/core/Settings/BotFeatureSettings.cs +++ b/runtime/dotnet/core/Settings/BotFeatureSettings.cs @@ -15,5 +15,8 @@ public class BotFeatureSettings // Use InspectionMiddleware public bool UseInspectionMiddleware { get; set; } + + // Use RemoveRecipientMentionExtensions, only works in Teams channel + public bool RemoveRecipientMention { get; set; } } } From bae5ccc95fb71c3d74ca067c4cfe4145f0548c09 Mon Sep 17 00:00:00 2001 From: Qi Kang Date: Thu, 21 May 2020 14:42:18 +0800 Subject: [PATCH 2/3] fix code comment --- runtime/dotnet/core/Settings/BotFeatureSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/dotnet/core/Settings/BotFeatureSettings.cs b/runtime/dotnet/core/Settings/BotFeatureSettings.cs index 3d3b47ee71..1073ae5786 100644 --- a/runtime/dotnet/core/Settings/BotFeatureSettings.cs +++ b/runtime/dotnet/core/Settings/BotFeatureSettings.cs @@ -16,7 +16,7 @@ public class BotFeatureSettings // Use InspectionMiddleware public bool UseInspectionMiddleware { get; set; } - // Use RemoveRecipientMentionExtensions, only works in Teams channel + // Use RemoveRecipientMention Activity Extensions public bool RemoveRecipientMention { get; set; } } } From dbc57ee774cd4938b4b36531a22568aee3ac0206 Mon Sep 17 00:00:00 2001 From: Qi Kang Date: Thu, 21 May 2020 14:56:57 +0800 Subject: [PATCH 3/3] fix ci --- .../server/src/models/settings/defaultSettingManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Composer/packages/server/src/models/settings/defaultSettingManager.ts b/Composer/packages/server/src/models/settings/defaultSettingManager.ts index 21db6b8c94..0b565bca2e 100644 --- a/Composer/packages/server/src/models/settings/defaultSettingManager.ts +++ b/Composer/packages/server/src/models/settings/defaultSettingManager.ts @@ -22,7 +22,7 @@ export class DefaultSettingManager extends FileSettingManager { feature: { UseShowTypingMiddleware: false, UseInspectionMiddleware: false, - RemoveRecipientMention: false + RemoveRecipientMention: false, }, MicrosoftAppPassword: '', MicrosoftAppId: '',