Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Microsoft.Bot.Builder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Parsers", "Parsers", "{37BA
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Builder.Parsers.LU.Tests", "tests\Parsers\Microsoft.Bot.Builder.Parsers.LU.Tests\Microsoft.Bot.Builder.Parsers.LU.Tests.csproj", "{D7FFAB17-C7BE-490F-A974-584B5E37CF6D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Builder.Runtime", "libraries\Microsoft.Bot.Builder.Runtime\Microsoft.Bot.Builder.Runtime.csproj", "{7C5523DB-CFFF-4560-A718-03B101129394}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Builder.Runtime.Tests", "tests\Microsoft.Bot.Builder.Runtime.Tests\Microsoft.Bot.Builder.Runtime.Tests.csproj", "{A3E52462-628B-4595-9399-09E3609258AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -869,6 +873,22 @@ Global
{D7FFAB17-C7BE-490F-A974-584B5E37CF6D}.Release|Any CPU.Build.0 = Release|Any CPU
{D7FFAB17-C7BE-490F-A974-584B5E37CF6D}.Release-Windows|Any CPU.ActiveCfg = Release|Any CPU
{D7FFAB17-C7BE-490F-A974-584B5E37CF6D}.Release-Windows|Any CPU.Build.0 = Release|Any CPU
{7C5523DB-CFFF-4560-A718-03B101129394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C5523DB-CFFF-4560-A718-03B101129394}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C5523DB-CFFF-4560-A718-03B101129394}.Debug-Windows|Any CPU.ActiveCfg = Debug|Any CPU
{7C5523DB-CFFF-4560-A718-03B101129394}.Debug-Windows|Any CPU.Build.0 = Debug|Any CPU
{7C5523DB-CFFF-4560-A718-03B101129394}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C5523DB-CFFF-4560-A718-03B101129394}.Release|Any CPU.Build.0 = Release|Any CPU
{7C5523DB-CFFF-4560-A718-03B101129394}.Release-Windows|Any CPU.ActiveCfg = Release|Any CPU
{7C5523DB-CFFF-4560-A718-03B101129394}.Release-Windows|Any CPU.Build.0 = Release|Any CPU
{A3E52462-628B-4595-9399-09E3609258AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3E52462-628B-4595-9399-09E3609258AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3E52462-628B-4595-9399-09E3609258AB}.Debug-Windows|Any CPU.ActiveCfg = Debug|Any CPU
{A3E52462-628B-4595-9399-09E3609258AB}.Debug-Windows|Any CPU.Build.0 = Debug|Any CPU
{A3E52462-628B-4595-9399-09E3609258AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3E52462-628B-4595-9399-09E3609258AB}.Release|Any CPU.Build.0 = Release|Any CPU
{A3E52462-628B-4595-9399-09E3609258AB}.Release-Windows|Any CPU.ActiveCfg = Release|Any CPU
{A3E52462-628B-4595-9399-09E3609258AB}.Release-Windows|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -964,6 +984,8 @@ Global
{C395D6D2-DF99-4FD9-B5C5-04E8BB866509} = {ABB57A05-A284-40BA-A143-0CFEADE2B630}
{37BA1593-FE3D-4CB9-A040-6CAB7B2D134A} = {AD743B78-D61F-4FBF-B620-FA83CE599A50}
{D7FFAB17-C7BE-490F-A974-584B5E37CF6D} = {37BA1593-FE3D-4CB9-A040-6CAB7B2D134A}
{7C5523DB-CFFF-4560-A718-03B101129394} = {4269F3C3-6B42-419B-B64A-3E6DC0F1574A}
{A3E52462-628B-4595-9399-09E3609258AB} = {AD743B78-D61F-4FBF-B620-FA83CE599A50}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7173C9F3-A7F9-496E-9078-9156E35D6E16}
Expand Down
26 changes: 26 additions & 0 deletions libraries/Microsoft.Bot.Builder.Runtime/Builders/IBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Bot.Builder.Runtime.Builders
{
/// <summary>
/// Defines an interface used to build an instance of the specified type using supplied application
/// configuration and registered services.
/// </summary>
/// <typeparam name="T">The type of the object to be returned by the builder.</typeparam>
public interface IBuilder<out T>
{
/// <summary>
/// Builds an instance of type <typeparamref name="T"/>.
/// </summary>
/// <param name="services">
/// Provider containing all services registered with the application's service collection.
/// </param>
/// <param name="configuration">Application configuration.</param>
/// <returns>An instance of type <typeparamref name="T"/>.</returns>
T Build(IServiceProvider services, IConfiguration configuration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Bot.Builder.Runtime.Builders.Middleware
{
/// <summary>
/// Defines an interface for an implementation of <see cref="IBuilder{T}"/> that returns an
/// instance whose type implements <see cref="IMiddleware" />.
/// </summary>
public interface IMiddlewareBuilder : IBuilder<IMiddleware>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Runtime.Builders.Middleware
{
/// <summary>
/// Defines an implementation of <see cref="IMiddlewareBuilder"/> that returns an instance
/// of <see cref="InspectionMiddleware"/>.
/// </summary>
[JsonObject]
public class InspectionMiddlewareBuilder : IMiddlewareBuilder
{
/// <summary>
/// Class identifier.
/// </summary>
[JsonProperty("$kind")]
public const string Kind = "Microsoft.InspectionMiddleware";

/// <summary>
/// Builds an instance of type <see cref="InspectionMiddleware"/>.
/// </summary>
/// <param name="services">
/// Provider containing all services registered with the application's service collection.
/// </param>
/// <param name="configuration">Application configuration.</param>
/// <returns>An instance of type <see cref="InspectionMiddleware"/>.</returns>
public IMiddleware Build(IServiceProvider services, IConfiguration configuration)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}

if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

var storage = services.GetService<IStorage>();

return new InspectionMiddleware(new InspectionState(storage));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Runtime.Builders.Middleware
{
/// <summary>
/// Defines an implementation of <see cref="IMiddlewareBuilder"/> that returns an instance
/// of <see cref="RemoveRecipientMentionMiddlewareBuilder"/>.
/// </summary>
[JsonObject]
public class RemoveRecipientMentionMiddlewareBuilder : IMiddleware, IMiddlewareBuilder
{
/// <summary>
/// Class identifier.
/// </summary>
[JsonProperty("$kind")]
public const string Kind = "Microsoft.RemoveRecipientMentionMiddleware";

/// <summary>
/// Builds an instance of type <see cref="RemoveRecipientMentionMiddlewareBuilder"/>.
/// </summary>
/// <param name="services">
/// Provider containing all services registered with the application's service collection.
/// </param>
/// <param name="configuration">Application configuration.</param>
/// <returns>An instance of type <see cref="RemoveRecipientMentionMiddlewareBuilder"/>.</returns>
public IMiddleware Build(IServiceProvider services, IConfiguration configuration)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}

if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

return this;
}

/// <summary>
/// Processes an incoming activity.
/// </summary>
/// <param name="turnContext">The context object for this turn.</param>
/// <param name="next">The delegate to call to continue the bot middleware pipeline.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the work queued to execute.</returns>
/// <remarks>Spawns a thread that sends the periodic typing activities until the turn ends.
/// </remarks>
/// <seealso cref="ITurnContext"/>
/// <seealso cref="Bot.Schema.IActivity"/>
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)
{
if (turnContext?.Activity?.Type == ActivityTypes.Message)
{
turnContext.Activity.RemoveRecipientMention();
}

await next(cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder.Runtime.Extensions;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Runtime.Builders.Middleware
{
/// <summary>
/// Defines an implementation of <see cref="IMiddlewareBuilder"/> that returns an instance
/// of <see cref="ShowTypingMiddleware"/>.
/// </summary>
[JsonObject]
public class ShowTypingMiddlewareBuilder : IMiddlewareBuilder
{
/// <summary>
/// Class identifier.
/// </summary>
[JsonProperty("$kind")]
public const string Kind = "Microsoft.ShowTypingMiddleware";

private const int DefaultDelay = 500;
private const int DefaultPeriod = 2000;

/// <summary>
/// Gets or sets the duration in milliseconds to delay before sending the first typing indicator.
/// Defaults to 500.
/// </summary>
/// <value>
/// The duration in milliseconds to delay before sending the first typing indicator.
/// Defaults to 500.
/// </value>
[JsonProperty("delay")]
public IntExpression Delay { get; set; }

/// <summary>
/// Gets or sets the interval in milliseconds at which additional typing indicators will be sent.
/// Defaults to 2000.
/// </summary>
/// <value>
/// The interval in milliseconds at which additional typing indicators will be sent.
/// Defaults to 2000.
/// </value>
[JsonProperty("period")]
public IntExpression Period { get; set; }

/// <summary>
/// Builds an instance of type <see cref="ShowTypingMiddleware"/>.
/// </summary>
/// <param name="services">
/// Provider containing all services registered with the application's service collection.
/// </param>
/// <param name="configuration">Application configuration.</param>
/// <returns>An instance of type <see cref="ShowTypingMiddleware"/>.</returns>
public IMiddleware Build(IServiceProvider services, IConfiguration configuration)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}

if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

return new ShowTypingMiddleware(
delay: this.Delay?.GetConfigurationValue(configuration) ?? DefaultDelay,
period: this.Period?.GetConfigurationValue(configuration) ?? DefaultPeriod);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using AdaptiveExpressions.Properties;
using Microsoft.AspNetCore.Http;
using Microsoft.Bot.Builder.Integration.ApplicationInsights.Core;
using Microsoft.Bot.Builder.Runtime.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Runtime.Builders.Middleware
{
/// <summary>
/// Defines an implementation of <see cref="IMiddlewareBuilder"/> that returns an instance
/// of <see cref="TelemetryInitializerMiddleware"/>.
/// </summary>
[JsonObject]
public class TelemetryMiddlewareBuilder : IMiddlewareBuilder
{
/// <summary>
/// Class identifier.
/// </summary>
[JsonProperty("$kind")]
public const string Kind = "Microsoft.TelemetryMiddleware";

/// <summary>
/// Gets or sets whether to enable logging of activity events. Defaults to true.
/// </summary>
/// <value>
/// Indicates whether to enable logging of activity events. Defaults to true.
/// </value>
[JsonProperty("logActivities")]
public BoolExpression LogActivities { get; set; }

/// <summary>
/// Gets or sets whether include personally identifiable information (PII) in log events. Defaults to false.
/// </summary>
/// <value>
/// Indicates whether include personally identifiable information (PII) in log events. Defaults to false.
/// </value>
[JsonProperty("logPersonalInformation")]
public BoolExpression LogPersonalInformation { get; set; }

/// <summary>
/// Builds an instance of type <see cref="TelemetryInitializerMiddleware"/>.
/// </summary>
/// <param name="services">
/// Provider containing all services registered with the application's service collection.
/// </param>
/// <param name="configuration">Application configuration.</param>
/// <returns>An instance of type <see cref="TelemetryInitializerMiddleware"/>.</returns>
public IMiddleware Build(IServiceProvider services, IConfiguration configuration)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}

if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

var botTelemetryClient = services.GetService<IBotTelemetryClient>();
var httpContextAccessor = services.GetService<IHttpContextAccessor>();

return new TelemetryInitializerMiddleware(
httpContextAccessor: httpContextAccessor,
telemetryLoggerMiddleware: new TelemetryLoggerMiddleware(
telemetryClient: botTelemetryClient,
logPersonalInformation: this.LogPersonalInformation?.GetConfigurationValue(configuration) ?? false),
logActivityTelemetry: this.LogActivities?.GetConfigurationValue(configuration) ?? true);
}
}
}
Loading