Skip to content

Commit

Permalink
Handle action and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Terentiev committed Oct 16, 2023
1 parent ff04905 commit eff37be
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 11,755 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ protected override async Task<InvokeResponse> OnInvokeActivityAsync(ITurnContext
case "cardExtension/setPropertyPaneConfiguration":
await OnSharePointTaskSetPropertyPaneConfigurationAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false);
return CreateInvokeResponse();

case "cardExtension/handleAction":
return CreateInvokeResponse(await OnSharePointTaskHandleActionAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));
}
}
}
Expand All @@ -73,7 +76,7 @@ protected override async Task<InvokeResponse> OnInvokeActivityAsync(ITurnContext
/// 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 task module invoke request value payload.</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>
Expand All @@ -86,7 +89,7 @@ protected virtual Task<GetCardViewResponse> OnSharePointTaskGetCardViewAsync(ITu
/// 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 task module invoke request value payload.</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>
Expand All @@ -99,7 +102,7 @@ protected virtual Task<GetQuickViewResponse> OnSharePointTaskGetQuickViewAsync(I
/// 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 task module invoke request value payload.</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>
Expand All @@ -112,7 +115,7 @@ protected virtual Task<GetPropertyPaneConfigurationResponse> OnSharePointTaskGet
/// 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 task module invoke request value payload.</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>An empty response.</returns>
Expand All @@ -121,6 +124,19 @@ protected virtual Task OnSharePointTaskSetPropertyPaneConfigurationAsync(ITurnCo
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 view 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>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Microsoft.Bot.Schema.SharePoint
{
/// <summary>
/// Adaptive Card Extension View response type.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum ViewResponseType
{
/// <summary>
/// Render card view.
/// </summary>
Card,

/// <summary>
/// Render quick view.
/// </summary>
QuickView,

/// <summary>
/// No operation.
/// </summary>
NoOp
}

/// <summary>
/// Response returned when handling a client-side action on an Adaptive Card Extension.
/// </summary>
public abstract class BaseHandleActionResponse
{
/// <summary>
/// Gets the response type.
/// </summary>
/// <value>Response type.</value>
[JsonProperty(PropertyName = "responseType")]
public abstract ViewResponseType ResponseType { get; }

/// <summary>
/// Gets or sets render arguments.
/// </summary>
/// <value>Render arguments.</value>
[JsonProperty(PropertyName = "renderArguments")]
public object RenderArguments { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace Microsoft.Bot.Schema.SharePoint
{
/// <summary>
/// Adaptive Card Extension Client-side action response to render card view.
/// </summary>
public class CardViewHandleActionResponse : BaseHandleActionResponse
{
/// <summary>
/// Gets the response type.
/// </summary>
/// <value>Card.</value>
[JsonProperty(PropertyName = "responseType")]
public override ViewResponseType ResponseType => ViewResponseType.Card;

/// <summary>
/// Gets or sets card view render arguments.
/// </summary>
/// <value>Card view render arguments.</value>
[JsonProperty(PropertyName = "renderArguments")]
public new GetCardViewResponse RenderArguments { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace Microsoft.Bot.Schema.SharePoint
{
/// <summary>
/// Adaptive Card Extension Client-side action no-op response.
/// </summary>
public class NoOpHandleActionResponse : BaseHandleActionResponse
{
/// <summary>
/// Gets the response type.
/// </summary>
/// <value>Card.</value>
[JsonProperty(PropertyName = "responseType")]
public override ViewResponseType ResponseType => ViewResponseType.NoOp;

/// <summary>
/// Gets or sets card view render arguments.
/// </summary>
/// <value>Card view render arguments.</value>
[JsonProperty(PropertyName = "renderArguments")]
public new object RenderArguments
{
get => null;
set { }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace Microsoft.Bot.Schema.SharePoint
{
/// <summary>
/// Adaptive Card Extension Client-side action response to render quick view.
/// </summary>
public class QuickViewHandleActionResponse : BaseHandleActionResponse
{
/// <summary>
/// Gets the response type.
/// </summary>
/// <value>Card.</value>
[JsonProperty(PropertyName = "responseType")]
public override ViewResponseType ResponseType => ViewResponseType.QuickView;

/// <summary>
/// Gets or sets card view render arguments.
/// </summary>
/// <value>Card view render arguments.</value>
[JsonProperty(PropertyName = "renderArguments")]
public new GetQuickViewResponse RenderArguments { get; set; }
}
}
Loading

0 comments on commit eff37be

Please sign in to comment.