From 1380be6b2a93e8e107673d52db4b363a0f4dfcc5 Mon Sep 17 00:00:00 2001 From: stgum <14935595+stevengum@users.noreply.github.com> Date: Mon, 16 Dec 2019 12:41:30 -0800 Subject: [PATCH] move InvokeResponse, WebRequest, WebResponse interfaces into separate files --- .../botbuilder/src/botFrameworkAdapter.ts | 104 +----------------- .../botbuilder/src/botFrameworkHttpClient.ts | 3 +- .../botbuilder/src/channelServiceRoutes.ts | 6 +- libraries/botbuilder/src/index.ts | 8 +- libraries/botbuilder/src/interfaces/index.ts | 11 ++ .../src/interfaces/invokeResponse.ts | 24 ++++ .../botbuilder/src/interfaces/webRequest.ts | 51 +++++++++ .../botbuilder/src/interfaces/webResponse.ts | 47 ++++++++ .../botbuilder/src/skills/skillHttpClient.ts | 2 +- .../botbuilder/src/teamsActivityHandler.ts | 6 +- 10 files changed, 149 insertions(+), 113 deletions(-) create mode 100644 libraries/botbuilder/src/interfaces/index.ts create mode 100644 libraries/botbuilder/src/interfaces/invokeResponse.ts create mode 100644 libraries/botbuilder/src/interfaces/webRequest.ts create mode 100644 libraries/botbuilder/src/interfaces/webResponse.ts diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index d234df8d47..f0a7bc9417 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -13,6 +13,7 @@ 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 { InvokeResponse, WebRequest, WebResponse } from './interfaces'; import { StreamingHttpClient, TokenResolver } from './streaming'; export enum StatusCodes { @@ -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. */ @@ -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(); @@ -1459,4 +1359,4 @@ function abortWebSocketUpgrade(socket: INodeSocket, code: number) { } socket.destroy(); -} \ No newline at end of file +} diff --git a/libraries/botbuilder/src/botFrameworkHttpClient.ts b/libraries/botbuilder/src/botFrameworkHttpClient.ts index 9948e640b4..146060ba8d 100644 --- a/libraries/botbuilder/src/botFrameworkHttpClient.ts +++ b/libraries/botbuilder/src/botFrameworkHttpClient.ts @@ -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. diff --git a/libraries/botbuilder/src/channelServiceRoutes.ts b/libraries/botbuilder/src/channelServiceRoutes.ts index 915f33e4b2..ae91033f11 100644 --- a/libraries/botbuilder/src/channelServiceRoutes.ts +++ b/libraries/botbuilder/src/channelServiceRoutes.ts @@ -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; diff --git a/libraries/botbuilder/src/index.ts b/libraries/botbuilder/src/index.ts index 3c28badc6d..43245b10c5 100644 --- a/libraries/botbuilder/src/index.ts +++ b/libraries/botbuilder/src/index.ts @@ -9,18 +9,20 @@ 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 * from './teamsActivityHandler'; diff --git a/libraries/botbuilder/src/interfaces/index.ts b/libraries/botbuilder/src/interfaces/index.ts new file mode 100644 index 0000000000..067203f0d1 --- /dev/null +++ b/libraries/botbuilder/src/interfaces/index.ts @@ -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'; diff --git a/libraries/botbuilder/src/interfaces/invokeResponse.ts b/libraries/botbuilder/src/interfaces/invokeResponse.ts new file mode 100644 index 0000000000..02887f6481 --- /dev/null +++ b/libraries/botbuilder/src/interfaces/invokeResponse.ts @@ -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; +} diff --git a/libraries/botbuilder/src/interfaces/webRequest.ts b/libraries/botbuilder/src/interfaces/webRequest.ts new file mode 100644 index 0000000000..39785cb75f --- /dev/null +++ b/libraries/botbuilder/src/interfaces/webRequest.ts @@ -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; +} diff --git a/libraries/botbuilder/src/interfaces/webResponse.ts b/libraries/botbuilder/src/interfaces/webResponse.ts new file mode 100644 index 0000000000..d64896749a --- /dev/null +++ b/libraries/botbuilder/src/interfaces/webResponse.ts @@ -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; +} diff --git a/libraries/botbuilder/src/skills/skillHttpClient.ts b/libraries/botbuilder/src/skills/skillHttpClient.ts index 2ef87ce105..149396e200 100644 --- a/libraries/botbuilder/src/skills/skillHttpClient.ts +++ b/libraries/botbuilder/src/skills/skillHttpClient.ts @@ -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'; /** diff --git a/libraries/botbuilder/src/teamsActivityHandler.ts b/libraries/botbuilder/src/teamsActivityHandler.ts index 0afe46232c..ca93c5d778 100644 --- a/libraries/botbuilder/src/teamsActivityHandler.ts +++ b/libraries/botbuilder/src/teamsActivityHandler.ts @@ -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, @@ -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 {