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

Cleanup in botbuilder #1508

Merged
merged 3 commits into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
113 changes: 3 additions & 110 deletions libraries/botbuilder/src/botFrameworkAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { Activity, ActivityTypes, BotAdapter, BotCallbackHandlerKey, ChannelAcco
import { AuthenticationConfiguration, AuthenticationConstants, ChannelValidation, ClaimsIdentity, ConnectorClient, EmulatorApiClient, GovernmentConstants, GovernmentChannelValidation, JwtTokenValidation, MicrosoftAppCredentials, AppCredentials, CertificateAppCredentials, SimpleCredentialProvider, TokenApiClient, TokenStatus, TokenApiModels, SkillValidation } from 'botframework-connector';
import { INodeBuffer, INodeSocket, IReceiveRequest, ISocket, IStreamingTransportServer, NamedPipeServer, NodeWebSocketFactory, NodeWebSocketFactoryBase, RequestHandler, StreamingResponse, WebSocketServer } from 'botframework-streaming';

import { StreamingHttpClient, TokenResolver } from './streaming';
import { InvokeResponse, WebRequest, WebResponse } from './interfaces';
import { defaultPipeName, GET, POST, MESSAGES_PATH, StreamingHttpClient, TokenResolver, VERSION_PATH } from './streaming';

export enum StatusCodes {
OK = 200,
Expand All @@ -33,90 +34,6 @@ export class StatusCodeError extends Error {
}
}

/**
* Represents an Express or Restify request object.
*
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface WebRequest {
/**
* Optional. The request body.
*/
body?: any;

/***
* Optional. The request headers.
*/
headers: any;

/***
* Optional. The request method.
*/
method?: any;

/***
* Optional. The request parameters from the url.
*/
params?: any;

/***
* Optional. The values from the query string.
*/
query?: any;

/**
* When implemented in a derived class, adds a listener for an event.
* The framework uses this method to retrieve the request body when the
* [body](xref:botbuilder.WebRequest.body) property is `null` or `undefined`.
*
* @param event The event name.
* @param args Arguments used to handle the event.
*
* @returns A reference to the request object.
*/
on(event: string, ...args: any[]): any;
}

/**
* Represents an Express or Restify response object.
*
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface WebResponse {
/**
*
* Optional. The underlying socket.
*/
socket?: any;

/**
* When implemented in a derived class, sends a FIN packet.
*
* @param args The arguments for the end event.
*
* @returns A reference to the response object.
*/
end(...args: any[]): any;

/**
* When implemented in a derived class, sends the response.
*
* @param body The response payload.
*
* @returns A reference to the response object.
*/
send(body: any): any;

/**
* When implemented in a derived class, sets the HTTP status code for the response.
*
* @param status The status code to use.
*
* @returns The status code.
*/
status(status: number): any;
}

/**
* Contains settings used to configure a [BotFrameworkAdapter](xref:botbuilder.BotFrameworkAdapter) instance.
*/
Expand Down Expand Up @@ -172,23 +89,6 @@ export interface BotFrameworkAdapterSettings {
authConfig?: AuthenticationConfiguration;
}

/**
* Represents a response returned by a bot when it receives an `invoke` activity.
*
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface InvokeResponse {
/**
* The HTTP status code of the response.
*/
status: number;

/**
* Optional. The body of the response.
*/
body?: any;
}

// Retrieve additional information, i.e., host operating system, host OS release, architecture, Node.js version
const ARCHITECTURE: any = os.arch();
const TYPE: any = os.type();
Expand All @@ -202,13 +102,6 @@ export const USER_AGENT: string = `Microsoft-BotFramework/3.1 BotBuilder/${ pjso
const OAUTH_ENDPOINT = 'https://api.botframework.com';
const US_GOV_OAUTH_ENDPOINT = 'https://api.botframework.azure.us';

// Streaming-specific constants
const defaultPipeName = 'bfv4.pipes';
const VERSION_PATH: string = '/api/version';
const MESSAGES_PATH: string = '/api/messages';
const GET: string = 'GET';
const POST: string = 'POST';

// This key is exported internally so that the TeamsActivityHandler will not overwrite any already set InvokeResponses.
export const INVOKE_RESPONSE_KEY: symbol = Symbol('invokeResponse');

Expand Down Expand Up @@ -1459,4 +1352,4 @@ function abortWebSocketUpgrade(socket: INodeSocket, code: number) {
}

socket.destroy();
}
}
3 changes: 2 additions & 1 deletion libraries/botbuilder/src/botFrameworkHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
MicrosoftAppCredentials
} from 'botframework-connector';

import { InvokeResponse, USER_AGENT } from './botFrameworkAdapter';
import { USER_AGENT } from './botFrameworkAdapter';
import { InvokeResponse } from './interfaces';

/**
* HttpClient for calling skills from a Node.js BotBuilder V4 SDK bot.
Expand Down
6 changes: 4 additions & 2 deletions libraries/botbuilder/src/channelServiceRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
* Licensed under the MIT License.
*/

import { ChannelServiceHandler } from './channelServiceHandler';
import { Activity, ConversationParameters, Transcript, AttachmentData } from 'botbuilder-core';
import { WebRequest, WebResponse, StatusCodeError, StatusCodes } from './botFrameworkAdapter';

import { ChannelServiceHandler } from './channelServiceHandler';
import { StatusCodeError, StatusCodes } from './botFrameworkAdapter';
import { WebRequest, WebResponse } from './interfaces';

export type RouteHandler = (request: WebRequest, response: WebResponse) => void;

Expand Down
10 changes: 6 additions & 4 deletions libraries/botbuilder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@
export {
BotFrameworkAdapter,
BotFrameworkAdapterSettings,
InvokeResponse,
INVOKE_RESPONSE_KEY,
StatusCodes,
StatusCodeError,
WebRequest,
WebResponse
} from './botFrameworkAdapter';
export { BotFrameworkHttpClient } from './botFrameworkHttpClient';
export { ChannelServiceHandler } from './channelServiceHandler';
export { ChannelServiceRoutes, RouteHandler, WebServer } from './channelServiceRoutes';
export * from './fileTranscriptStore';
export * from './inspectionMiddleware';
export {
InvokeResponse,
WebRequest,
WebResponse
} from './interfaces';
export * from './skills';
export * from './streaming';
export { StreamingHttpClient, TokenResolver } from './streaming';
export * from './teamsActivityHandler';
export * from './teamsActivityHelpers';
export * from './teamsInfo';
Expand Down
11 changes: 11 additions & 0 deletions libraries/botbuilder/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

export * from './invokeResponse';
export * from './webRequest';
export * from './webResponse';
24 changes: 24 additions & 0 deletions libraries/botbuilder/src/interfaces/invokeResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

/**
* Represents a response returned by a bot when it receives an `invoke` activity.
*
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface InvokeResponse {
/**
* The HTTP status code of the response.
*/
status: number;

/**
* Optional. The body of the response.
*/
body?: any;
}
51 changes: 51 additions & 0 deletions libraries/botbuilder/src/interfaces/webRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

/**
* Represents an Express or Restify request object.
*
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface WebRequest {
/**
* Optional. The request body.
*/
body?: any;

/***
* Optional. The request headers.
*/
headers: any;

/***
* Optional. The request method.
*/
method?: any;

/***
* Optional. The request parameters from the url.
*/
params?: any;

/***
* Optional. The values from the query string.
*/
query?: any;

/**
* When implemented in a derived class, adds a listener for an event.
* The framework uses this method to retrieve the request body when the
* [body](xref:botbuilder.WebRequest.body) property is `null` or `undefined`.
*
* @param event The event name.
* @param args Arguments used to handle the event.
*
* @returns A reference to the request object.
*/
on(event: string, ...args: any[]): any;
}
47 changes: 47 additions & 0 deletions libraries/botbuilder/src/interfaces/webResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

/**
* Represents an Express or Restify response object.
*
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface WebResponse {
/**
*
* Optional. The underlying socket.
*/
socket?: any;

/**
* When implemented in a derived class, sends a FIN packet.
*
* @param args The arguments for the end event.
*
* @returns A reference to the response object.
*/
end(...args: any[]): any;

/**
* When implemented in a derived class, sends the response.
*
* @param body The response payload.
*
* @returns A reference to the response object.
*/
send(body: any): any;

/**
* When implemented in a derived class, sets the HTTP status code for the response.
*
* @param status The status code to use.
*
* @returns The status code.
*/
status(status: number): any;
}
2 changes: 1 addition & 1 deletion libraries/botbuilder/src/skills/skillHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
import { Activity, ConversationReference, TurnContext } from 'botbuilder-core';
import { ICredentialProvider } from 'botframework-connector';
import { InvokeResponse } from '../botFrameworkAdapter';
import { BotFrameworkHttpClient } from '../botFrameworkHttpClient';
import { BotFrameworkSkill } from './botFrameworkSkill';
import { InvokeResponse } from '../interfaces';
import { SkillConversationIdFactoryBase } from './skillConversationIdFactoryBase';

/**
Expand Down
13 changes: 13 additions & 0 deletions libraries/botbuilder/src/streaming/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

export const defaultPipeName = 'bfv4.pipes';
export const VERSION_PATH: string = '/api/version';
export const MESSAGES_PATH: string = '/api/messages';
export const GET: string = 'GET';
export const POST: string = 'POST';
1 change: 1 addition & 0 deletions libraries/botbuilder/src/streaming/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
* Licensed under the MIT License.
*/

export * from './constants';
export * from './streamingHttpClient';
export * from './tokenResolver';
6 changes: 2 additions & 4 deletions libraries/botbuilder/src/teamsActivityHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* Licensed under the MIT License.
*/

import { InvokeResponse, INVOKE_RESPONSE_KEY } from './botFrameworkAdapter';
import { INVOKE_RESPONSE_KEY } from './botFrameworkAdapter';

import {
ActivityHandler,
ActivityTypes,
AppBasedLinkQuery,
ChannelAccount,
ChannelInfo,
FileConsentCardResponse,
MessagingExtensionAction,
Expand All @@ -21,15 +20,14 @@ import {
MessagingExtensionResponse,
O365ConnectorCardActionQuery,
SigninStateVerificationQuery,
TaskModuleTaskInfo,
TaskModuleRequest,
TaskModuleResponse,
TaskModuleResponseBase,
TeamsChannelData,
TeamsChannelAccount,
TeamInfo,
TurnContext
} from 'botbuilder-core';
import { InvokeResponse } from './interfaces';
import { TeamsInfo } from './teamsInfo';

export class TeamsActivityHandler extends ActivityHandler {
Expand Down