Skip to content

Commit

Permalink
feat: Support for SharePoint (Viva) Adaptive Card Extension (#4551)
Browse files Browse the repository at this point in the history
* SP API

* comments

* return comments

* update api file

* fix all lint errors

* more lint errors

* address comments

* formatting

* incorrect comment

* more lint fixes

* updated comments

* export SP activity handler

* update public API md

---------

Co-authored-by: Alex Terentiev <aterentiev@microsoft.com>
  • Loading branch information
AJIXuMuK and Alex Terentiev committed Nov 1, 2023
1 parent 0032ed7 commit d18c19c
Show file tree
Hide file tree
Showing 49 changed files with 2,445 additions and 1 deletion.
16 changes: 16 additions & 0 deletions libraries/botbuilder/etc/botbuilder.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
```ts

import { AceRequest } from 'botbuilder-core';
import { Activity } from 'botbuilder-core';
import { ActivityHandler } from 'botbuilder-core';
import { ActivityHandlerBase } from 'botbuilder-core';
Expand All @@ -22,6 +23,7 @@ import { BotFrameworkClient } from 'botbuilder-core';
import { BotFrameworkSkill } from 'botbuilder-core';
import { BotState } from 'botbuilder-core';
import { CancelOperationResponse } from 'botframework-connector';
import { CardViewResponse } from 'botbuilder-core';
import { ChannelAccount } from 'botbuilder-core';
import { ChannelInfo } from 'botbuilder-core';
import { ClaimsIdentity } from 'botframework-connector';
Expand All @@ -39,6 +41,8 @@ import { ConversationState } from 'botbuilder-core';
import { CoreAppCredentials } from 'botbuilder-core';
import { ExtendedUserTokenProvider } from 'botbuilder-core';
import { FileConsentCardResponse } from 'botbuilder-core';
import { GetPropertyPaneConfigurationResponse } from 'botbuilder-core';
import { HandleActionResponse } from 'botbuilder-core';
import { HttpClient } from '@azure/ms-rest-js';
import { HttpOperationResponse } from '@azure/ms-rest-js';
import { ICredentialProvider } from 'botframework-connector';
Expand All @@ -63,9 +67,11 @@ import { O365ConnectorCardActionQuery } from 'botbuilder-core';
import { OnBehalfOf } from 'botbuilder-core';
import { PagedMembersResult } from 'botbuilder-core';
import { PagedResult } from 'botbuilder-core';
import { QuickViewResponse } from 'botbuilder-core';
import { ReadReceiptInfo } from 'botframework-connector';
import { RequestHandler } from 'botframework-streaming';
import { ResourceResponse } from 'botbuilder-core';
import { SetPropertyPaneConfigurationResponse } from 'botbuilder-core';
import { SigninStateVerificationQuery } from 'botbuilder-core';
import { SignInUrlResponse } from 'botframework-connector';
import { SimpleCredentialProvider } from 'botframework-connector';
Expand Down Expand Up @@ -338,6 +344,16 @@ export class SetSpeakMiddleware implements Middleware {
onTurn(turnContext: TurnContext, next: () => Promise<void>): Promise<void>;
}

// @public
export class SharePointActivityHandler extends ActivityHandler {
protected onInvokeActivity(context: TurnContext): Promise<InvokeResponse>;
protected onSharePointTaskGetCardViewAsync(_context: TurnContext, _aceRequest: AceRequest): Promise<CardViewResponse>;
protected onSharePointTaskGetPropertyPaneConfigurationAsync(_context: TurnContext, _aceRequest: AceRequest): Promise<GetPropertyPaneConfigurationResponse>;
protected onSharePointTaskGetQuickViewAsync(_context: TurnContext, _aceRequest: AceRequest): Promise<QuickViewResponse>;
protected onSharePointTaskHandleActionAsync(_context: TurnContext, _aceRequest: AceRequest): Promise<HandleActionResponse>;
protected onSharePointTaskSetPropertyPaneConfigurationAsync(_context: TurnContext, _aceRequest: AceRequest): Promise<SetPropertyPaneConfigurationResponse>;
}

// @public @deprecated (undocumented)
export class SkillHandler extends ChannelServiceHandler {
constructor(adapter: BotAdapter, bot: ActivityHandlerBase, conversationIdFactory: SkillConversationIdFactoryBase, credentialProvider: ICredentialProvider, authConfig: AuthenticationConfiguration, channelService?: string);
Expand Down
1 change: 1 addition & 0 deletions libraries/botbuilder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export { HandoffEventNames } from './handoffEventNames';
export { Request, Response, WebRequest, WebResponse } from './interfaces';
export { StatusCodeError } from './statusCodeError';
export { StreamingHttpClient, TokenResolver } from './streaming';
export { SharePointActivityHandler } from './sharepoint/sharePointActivityHandler';
152 changes: 152 additions & 0 deletions libraries/botbuilder/src/sharepoint/sharePointActivityHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**
* @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.
* * Invoke activities communicate programmatic commands from a client or channel to a bot.
*
* @param context A strongly-typed context object for this turn
* @returns A task that represents the work queued to execute
*/
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 _aceRequest - The Ace invoke request value payload
* @returns A Card View 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 _aceRequest - The Ace invoke request value payload
* @returns A Quick View 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 _aceRequest - The Ace invoke request value payload
* @returns A Property Pane Configuration 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 _aceRequest - The Ace invoke request value payload
* @returns A Card view or no-op action response
*/
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 _aceRequest - The Ace invoke request value payload
* @returns A handle action response
*/
protected async onSharePointTaskHandleActionAsync(
_context: TurnContext,
_aceRequest: AceRequest
): Promise<HandleActionResponse> {
throw new Error('NotImplemented');
}
}

0 comments on commit d18c19c

Please sign in to comment.