Skip to content

Commit

Permalink
SP API
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Terentiev committed Oct 23, 2023
1 parent 593cd3b commit 9a80de0
Show file tree
Hide file tree
Showing 46 changed files with 1,332 additions and 1 deletion.
131 changes: 131 additions & 0 deletions libraries/botbuilder/src/sharepoint/sharePointActivityHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import {
ActivityHandler,
InvokeResponse,
AceRequest,
TurnContext,
CardViewResponse,
QuickViewResponse,
GetPropertyPaneConfigurationResponse,
SetPropertyPaneConfigurationResponse,
HandleActionResponse
} from 'botbuilder-core';

/**
* The SharePointActivityHandler is derived from ActivityHandler. It adds support for
* the SharePoint specific events and interactions
*/
export class SharePointActivityHandler extends ActivityHandler {
/**
* Invoked when an invoke activity is received from the connector.
* Invoke activities can be used to communicate many different things.
* @param context A strongly-typed context object for this turn
* @returns A task that represents the work queued to execute
*
* Invoke activities communicate programmatic commands from a client or channel to a bot.
*/
protected async onInvokeActivity(context: TurnContext): Promise<InvokeResponse> {
try {
if (!context.activity.name && context.activity.channelId === 'sharepoint') {
throw new Error('NotImplemented');
} else {
switch (context.activity.name) {
case 'cardExtension/getCardView':
return ActivityHandler.createInvokeResponse(
await this.OnSharePointTaskGetCardViewAsync(context, (context.activity.value as AceRequest))
);

case 'cardExtension/getQuickView':
return ActivityHandler.createInvokeResponse(
await this.OnSharePointTaskGetQuickViewAsync(context, (context.activity.value as AceRequest))
);

case 'cardExtension/getPropertyPaneConfiguration':
return ActivityHandler.createInvokeResponse(
await this.OnSharePointTaskGetPropertyPaneConfigurationAsync(context, (context.activity.value as AceRequest))
);

case 'cardExtension/setPropertyPaneConfiguration':
return ActivityHandler.createInvokeResponse(
await this.OnSharePointTaskSetPropertyPaneConfigurationAsync(context, (context.activity.value as AceRequest))
);
case 'cardExtension/handleAction':
return ActivityHandler.createInvokeResponse(
await this.OnSharePointTaskHandleActionAsync(context, (context.activity.value as AceRequest))
);
default:
return super.onInvokeActivity(context);
}
}
} catch (err) {
if (err.message === 'NotImplemented') {
return { status: 501 };
} else if (err.message === 'BadRequest') {
return { status: 400 };
}
throw err;
}
}

/**
* Override this in a derived class to provide logic for when a card view is fetched
*
* @param context - A strongly-typed context object for this turn
* @param taskModuleRequest - The task module invoke request value payload
* @returns A task module response for the request
*/
protected async OnSharePointTaskGetCardViewAsync(context: TurnContext, aceRequest: AceRequest): Promise<CardViewResponse>{
throw new Error('NotImplemented');
}

/**
* Override this in a derived class to provide logic for when a quick view is fetched
*
* @param context - A strongly-typed context object for this turn
* @param taskModuleRequest - The task module invoke request value payload
* @returns A task module response for the request
*/
protected async OnSharePointTaskGetQuickViewAsync(context: TurnContext, aceRequest: AceRequest): Promise<QuickViewResponse>{
throw new Error('NotImplemented');
}

/**
* Override this in a derived class to provide logic for getting configuration pane properties.
*
* @param context - A strongly-typed context object for this turn
* @param taskModuleRequest - The task module invoke request value payload
* @returns A task module response for the request
*/
protected async OnSharePointTaskGetPropertyPaneConfigurationAsync(context: TurnContext, aceRequest: AceRequest): Promise<GetPropertyPaneConfigurationResponse>{
throw new Error('NotImplemented');
}

/**
* Override this in a derived class to provide logic for setting configuration pane properties.
*
* @param context - A strongly-typed context object for this turn
* @param taskModuleRequest - The task module invoke request value payload
* @returns A task module response for the request
*/
protected async OnSharePointTaskSetPropertyPaneConfigurationAsync(context: TurnContext, aceRequest: AceRequest): Promise<SetPropertyPaneConfigurationResponse>{
throw new Error('NotImplemented');
}

/**
* Override this in a derived class to provide logic for setting configuration pane properties.
*
* @param context - A strongly-typed context object for this turn
* @param taskModuleRequest - The task module invoke request value payload
* @returns A task module response for the request
*/
protected async OnSharePointTaskHandleActionAsync(context: TurnContext, aceRequest: AceRequest): Promise<HandleActionResponse>{
throw new Error('NotImplemented');
}
}
3 changes: 2 additions & 1 deletion libraries/botframework-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"dependencies": {
"uuid": "^8.3.2",
"zod": "~1.11.17"
"zod": "~1.11.17",
"adaptivecards": "1.2.3"
},
"scripts": {
"build": "tsc -b",
Expand Down
3 changes: 3 additions & 0 deletions libraries/botframework-schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export { TokenExchangeInvokeResponse } from './tokenExchangeInvokeResponse';
// The Teams schemas was manually added to this library. This file has been updated to export those schemas.
export * from './teams';

// The SharePoint schemas was manually added to this library. This file has been updated to export those schemas.
export * from './sharepoint';

/**
* Attachment View name and size
*/
Expand Down
20 changes: 20 additions & 0 deletions libraries/botframework-schema/src/sharepoint/aceData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

/**
* SharePoint Ace Data object
*/
export interface AceData {
cardSize: AceCardSize;
dataVersion: string;
id: string;
title: string;
iconProperty: string;
description: string;
properties: any;
}

/**
* SharePoint Ace Card Size
*/
export type AceCardSize = "Medium" | "Large";
17 changes: 17 additions & 0 deletions libraries/botframework-schema/src/sharepoint/aceRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

/**
* ACE invoke request payload.
*/
export interface AceRequest {
/**
* @member {any} [data] User ACE request data. Free payload with key-value pairs.
*/
data?: any; // eslint-disable-line @typescript-eslint/no-explicit-any

/**
* @member {any} [properties] ACE properties data.
*/
properties?: any; // eslint-disable-line @typescript-eslint/no-explicit-any
}
Loading

0 comments on commit 9a80de0

Please sign in to comment.