Skip to content

Commit

Permalink
Merge branch 'microsoft:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
fangyangci authored Dec 18, 2023
2 parents 27bc619 + 7795856 commit 8da0eae
Show file tree
Hide file tree
Showing 105 changed files with 4,235 additions and 930 deletions.
9 changes: 8 additions & 1 deletion ApiCompatBaseline.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# These types are no longer supported in Microsoft.Bot.Builder.Azure:
TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbCustomClientOptions' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbStorage' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbStorageOptions' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbStorageOptions' does not exist in the implementation but it does exist in the contract.

TypesMustExist : Type 'Microsoft.Bot.Connector.Authentication.AdalAuthenticator' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.AppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract.
CannotAddAbstractMembers : Member 'Microsoft.Bot.Connector.Authentication.AppCredentials.BuildIAuthenticator()' is abstract in the implementation but is missing in the contract.
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.CertificateAppCredentials..ctor(Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate, System.String, System.Net.Http.HttpClient, Microsoft.Extensions.Logging.ILogger)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.CertificateAppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.Bot.Builder.Dialogs.Declarative;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -11,6 +12,7 @@ namespace Microsoft.Bot.Builder.AI.Orchestrator
/// <summary>
/// Define component assets for Orchestrator.
/// </summary>
[Obsolete("The Bot Framework Orchestrator will be deprecated in the next version of the Bot Framework SDK.")]
public class OrchestratorBotComponent : BotComponent
{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Microsoft.Bot.Builder.AI.Orchestrator
/// <summary>
/// Class that represents an adaptive Orchestrator recognizer.
/// </summary>
[Obsolete("The Bot Framework Orchestrator will be deprecated in the next version of the Bot Framework SDK.")]
public class OrchestratorRecognizer : AdaptiveRecognizer
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ public enum HttpMethod
/// <summary>
/// Http DELETE.
/// </summary>
DELETE
DELETE,

/// <summary>
/// Http HEAD.
/// </summary>
HEAD
}

/// <summary>
Expand Down Expand Up @@ -315,7 +320,8 @@ public enum HttpMethod
}

break;
case HttpMethod.DELETE:
case HttpMethod.DELETE:
case HttpMethod.HEAD:
response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"POST",
"PATCH",
"PUT",
"DELETE"
"DELETE",
"HEAD"
],
"examples": [
"GET",
Expand Down
22 changes: 20 additions & 2 deletions libraries/Microsoft.Bot.Builder.Dialogs/DialogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
Expand Down Expand Up @@ -74,8 +75,25 @@ internal static async Task<DialogTurnResult> InternalRunAsync(ITurnContext turnC
}
catch (Exception err)
{
// fire error event, bubbling from the leaf.
var handled = await dialogContext.EmitEventAsync(DialogEvents.Error, err, bubble: true, fromLeaf: true, cancellationToken: cancellationToken).ConfigureAwait(false);
var handled = false;
var innerExceptions = new List<Exception>();
try
{
// fire error event, bubbling from the leaf.
handled = await dialogContext.EmitEventAsync(DialogEvents.Error, err, bubble: true, fromLeaf: true, cancellationToken: cancellationToken).ConfigureAwait(false);
}
#pragma warning disable CA1031 // Do not catch general exception types (capture the error in case it's not handled properly)
catch (Exception emitErr)
#pragma warning restore CA1031 // Do not catch general exception types
{
innerExceptions.Add(emitErr);
}

if (innerExceptions.Any())
{
innerExceptions.Add(err);
throw new AggregateException("Unable to emit the error as a DialogEvent.", innerExceptions);
}

if (!handled)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.SharePoint;
using Microsoft.Bot.Schema.Teams;
using Newtonsoft.Json.Linq;

namespace Microsoft.Bot.Builder.SharePoint
{
/// <summary>
/// The SharePointActivityHandler is derived from ActivityHandler. It adds support for
/// the SharePoint specific events and interactions.
/// </summary>
public class SharePointActivityHandler : ActivityHandler
{
/// <summary>
/// Invoked when an invoke activity is received from the connector.
/// Invoke activities can be used to communicate many different things.
/// </summary>
/// <param name="turnContext">A strongly-typed context object for this turn.</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>
/// Invoke activities communicate programmatic commands from a client or channel to a bot.
/// The meaning of an invoke activity is defined by the <see cref="IInvokeActivity.Name"/> property,
/// which is meaningful within the scope of a channel.
/// </remarks>
protected override async Task<InvokeResponse> OnInvokeActivityAsync(ITurnContext<IInvokeActivity> turnContext, CancellationToken cancellationToken)
{
try
{
if (turnContext.Activity.Name == null)
{
throw new NotSupportedException();
}
else
{
switch (turnContext.Activity.Name)
{
case "cardExtension/getCardView":
return CreateInvokeResponse(await OnSharePointTaskGetCardViewAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));

case "cardExtension/getQuickView":
return CreateInvokeResponse(await OnSharePointTaskGetQuickViewAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));

case "cardExtension/getPropertyPaneConfiguration":
return CreateInvokeResponse(await OnSharePointTaskGetPropertyPaneConfigurationAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));

case "cardExtension/setPropertyPaneConfiguration":
BaseHandleActionResponse setPropPaneConfigResponse = await OnSharePointTaskSetPropertyPaneConfigurationAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false);
ValidateSetPropertyPaneConfigurationResponse(setPropPaneConfigResponse);
return CreateInvokeResponse(setPropPaneConfigResponse);

case "cardExtension/handleAction":
return CreateInvokeResponse(await OnSharePointTaskHandleActionAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));
}
}
}
catch (InvokeResponseException e)
{
return e.CreateInvokeResponse();
}

return await base.OnInvokeActivityAsync(turnContext, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Override this in a derived class to provide logic for when a card view is fetched.
/// </summary>
/// <param name="turnContext">A strongly-typed context object for this turn.</param>
/// <param name="aceRequest">The ACE invoke request value payload.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A Card View Response for the request.</returns>
protected virtual Task<CardViewResponse> OnSharePointTaskGetCardViewAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}

/// <summary>
/// Override this in a derived class to provide logic for when a quick view is fetched.
/// </summary>
/// <param name="turnContext">A strongly-typed context object for this turn.</param>
/// <param name="aceRequest">The ACE invoke request value payload.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A Quick View Response for the request.</returns>
protected virtual Task<QuickViewResponse> OnSharePointTaskGetQuickViewAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}

/// <summary>
/// Override this in a derived class to provide logic for getting configuration pane properties.
/// </summary>
/// <param name="turnContext">A strongly-typed context object for this turn.</param>
/// <param name="aceRequest">The ACE invoke request value payload.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A Property Pane Configuration Response for the request.</returns>
protected virtual Task<GetPropertyPaneConfigurationResponse> OnSharePointTaskGetPropertyPaneConfigurationAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}

/// <summary>
/// Override this in a derived class to provide logic for setting configuration pane properties.
/// </summary>
/// <param name="turnContext">A strongly-typed context object for this turn.</param>
/// <param name="aceRequest">The ACE invoke request value payload.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>Card view or no-op action response.</returns>
/// <remarks>The handler will fail with 500 status code if the response is of type <see cref="QuickViewHandleActionResponse" />.</remarks>
protected virtual Task<BaseHandleActionResponse> OnSharePointTaskSetPropertyPaneConfigurationAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}

/// <summary>
/// Override this in a derived class to provide logic for handling ACE actions.
/// </summary>
/// <param name="turnContext">A strongly-typed context object for this turn.</param>
/// <param name="aceRequest">The ACE invoke request value payload.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A handle action response.</returns>
protected virtual Task<BaseHandleActionResponse> OnSharePointTaskHandleActionAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}

/// <summary>
/// Safely casts an object to an object of type <typeparamref name="T"/> .
/// </summary>
/// <param name="value">The object to be casted.</param>
/// <returns>The object casted in the new type.</returns>
private static T SafeCast<T>(object value)
{
var obj = value as JObject;
if (obj == null)
{
throw new InvokeResponseException(HttpStatusCode.BadRequest, $"expected type '{value.GetType().Name}'");
}

return obj.ToObject<T>();
}

private void ValidateSetPropertyPaneConfigurationResponse(BaseHandleActionResponse response)
{
if (response is QuickViewHandleActionResponse)
{
throw new InvokeResponseException(HttpStatusCode.InternalServerError, "Response for SetPropertyPaneConfiguration action can't be of QuickView type.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Threading;
Expand Down Expand Up @@ -91,7 +92,7 @@ public async Task<ReceiveResponse> SendRequestAsync(StreamingRequest request, Ca
}
}

return await responseCompletionSource.Task.DefaultTimeOutAsync().ConfigureAwait(false);
return await responseCompletionSource.Task.DefaultTimeOutAsync().ConfigureAwait(false);
}

public async Task SendResponseAsync(Header header, StreamingResponse response, CancellationToken cancellationToken)
Expand Down Expand Up @@ -194,6 +195,11 @@ public virtual void ReceiveResponse(Header header, ReceiveResponse response)

Log.PayloadReceived(_logger, header);

if (response.StatusCode == (int)HttpStatusCode.Accepted)
{
return;
}

lock (_receiveSync)
{
if (!response.Streams.Any())
Expand Down Expand Up @@ -358,6 +364,8 @@ private void ProcessRequest(Guid id, ReceiveRequest request)
{
_ = Task.Run(async () =>
{
// Send an HTTP 202 (Accepted) response right away, otherwise, while under high streaming load, the conversation times out due to not having a response in the request/response time frame.
await SendResponseAsync(new Header { Id = id, Type = PayloadTypes.Response }, new StreamingResponse { StatusCode = (int)HttpStatusCode.Accepted }, _connectionCancellationToken).ConfigureAwait(false);
var streamingResponse = await _receiver.ProcessRequestAsync(request, null).ConfigureAwait(false);
await SendResponseAsync(new Header() { Id = id, Type = PayloadTypes.Response }, streamingResponse, _connectionCancellationToken).ConfigureAwait(false);

Expand Down
Loading

0 comments on commit 8da0eae

Please sign in to comment.