Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for the SharePoint ACE APIs #6610

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// 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 && turnContext.Activity.ChannelId == Channels.SharePoint)
{
throw new NotSupportedException();
}
else
{
switch (turnContext.Activity.Name)
{
case "cardExtension/getCardView":
return CreateInvokeResponse(await OnSharePointTaskGetCardViewAsync(turnContext, SafeCast<TaskModuleRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));

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

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

case "cardExtension/setPropertyPaneConfiguration":
await OnSharePointTaskSetPropertyPaneConfigurationAsync(turnContext, SafeCast<TaskModuleRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false);
return CreateInvokeResponse();
}
}
}
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="taskModuleRequest">The task module 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 Task Module Response for the request.</returns>
protected virtual Task<GetCardViewResponse> OnSharePointTaskGetCardViewAsync(ITurnContext<IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, 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="taskModuleRequest">The task module 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 Task Module Response for the request.</returns>
protected virtual Task<GetQuickViewResponse> OnSharePointTaskGetQuickViewAsync(ITurnContext<IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, 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="taskModuleRequest">The task module 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 Task Module Response for the request.</returns>
protected virtual Task<GetPropertyPaneConfigurationResponse> OnSharePointTaskGetPropertyPaneConfigurationAsync(ITurnContext<IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, 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="taskModuleRequest">The task module 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 Task Module Response for the request.</returns>
protected virtual Task OnSharePointTaskSetPropertyPaneConfigurationAsync(ITurnContext<IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, 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>();
}
}
}
5 changes: 5 additions & 0 deletions libraries/Microsoft.Bot.Connector/Channels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public class Channels
/// </summary>
public const string Msteams = "msteams";

/// <summary>
/// MS Teams channel.
/// </summary>
public const string SharePoint = "sharepoint";

/// <summary>
/// Skype channel.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AdaptiveCards" Version="1.2.3" />
tracyboehrer marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>
84 changes: 84 additions & 0 deletions libraries/Microsoft.Bot.Schema/SharePoint/AceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

namespace Microsoft.Bot.Schema.SharePoint
{
/// <summary>
/// SharePoint Ace Data object.
/// </summary>
public class AceData
{
/// <summary>
/// Initializes a new instance of the <see cref="AceData"/> class.
/// </summary>
public AceData()
{
// Do nothing
}

/// <summary>
/// This enum contains the different types of card templates available in the SPFx framework.
/// </summary>
public enum AceCardSize
{
/// <summary>
/// Small
/// </summary>
Small,

/// <summary>
/// Medium
/// </summary>
Medium,

/// <summary>
/// Large
/// </summary>
Large
}

/// <summary>
/// Gets or Sets the card size of the adaptive card extension of type <see cref="AceCardSize"/> enum.
/// </summary>
/// <value>This value is the size of the adaptive card extension.</value>
[JsonProperty(PropertyName = "cardSize")]
[JsonConverter(typeof(StringEnumConverter))]
public AceCardSize CardSize { get; set; }

/// <summary>
/// Gets or Sets the version of the data of type <see cref="string"/>.
/// </summary>
/// <value>This value is the version of the adaptive card extension.</value>
[JsonProperty(PropertyName = "dataVersion")]
public string DataVersion { get; set; }

/// <summary>
/// Gets or Sets the id of type <see cref="string"/>.
/// </summary>
/// <value>This value is the ID of the adaptive card extension.</value>
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }

/// <summary>
/// Gets or Sets the title of type <see cref="string"/>.
/// </summary>
/// <value>This value is the title of the adaptive card extension.</value>
[JsonProperty(PropertyName = "title")]
public string Title { get; set; }

/// <summary>
/// Gets or Sets the icon property of type <see cref="string"/>.
/// </summary>
/// <value>This value is the icon of the adaptive card extension.</value>
[JsonProperty(PropertyName = "iconProperty")]
public string IconProperty { get; set; }
}
}
30 changes: 30 additions & 0 deletions libraries/Microsoft.Bot.Schema/SharePoint/Action.cs
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>
/// Initializes a new instance of the <see cref="ActionButton"/> class.
/// </summary>
public class Action
{
/// <summary>
/// Gets or Sets the type of type <see cref="string"/>.
/// </summary>
/// <value>This value is the type of the action.</value>
[JsonProperty(PropertyName = "type")]
public string Type { get; set; }

/// <summary>
/// Gets or Sets the action parameters of type <see cref="string"/>.
/// </summary>
/// <value>This value is the parameters of the action.</value>
[JsonProperty(PropertyName = "parameters")]
public ActionParameters Parameters { get; set; }
}
}
38 changes: 38 additions & 0 deletions libraries/Microsoft.Bot.Schema/SharePoint/ActionButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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>
/// SharePoint action button.
/// </summary>
public class ActionButton
{
/// <summary>
/// Initializes a new instance of the <see cref="ActionButton"/> class.
/// </summary>
public ActionButton()
{
// Do nothing
}

/// <summary>
/// Gets or Sets the title of type <see cref="string"/>.
/// </summary>
/// <value>This value is the title of the action button.</value>
[JsonProperty(PropertyName = "title")]
public string Title { get; set; }

/// <summary>
/// Gets or Sets the action of type <see cref="Action"/>.
/// </summary>
/// <value>This value is the action of the action button.</value>
[JsonProperty(PropertyName = "action")]
public Action Action { get; set; }
}
}
31 changes: 31 additions & 0 deletions libraries/Microsoft.Bot.Schema/SharePoint/ActionParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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>
/// SharePoint action button parameters.
/// </summary>
public class ActionParameters
{
/// <summary>
/// Initializes a new instance of the <see cref="ActionParameters"/> class.
/// </summary>
public ActionParameters()
{
// Do nothing
}

/// <summary>
/// Gets or Sets the view of type <see cref="string"/>.
/// </summary>
/// <value>This value is the view of the action parameter.</value>
[JsonProperty(PropertyName = "view")]
public string View { get; set; }
}
}
39 changes: 39 additions & 0 deletions libraries/Microsoft.Bot.Schema/SharePoint/CardViewData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

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

namespace Microsoft.Bot.Schema.SharePoint
{
/// <summary>
/// SharePoint Card View Data object.
/// </summary>
public class CardViewData
{
/// <summary>
/// Initializes a new instance of the <see cref="CardViewData"/> class.
/// </summary>
public CardViewData()
{
// Do nothing
}

/// <summary>
/// Gets or Sets the action buttons of type <see cref="ActionButton"/>.
/// </summary>
/// <value>This value is the action buttons of the card view.</value>
[JsonProperty(PropertyName = "actionButtons")]
public IEnumerable<ActionButton> ActionButtons { get; set; }

/// <summary>
/// Gets or Sets the primary text of type <see cref="string"/>.
/// </summary>
/// <value>This value is the primary text of the card view.</value>
[JsonProperty(PropertyName = "primaryText")]
public string PrimaryText { get; set; }
}
}
Loading
Loading