Skip to content

Commit

Permalink
Merge pull request #148 from OfficeDev/yilia/adaptive-card-task-modul…
Browse files Browse the repository at this point in the history
…e-node

[Node.js] Support 1) Task Module, 2) Adaptive Card, and 3) bot-builder wrapped adaptive card actions
  • Loading branch information
robin-liao authored Oct 16, 2018
2 parents 8fe2090 + 68a5dcf commit fff9395
Show file tree
Hide file tree
Showing 10 changed files with 1,359 additions and 12 deletions.
1 change: 1 addition & 0 deletions Node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"main": "./lib/botbuilder-teams.js",
"typings": "./lib/botbuilder-teams.d.ts",
"dependencies": {
"adaptivecards": "^1.0.0",
"botbuilder": "^3.11.0",
"crypto": "^1.0.1",
"ms-rest": "^1.15.7",
Expand Down
27 changes: 27 additions & 0 deletions Node/src/TeamsChatConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ import RemoteQuery = require('./RemoteQuery/teams');
import RestClient = require('./RemoteQuery/RestClient');
import { ChannelAccount, ChannelInfo, ComposeExtensionQuery, IComposeExtensionResponse, ComposeExtensionParameter, ComposeExtensionResponse, IO365ConnectorCardActionQuery, ISigninStateVerificationQuery, TeamInfo, TeamsChannelAccountsResult } from './models';
import { IFileConsentCardResponse } from './models/FileConsentCardResponse';
import * as task from './models/TaskModuleResponse';

var WebResource = msRest.WebResource;

export type ComposeExtensionHandlerType = (event: builder.IEvent, query: ComposeExtensionQuery, callback: (err: Error, result: IComposeExtensionResponse, statusCode?: number) => void) => void;
export type O365ConnectorCardActionHandlerType = (event: builder.IEvent, query: IO365ConnectorCardActionQuery, callback: (err: Error, result: any, statusCode?: number) => void) => void;
export type SigninStateVerificationHandlerType = (event: builder.IEvent, query: ISigninStateVerificationQuery, callback: (err: Error, result: any, statusCode?: number) => void) => void;
export type FileConsentCardResponseHandlerType = (event: builder.IEvent, response: IFileConsentCardResponse, callback: (err: Error, result: any, statusCode?: number) => void) => void;
export type TaskModuleFetchHandlerType = (event: builder.IEvent, request: task.ITaskModuleInvokeRequest, callback: (err: Error, result: task.ITaskModuleResponseOfFetch, statusCode?: number) => void) => void;
export type TaskModuleSubmitHandlerType = (event: builder.IEvent, request: task.ITaskModuleInvokeRequest, callback: (err: Error, result: task.ITaskModuleResponseOfSubmit, statusCode?: number) => void) => void;

export interface IInvokeEvent extends builder.IEvent {
name: string;
Expand All @@ -64,6 +67,8 @@ export class TeamsChatConnector extends builder.ChatConnector {
private static selectItemInvokeName = 'composeExtension/selectItem';
private static settingInvokeName = 'composeExtension/setting';
private static fileConsentInvokeName = 'fileConsent/invoke';
private static taskModuleInvokeNameOfFetch = task.taskModuleInvokeNameOfFetch;
private static taskModuleInvokeNameOfSubmit = task.taskModuleInvokeNameOfSubmit;

private allowedTenants: string[];

Expand All @@ -74,6 +79,8 @@ export class TeamsChatConnector extends builder.ChatConnector {
private settingsUpdateHandler: ComposeExtensionHandlerType;
private selectItemInvokeHandler: ComposeExtensionHandlerType;
private fileConsentCardResponseHandler: FileConsentCardResponseHandlerType;
private taskModuleFetchHandler: TaskModuleFetchHandlerType;
private taskModuleSubmitHandler: TaskModuleSubmitHandlerType;

constructor(settings: builder.IChatConnectorSettings = {}) {
super(settings)
Expand Down Expand Up @@ -343,6 +350,14 @@ export class TeamsChatConnector extends builder.ChatConnector {
this.fileConsentCardResponseHandler = handler;
}

public onTaskModuleFetch(handler: TaskModuleFetchHandlerType): void {
this.taskModuleFetchHandler = handler;
}

public onTaskModuleSubmit(handler: TaskModuleSubmitHandlerType): void {
this.taskModuleSubmitHandler = handler;
}

protected onDispatchEvents(events: builder.IEvent[], callback: (err: Error, body: any, status?: number) => void): void {
if (this.allowedTenants) {
var filteredEvents: builder.IEvent[] = [];
Expand Down Expand Up @@ -409,6 +424,18 @@ export class TeamsChatConnector extends builder.ChatConnector {
}
break;

case TeamsChatConnector.taskModuleInvokeNameOfFetch:
if (this.taskModuleFetchHandler) {
invokeHandler = this.taskModuleFetchHandler.bind(this);
}
break;

case TeamsChatConnector.taskModuleInvokeNameOfSubmit:
if (this.taskModuleSubmitHandler) {
invokeHandler = this.taskModuleSubmitHandler.bind(this);
}
break;

default:
// Generic invoke activity, defer to default handling of invoke activities
realEvents.push(event);
Expand Down
Loading

0 comments on commit fff9395

Please sign in to comment.