From 463f2e299ff635aeb8af674379cfcd89694a3322 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Mon, 2 May 2022 11:30:03 -0300 Subject: [PATCH 1/4] Fix eslint issues in botbuilder-core (1/2) --- .../etc/botbuilder-core.api.md | 88 ++++++-------- libraries/botbuilder-core/package.json | 1 - .../botbuilder-core/src/activityFactory.ts | 31 +++-- .../botbuilder-core/src/activityHandler.ts | 113 ++++++------------ .../src/activityHandlerBase.ts | 77 ++++++------ .../botbuilder-core/src/adapterExtensions.ts | 2 + .../src/autoSaveStateMiddleware.ts | 4 + libraries/botbuilder-core/src/botAdapter.ts | 40 +++---- libraries/botbuilder-core/src/botState.ts | 10 +- .../src/botStatePropertyAccessor.ts | 11 +- libraries/botbuilder-core/src/botStateSet.ts | 7 +- .../botbuilder-core/src/botTelemetryClient.ts | 31 +++-- libraries/botbuilder-core/src/cardFactory.ts | 54 +++++---- .../botbuilder-core/src/cloudAdapterBase.ts | 7 +- .../src/componentRegistration.ts | 4 +- ...configurationBotFrameworkAuthentication.ts | 37 ++++++ .../botbuilder-core/src/conversationState.ts | 5 +- .../botbuilder-core/src/coreAppCredentials.ts | 5 +- .../src/extendedUserTokenProvider.ts | 11 +- .../botbuilder-core/src/invokeException.ts | 12 ++ .../botbuilder-core/src/memoryStorage.ts | 23 ++-- .../src/memoryTranscriptStore.ts | 10 +- .../botbuilder-core/src/messageFactory.ts | 6 + .../botbuilder-core/src/middlewareSet.ts | 15 ++- .../src/privateConversationState.ts | 5 +- .../botbuilder-core/src/propertyManager.ts | 1 + .../botbuilder-core/src/recognizerResult.ts | 3 +- .../src/registerClassMiddleware.ts | 4 +- .../src/showTypingMiddleware.ts | 2 + .../src/skills/skillConversationIdFactory.ts | 26 ++++ .../skills/skillConversationIdFactoryBase.ts | 33 ++--- .../src/skypeMentionNormalizeMiddleware.ts | 2 + libraries/botbuilder-core/src/stringUtils.ts | 5 + .../src/telemetryLoggerMiddleware.ts | 20 +++- libraries/botbuilder-core/src/testAdapter.ts | 104 ++++++++++++---- .../botbuilder-core/src/transcriptLogger.ts | 13 ++ libraries/botbuilder-core/src/turnContext.ts | 69 ++++++----- .../src/turnContextStateCollection.ts | 13 +- libraries/botbuilder-core/src/userState.ts | 5 +- .../botbuilder-core/src/userTokenProvider.ts | 7 +- 40 files changed, 577 insertions(+), 339 deletions(-) diff --git a/libraries/botbuilder-core/etc/botbuilder-core.api.md b/libraries/botbuilder-core/etc/botbuilder-core.api.md index ef14a50002..30e75d77e7 100644 --- a/libraries/botbuilder-core/etc/botbuilder-core.api.md +++ b/libraries/botbuilder-core/etc/botbuilder-core.api.md @@ -67,7 +67,7 @@ export class ActivityHandler extends ActivityHandlerBase { [type: string]: BotHandler[]; }; protected on(type: string, handler: BotHandler): this; - protected onAdaptiveCardInvoke(context: TurnContext, invokeValue: AdaptiveCardInvokeValue): Promise; + protected onAdaptiveCardInvoke(_context: TurnContext, _invokeValue: AdaptiveCardInvokeValue): Promise; onCommand(handler: BotHandler): this; protected onCommandActivity(context: TurnContext): Promise; onCommandResult(handler: BotHandler): this; @@ -96,8 +96,8 @@ export class ActivityHandler extends ActivityHandlerBase { protected onReactionsAddedActivity(reactionsAdded: MessageReaction[], context: TurnContext): Promise; onReactionsRemoved(handler: BotHandler): this; protected onReactionsRemovedActivity(reactionsRemoved: MessageReaction[], context: TurnContext): Promise; - protected onSearchInvoke(context: TurnContext, invokeValue: SearchInvokeValue): Promise; - protected onSignInInvoke(context: TurnContext): Promise; + protected onSearchInvoke(_context: TurnContext, _invokeValue: SearchInvokeValue): Promise; + protected onSignInInvoke(_context: TurnContext): Promise; onTokenResponseEvent(handler: BotHandler): this; onTurn(handler: BotHandler): this; protected onTurnActivity(context: TurnContext): Promise; @@ -110,24 +110,24 @@ export class ActivityHandler extends ActivityHandlerBase { // @public export class ActivityHandlerBase { - protected onCommandActivity(context: TurnContext): Promise; - protected onCommandResultActivity(context: TurnContext): Promise; + protected onCommandActivity(_context: TurnContext): Promise; + protected onCommandResultActivity(_context: TurnContext): Promise; protected onConversationUpdateActivity(context: TurnContext): Promise; - protected onEndOfConversationActivity(context: TurnContext): Promise; - protected onEventActivity(context: TurnContext): Promise; + protected onEndOfConversationActivity(_context: TurnContext): Promise; + protected onEventActivity(_context: TurnContext): Promise; protected onInstallationUpdateActivity(context: TurnContext): Promise; - protected onInstallationUpdateAddActivity(context: TurnContext): Promise; - protected onInstallationUpdateRemoveActivity(context: TurnContext): Promise; - protected onInvokeActivity(context: TurnContext): Promise; - protected onMembersAddedActivity(membersAdded: ChannelAccount[], context: TurnContext): Promise; - protected onMembersRemovedActivity(membersRemoved: ChannelAccount[], context: TurnContext): Promise; - protected onMessageActivity(context: TurnContext): Promise; + protected onInstallationUpdateAddActivity(_context: TurnContext): Promise; + protected onInstallationUpdateRemoveActivity(_context: TurnContext): Promise; + protected onInvokeActivity(_context: TurnContext): Promise; + protected onMembersAddedActivity(_membersAdded: ChannelAccount[], _context: TurnContext): Promise; + protected onMembersRemovedActivity(_membersRemoved: ChannelAccount[], _context: TurnContext): Promise; + protected onMessageActivity(_context: TurnContext): Promise; protected onMessageReactionActivity(context: TurnContext): Promise; - protected onReactionsAddedActivity(reactionsAdded: MessageReaction[], context: TurnContext): Promise; - protected onReactionsRemovedActivity(reactionsRemoved: MessageReaction[], context: TurnContext): Promise; + protected onReactionsAddedActivity(_reactionsAdded: MessageReaction[], _context: TurnContext): Promise; + protected onReactionsRemovedActivity(_reactionsRemoved: MessageReaction[], _context: TurnContext): Promise; protected onTurnActivity(context: TurnContext): Promise; - protected onTypingActivity(context: TurnContext): Promise; - protected onUnrecognizedActivity(context: TurnContext): Promise; + protected onTypingActivity(_context: TurnContext): Promise; + protected onUnrecognizedActivity(_context: TurnContext): Promise; run(context: TurnContext): Promise; } @@ -159,7 +159,7 @@ export abstract class BotAdapter { continueConversationAsync(botAppId: string, reference: Partial, logic: (context: TurnContext) => Promise): Promise; continueConversationAsync(claimsIdentity: ClaimsIdentity, reference: Partial, logic: (context: TurnContext) => Promise): Promise; continueConversationAsync(claimsIdentity: ClaimsIdentity, reference: Partial, audience: string, logic: (context: TurnContext) => Promise): Promise; - createConversationAsync(botAppId: string, channelId: string, serviceUrl: string, audience: string, conversationParameters: ConversationParameters, logic: (context: TurnContext) => Promise): Promise; + createConversationAsync(_botAppId: string, _channelId: string, _serviceUrl: string, _audience: string, _conversationParameters: ConversationParameters, _logic: (context: TurnContext) => Promise): Promise; abstract deleteActivity(context: TurnContext, reference: Partial): Promise; // (undocumented) protected middleware: MiddlewareSet; @@ -299,7 +299,7 @@ export class CardFactory { static videoCard(title: string, media: (MediaUrl | string)[], buttons?: (CardAction | string)[], other?: Partial): Attachment; } -// @public (undocumented) +// @public export abstract class CloudAdapterBase extends BotAdapter { constructor(botFrameworkAuthentication: BotFrameworkAuthentication); // (undocumented) @@ -307,7 +307,7 @@ export abstract class CloudAdapterBase extends BotAdapter { // (undocumented) readonly ConnectorFactoryKey: symbol; // @deprecated (undocumented) - continueConversation(reference: Partial, logic: (context: TurnContext) => Promise): Promise; + continueConversation(_reference: Partial, _logic: (context: TurnContext) => Promise): Promise; // @internal (undocumented) continueConversationAsync(botAppIdOrClaimsIdentity: string | ClaimsIdentity, reference: Partial, logicOrAudience: ((context: TurnContext) => Promise) | string, maybeLogic?: (context: TurnContext) => Promise): Promise; protected createClaimsIdentity(botAppId?: string): ClaimsIdentity; @@ -335,17 +335,11 @@ export class ComponentRegistration { // @public export class ConfigurationBotFrameworkAuthentication extends BotFrameworkAuthentication { constructor(botFrameworkAuthConfig?: ConfigurationBotFrameworkAuthenticationOptions, credentialsFactory?: ServiceClientCredentialsFactory, authConfiguration?: AuthenticationConfiguration, botFrameworkClientFetch?: (input: RequestInfo, init?: RequestInit) => Promise, connectorClientOptions?: ConnectorClientOptions); - // (undocumented) authenticateChannelRequest(authHeader: string): Promise; - // (undocumented) authenticateRequest(activity: Activity, authHeader: string): Promise; - // (undocumented) authenticateStreamingRequest(authHeader: string, channelIdHeader: string): Promise; - // (undocumented) createBotFrameworkClient(): BotFrameworkClient; - // (undocumented) createConnectorFactory(claimsIdentity: ClaimsIdentity): ConnectorFactory; - // (undocumented) createUserTokenClient(claimsIdentity: ClaimsIdentity): Promise; } @@ -396,7 +390,7 @@ export function createServiceClientCredentialFactoryFromConfiguration(configurat // @public export type DeleteActivityHandler = (context: TurnContext, reference: Partial, next: () => Promise) => Promise; -// @public +// @public @deprecated export interface ExtendedUserTokenProvider extends IUserTokenProvider { exchangeToken(context: TurnContext, connectionName: string, userId: string, tokenExchangeRequest: TokenExchangeRequest): Promise; exchangeToken(context: TurnContext, connectionName: string, userId: string, tokenExchangeRequest: TokenExchangeRequest, appCredentials: CoreAppCredentials): Promise; @@ -426,16 +420,15 @@ export interface IntentScore { // @public (undocumented) export const INVOKE_RESPONSE_KEY: unique symbol; -// @public (undocumented) +// @public export class InvokeException extends Error { constructor(status: StatusCodes, response?: T); - // (undocumented) createInvokeResponse(): InvokeResponse; } export { InvokeResponse } -// @public +// @public @deprecated export interface IUserTokenProvider { getAadTokens(context: TurnContext, connectionName: string, resourceUrls: string[]): Promise<{ [propertyName: string]: TokenResponse; @@ -498,13 +491,13 @@ export class MiddlewareSet implements Middleware { // @public export class NullTelemetryClient implements BotTelemetryClient, BotPageViewTelemetryClient { - constructor(settings?: any); + constructor(_settings?: any); flush(): void; - trackDependency(telemetry: TelemetryDependency): void; - trackEvent(telemetry: TelemetryEvent): void; - trackException(telemetry: TelemetryException): void; - trackPageView(telemetry: TelemetryPageView): void; - trackTrace(telemetry: TelemetryTrace): void; + trackDependency(_telemetry: TelemetryDependency): void; + trackEvent(_telemetry: TelemetryEvent): void; + trackException(_telemetry: TelemetryException): void; + trackPageView(_telemetry: TelemetryPageView): void; + trackTrace(_telemetry: TelemetryTrace): void; } // @public @@ -574,26 +567,23 @@ export class ShowTypingMiddleware implements Middleware { onTurn(context: TurnContext, next: () => Promise): Promise; } -// @public (undocumented) +// @public export class SkillConversationIdFactory extends SkillConversationIdFactoryBase { constructor(storage: Storage_2); - // (undocumented) createSkillConversationIdWithOptions(options: SkillConversationIdFactoryOptions): Promise; - // (undocumented) deleteConversationReference(skillConversationId: string): Promise; - // (undocumented) getSkillConversationReference(skillConversationId: string): Promise; } // @public export abstract class SkillConversationIdFactoryBase { // @deprecated - createSkillConversationId(conversationReference: ConversationReference): Promise; - createSkillConversationIdWithOptions(options: SkillConversationIdFactoryOptions): Promise; + createSkillConversationId(_conversationReference: ConversationReference): Promise; + createSkillConversationIdWithOptions(_options: SkillConversationIdFactoryOptions): Promise; abstract deleteConversationReference(skillConversationId: string): Promise; // @deprecated - getConversationReference(skillConversationId: string): Promise; - getSkillConversationReference(skillConversationId: string): Promise; + getConversationReference(_skillConversationId: string): Promise; + getSkillConversationReference(_skillConversationId: string): Promise; } // @public (undocumented) @@ -773,7 +763,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider get activityBuffer(): Partial[]; addExchangeableToken(connectionName: string, channelId: string, userId: string, exchangeableItem: string, token: string): void; addUserToken(connectionName: string, channelId: string, userId: string, token: string, magicCode?: string): void; - continueConversation(reference: Partial, logic: (revocableContext: TurnContext) => Promise): Promise; + continueConversation(_reference: Partial, _logic: (revocableContext: TurnContext) => Promise): Promise; conversation: ConversationReference; protected createContext(request: Partial): TurnContext; static createConversation(name: string, user?: string, bot?: string): ConversationReference; @@ -782,13 +772,13 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider // Warning: (ae-setter-with-docs) The doc comment for the property "enableTrace" must appear on the getter, not the setter. set enableTrace(value: boolean); exchangeToken(context: TurnContext, connectionName: string, userId: string, tokenExchangeRequest: TokenExchangeRequest): Promise; - getAadTokens(context: TurnContext, connectionName: string, resourceUrls: string[]): Promise<{ + getAadTokens(_context: TurnContext, _connectionName: string, _resourceUrls: string[]): Promise<{ [propertyName: string]: TokenResponse; }>; getNextReply(): Partial; getSignInLink(context: TurnContext, connectionName: string): Promise; - getSignInResource(context: TurnContext, connectionName: string, userId?: string, finalRedirect?: string): Promise; - getTokenStatus(context: TurnContext, userId: string, includeFilter?: string, oAuthAppCredentials?: any): Promise; + getSignInResource(context: TurnContext, connectionName: string, userId?: string, _finalRedirect?: string): Promise; + getTokenStatus(context: TurnContext, userId: string, includeFilter?: string, _oAuthAppCredentials?: any): Promise; getUserToken(context: TurnContext, connectionName: string, magicCode?: string): Promise; locale: string; makeActivity(text?: string): Partial; @@ -799,7 +789,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider sendTextToBot(userSays: string, callback: (context: TurnContext) => Promise): Promise; signOutUser(context: TurnContext, connectionName?: string, userId?: string): Promise; readonly template: Partial; - test(userSays: string | Partial, expected: string | Partial | ((activity: Partial, description?: string) => void), description?: string, timeout?: number): TestFlow; + test(userSays: string | Partial, expected: string | Partial | ((activity: Partial, description?: string) => void), description?: string, _timeout?: number): TestFlow; testActivities(activities: Partial[], description?: string, timeout?: number): TestFlow; throwOnExchangeRequest(connectionName: string, channelId: string, userId: string, exchangeableItem: string): void; updateActivity(context: TurnContext, activity: Partial): Promise; diff --git a/libraries/botbuilder-core/package.json b/libraries/botbuilder-core/package.json index c555930b2f..7de1873ab6 100644 --- a/libraries/botbuilder-core/package.json +++ b/libraries/botbuilder-core/package.json @@ -36,7 +36,6 @@ }, "devDependencies": { "chatdown": "^1.2.4", - "lodash": "^4.17.20", "request": "^2.88.2", "unzipper": "^0.10.9" }, diff --git a/libraries/botbuilder-core/src/activityFactory.ts b/libraries/botbuilder-core/src/activityFactory.ts index 3d54bf83a7..531965e5fc 100644 --- a/libraries/botbuilder-core/src/activityFactory.ts +++ b/libraries/botbuilder-core/src/activityFactory.ts @@ -115,7 +115,9 @@ export class ActivityFactory { /** * Generate the activity. + * * @param lgResult string result from languageGenerator. + * @returns The generated MessageActivity. */ public static fromObject(lgResult: any): Partial { if (lgResult == null) { @@ -135,7 +137,9 @@ export class ActivityFactory { /** * Given a lg result, create a text activity. This method will create a MessageActivity from text. + * * @param text lg text output. + * @returns The created MessageActivity. */ private static buildActivityFromText(text: string): Partial { const msg: Partial = { @@ -152,7 +156,9 @@ export class ActivityFactory { /** * Given a structured lg result, create an activity. This method will create an MessageActivity from object + * * @param lgValue lg output. + * @returns The created MessageActivity. */ private static buildActivityFromLGStructuredResult(lgValue: any): Partial { let activity: Partial = {}; @@ -171,6 +177,7 @@ export class ActivityFactory { /** * Builds an [Activity](xref:botframework-schema.Activity) with a given message. + * * @param messageValue Message value on which to base the activity. * @returns [Activity](xref:botframework-schema.Activity) with the given message. */ @@ -312,7 +319,7 @@ export class ActivityFactory { const value: any = input[key]; switch (property.toLowerCase()) { - case 'contenttype': + case 'contenttype': { const type: string = value.toString().toLowerCase(); if (this.genericCardTypeMapping.has(type)) { attachment.contentType = this.genericCardTypeMapping.get(type); @@ -322,9 +329,11 @@ export class ActivityFactory { attachment.contentType = type; } break; - default: + } + default: { attachment[this.realProperty(property, this.attachmentProperties)] = value; break; + } } } @@ -342,11 +351,12 @@ export class ActivityFactory { const value: any = input[key]; switch (property) { - case 'tap': + case 'tap': { card[property] = this.getCardAction(value); break; + } case 'image': - case 'images': + case 'images': { if (type === CardFactory.contentTypes.heroCard || type === CardFactory.contentTypes.thumbnailCard) { if (!('images' in card)) { card['images'] = []; @@ -358,7 +368,8 @@ export class ActivityFactory { card['image'] = this.normalizedToMediaOrImage(value); } break; - case 'media': + } + case 'media': { if (!('media' in card)) { card['media'] = []; } @@ -366,7 +377,8 @@ export class ActivityFactory { const mediaList = this.normalizedToList(value); mediaList.forEach((u): any => card['media'].push(this.normalizedToMediaOrImage(u))); break; - case 'buttons': + } + case 'buttons': { if (!('buttons' in card)) { card['buttons'] = []; } @@ -374,9 +386,10 @@ export class ActivityFactory { const buttons: any[] = this.getButtons(value); buttons.forEach((u): any => card[property].push(u)); break; + } case 'autostart': case 'shareable': - case 'autoloop': + case 'autoloop': { const boolValue: boolean = this.getValidBooleanValue(value.toString()); if (boolValue !== undefined) { card[property] = boolValue; @@ -384,9 +397,11 @@ export class ActivityFactory { card[property] = value; } break; - default: + } + default: { card[this.realProperty(key.trim(), this.cardProperties)] = value; break; + } } } diff --git a/libraries/botbuilder-core/src/activityHandler.ts b/libraries/botbuilder-core/src/activityHandler.ts index 41ed3efeac..96b9a72816 100644 --- a/libraries/botbuilder-core/src/activityHandler.ts +++ b/libraries/botbuilder-core/src/activityHandler.ts @@ -98,9 +98,7 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _turn_ event, emitted for every incoming activity, regardless of type. * * @param handler The event handler. - * - * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. */ public onTurn(handler: BotHandler): this { return this.on('Turn', handler); @@ -110,10 +108,8 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _message_ event, emitted for every incoming message activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * Message activities represent content intended to be shown within a conversational interface * and can contain text, speech, interactive cards, and binary or unknown attachments. * Not all message activities contain text, the activity's [text](xref:botframework-schema.Activity.text) @@ -128,10 +124,8 @@ export class ActivityHandler extends ActivityHandlerBase { * conversation update activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * Conversation update activities describe a changes to a conversation's metadata, such as title, participants, * or other channel-specific information. * @@ -148,10 +142,8 @@ export class ActivityHandler extends ActivityHandlerBase { * conversation update activity that includes members added to the conversation. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * The activity's [membersAdded](xref:botframework-schema.Activity.membersAdded) property * contains the members added to the conversation, which can include the bot. * @@ -167,10 +159,8 @@ export class ActivityHandler extends ActivityHandlerBase { * conversation update activity that includes members removed from the conversation. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * The activity's [membersRemoved](xref:botframework-schema.Activity.membersRemoved) property * contains the members removed from the conversation, which can include the bot. * @@ -186,10 +176,8 @@ export class ActivityHandler extends ActivityHandlerBase { * message reaction activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * Message reaction activities represent a social interaction on an existing message activity * within a conversation. The original activity is referred to by the message reaction activity's * [replyToId](xref:botframework-schema.Activity.replyToId) property. The @@ -209,10 +197,8 @@ export class ActivityHandler extends ActivityHandlerBase { * message reaction activity that describes reactions added to a message. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * The activity's [reactionsAdded](xref:botframework-schema.Activity.reactionsAdded) property * includes one or more reactions that were added. * @@ -228,10 +214,8 @@ export class ActivityHandler extends ActivityHandlerBase { * message reaction activity that describes reactions removed from a message. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * The activity's [reactionsRemoved](xref:botframework-schema.Activity.reactionsRemoved) property * includes one or more reactions that were removed. * @@ -246,10 +230,8 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _event_ event, emitted for every incoming event activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * Event activities communicate programmatic information from a client or channel to a bot. * The meaning of an event activity is defined by the activity's * [name](xref:botframework-schema.Activity.name) property, which is meaningful within the scope @@ -269,10 +251,8 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _end of conversation_ activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * This activity is typically send from a Skill to a Skill caller indicating the end of that particular child conversation. * * To handle an End of Conversation, use the @@ -286,10 +266,8 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _typing_ activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * To handle a Typing event, use the * [onTyping](xref:botbuilder-core.ActivityHandler.onTyping) type-specific event handler. */ @@ -301,10 +279,8 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _installationupdate_ activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * To handle a InstallationUpdate event, use the * [onInstallationUpdate](xref:botbuilder-core.ActivityHandler.onInstallationUpdate) type-specific event handler. */ @@ -316,10 +292,7 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _installationupdate add_ activity. * * @param handler The event handler. - * - * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * To handle a InstallationUpdateAdd event, use the * [onInstallationUpdateAdd](xref:botbuilder-core.ActivityHandler.onInstallationUpdateAdd) type-specific event handler. */ @@ -331,10 +304,8 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _installationupdate remove_ activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * To handle a InstallationUpdateRemove event, use the * [onInstallationUpdateRemove](xref:botbuilder-core.ActivityHandler.onInstallationUpdateRemove) type-specific event handler. */ @@ -347,10 +318,8 @@ export class ActivityHandler extends ActivityHandlerBase { * `tokens/response` event activity. These are generated as part of the OAuth authentication flow. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * The activity's [value](xref:botframework-schema.Activity.value) property contains the user token. * * If your bot handles authentication using an [OAuthPrompt](xref:botbuilder-dialogs.OAuthPrompt) @@ -367,10 +336,8 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _command_ activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * To handle a Command event, use the * [onCommand](xref:botbuilder-core.ActivityHandler.onCommand) type-specific event handler. */ @@ -382,10 +349,8 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _CommandResult_ activity. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * To handle a CommandResult event, use the * [onCommandResult](xref:botbuilder-core.ActivityHandler.onCommandResult) type-specific event handler. */ @@ -399,10 +364,8 @@ export class ActivityHandler extends ActivityHandlerBase { * doesn't provide an event handler. * * @param handler The event handler. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * * The `ActivityHandler` does not define events for all activity types defined in the * [Bot Framework Activity schema](http://aka.ms/botSpecs-activitySchema). In addition, * channels and custom adapters can create [Activities](xref:botframework-schema.Activity) with @@ -418,10 +381,7 @@ export class ActivityHandler extends ActivityHandlerBase { * Registers an activity event handler for the _dialog_ event, emitted as the last event for an incoming activity. * * @param handler The event handler. - * - * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. - * + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. */ public onDialog(handler: BotHandler): this { return this.on('Dialog', handler); @@ -489,8 +449,9 @@ export class ActivityHandler extends ActivityHandlerBase { /** * Provides default behavior for invoke activities. - * @param context The context object for the current turn. * + * @param context The context object for the current turn. + * @returns {Promise} An Invoke Response for the activity. * @remarks * Override this method to support channel-specific behavior across multiple channels. * The default logic is to check for a signIn invoke and handle that @@ -537,24 +498,25 @@ export class ActivityHandler extends ActivityHandlerBase { /** * Handle _signin invoke activity type_. * - * @param context The context object for the current turn. + * @param _context The context object for the current turn. * * @remarks * Override this method to support channel-specific behavior across multiple channels. */ - protected async onSignInInvoke(context: TurnContext): Promise { + protected async onSignInInvoke(_context: TurnContext): Promise { throw new InvokeException(StatusCodes.NOT_IMPLEMENTED); } /** * Invoked when the bot is sent an Adaptive Card Action Execute. * - * @param context the context object for the current turn - * @param invokeValue incoming activity value + * @param _context the context object for the current turn + * @param _invokeValue incoming activity value + * @returns {Promise} An Adaptive Card Invoke Response for the activity. */ protected onAdaptiveCardInvoke( - context: TurnContext, - invokeValue: AdaptiveCardInvokeValue + _context: TurnContext, + _invokeValue: AdaptiveCardInvokeValue ): Promise { return Promise.reject(new InvokeException(StatusCodes.NOT_IMPLEMENTED)); } @@ -562,13 +524,11 @@ export class ActivityHandler extends ActivityHandlerBase { /** * Invoked when the bot is sent an invoke activity with name of 'application/search'. * - * @param context the context object for the current turn - * @param invokeValue incoming activity value + * @param _context the context object for the current turn. + * @param _invokeValue incoming activity value. + * @returns {Promise} A Search Invoke Response for the activity. */ - protected onSearchInvoke( - context: TurnContext, - invokeValue: SearchInvokeValue - ): Promise { + protected onSearchInvoke(_context: TurnContext, _invokeValue: SearchInvokeValue): Promise { return Promise.reject(new InvokeException(StatusCodes.NOT_IMPLEMENTED)); } @@ -974,7 +934,7 @@ export class ActivityHandler extends ActivityHandlerBase { * Called at the end of the event emission process. * * @param context The context object for the current turn. - * + * @returns {Promise} A promise representing the async operation. * @remarks * Override this method to use custom logic for emitting events. * @@ -995,9 +955,7 @@ export class ActivityHandler extends ActivityHandlerBase { * * @param type The identifier for the event type. * @param handler The event handler to register. - * - * @remarks - * Returns a reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. + * @returns A reference to the [ActivityHandler](xref:botbuilder-core.ActivityHandler) object. */ protected on(type: string, handler: BotHandler) { if (!this.handlers[type]) { @@ -1014,7 +972,7 @@ export class ActivityHandler extends ActivityHandlerBase { * @param context The context object for the current turn. * @param type The identifier for the event type. * @param onNext The continuation function to call after all registered handlers for this event complete. - * + * @returns {Promise} The handler's return value. * @remarks * Runs any registered handlers for this event type and then calls the continuation function. * @@ -1048,6 +1006,7 @@ export class ActivityHandler extends ActivityHandlerBase { /** * An [InvokeResponse](xref:botbuilder.InvokeResponse) factory that initializes the body to the parameter passed and status equal to OK. + * * @param body JSON serialized content from a POST response. * @returns A new [InvokeResponse](xref:botbuilder.InvokeResponse) object. */ diff --git a/libraries/botbuilder-core/src/activityHandlerBase.ts b/libraries/botbuilder-core/src/activityHandlerBase.ts index 5565208904..e9458b9cc2 100644 --- a/libraries/botbuilder-core/src/activityHandlerBase.ts +++ b/libraries/botbuilder-core/src/activityHandlerBase.ts @@ -62,13 +62,14 @@ export class ActivityHandlerBase { case ActivityTypes.Event: await this.onEventActivity(context); break; - case ActivityTypes.Invoke: + case ActivityTypes.Invoke: { const invokeResponse = await this.onInvokeActivity(context); // If onInvokeActivity has already sent an InvokeResponse, do not send another one. if (invokeResponse && !context.turnState.get(INVOKE_RESPONSE_KEY)) { await context.sendActivity({ value: invokeResponse, type: 'invokeResponse' }); } break; + } case ActivityTypes.EndOfConversation: await this.onEndOfConversationActivity(context); break; @@ -94,13 +95,13 @@ export class ActivityHandlerBase { /** * Provides a hook for emitting the _message_ event. * - * @param context The context object for the current turn. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _message_ handlers and then continue the event * emission process. */ - protected async onMessageActivity(context: TurnContext): Promise { + protected async onMessageActivity(_context: TurnContext): Promise { return; } @@ -167,51 +168,51 @@ export class ActivityHandlerBase { /** * Provides a hook for emitting the _event_ event. * - * @param context The context object for the current turn. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _event_ handlers and then continue the event * emission process. */ - protected async onEventActivity(context: TurnContext): Promise { + protected async onEventActivity(_context: TurnContext): Promise { return; } /** * Provides a hook for invoke calls. * - * @param context The context object for the current turn. - * + * @param _context The context object for the current turn. + * @returns {Promise} An Invoke Response for the activity. * @remarks * Override this method to handle particular invoke calls. */ - protected async onInvokeActivity(context: TurnContext): Promise { + protected async onInvokeActivity(_context: TurnContext): Promise { return { status: StatusCodes.NOT_IMPLEMENTED }; } /** * Provides a hook for emitting the _end of conversation_ event. * - * @param context The context object for the current turn. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _end of conversation_ handlers and then continue the event * emission process. */ - protected async onEndOfConversationActivity(context: TurnContext): Promise { + protected async onEndOfConversationActivity(_context: TurnContext): Promise { return; } /** * Provides a hook for emitting the _typing_ event. * - * @param context The context object for the current turn. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _typing_ handlers and then continue the event * emission process. */ - protected async onTypingActivity(context: TurnContext): Promise { + protected async onTypingActivity(_context: TurnContext): Promise { return; } @@ -240,39 +241,39 @@ export class ActivityHandlerBase { /** * Provides a hook for emitting the _installationupdateadd_ event. * - * @param context The context object for the current turn. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _installationupdateadd_ handlers and then continue the event * emission process. */ - protected async onInstallationUpdateAddActivity(context: TurnContext): Promise { + protected async onInstallationUpdateAddActivity(_context: TurnContext): Promise { return; } /** * Provides a hook for emitting the _installationupdateremove_ event. * - * @param context The context object for the current turn. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _installationupdateremove_ handlers and then continue the event * emission process. */ - protected async onInstallationUpdateRemoveActivity(context: TurnContext): Promise { + protected async onInstallationUpdateRemoveActivity(_context: TurnContext): Promise { return; } /** * Provides a hook for emitting the _unrecognized_ event. * - * @param context The context object for the current turn. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _unrecognized_ handlers and then continue the event * emission process. */ - protected async onUnrecognizedActivity(context: TurnContext): Promise { + protected async onUnrecognizedActivity(_context: TurnContext): Promise { return; } @@ -280,14 +281,14 @@ export class ActivityHandlerBase { * Provides a hook for emitting the _members added_ event, * a sub-type of the _conversation update_ event. * - * @param membersAdded An array of the members added to the conversation. - * @param context The context object for the current turn. + * @param _membersAdded An array of the members added to the conversation. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _members added_ handlers and then continue the event * emission process. */ - protected async onMembersAddedActivity(membersAdded: ChannelAccount[], context: TurnContext): Promise { + protected async onMembersAddedActivity(_membersAdded: ChannelAccount[], _context: TurnContext): Promise { return; } @@ -295,14 +296,14 @@ export class ActivityHandlerBase { * Provides a hook for emitting the _members removed_ event, * a sub-type of the _conversation update_ event. * - * @param membersRemoved An array of the members removed from the conversation. - * @param context The context object for the current turn. + * @param _membersRemoved An array of the members removed from the conversation. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _members removed_ handlers and then continue the event * emission process. */ - protected async onMembersRemovedActivity(membersRemoved: ChannelAccount[], context: TurnContext): Promise { + protected async onMembersRemovedActivity(_membersRemoved: ChannelAccount[], _context: TurnContext): Promise { return; } @@ -310,14 +311,14 @@ export class ActivityHandlerBase { * Provides a hook for emitting the _reactions added_ event, * a sub-type of the _message reaction_ event. * - * @param reactionsAdded An array of the reactions added to a message. - * @param context The context object for the current turn. + * @param _reactionsAdded An array of the reactions added to a message. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _reactions added_ handlers and then continue the event * emission process. */ - protected async onReactionsAddedActivity(reactionsAdded: MessageReaction[], context: TurnContext): Promise { + protected async onReactionsAddedActivity(_reactionsAdded: MessageReaction[], _context: TurnContext): Promise { return; } @@ -325,16 +326,16 @@ export class ActivityHandlerBase { * Provides a hook for emitting the _reactions removed_ event, * a sub-type of the _message reaction_ event. * - * @param reactionsRemoved An array of the reactions removed from a message. - * @param context The context object for the current turn. + * @param _reactionsRemoved An array of the reactions removed from a message. + * @param _context The context object for the current turn. * * @remarks * Override this method to run registered _reactions removed_ handlers and then continue the event * emission process. */ protected async onReactionsRemovedActivity( - reactionsRemoved: MessageReaction[], - context: TurnContext + _reactionsRemoved: MessageReaction[], + _context: TurnContext ): Promise { return; } @@ -346,10 +347,10 @@ export class ActivityHandlerBase { * one or more commandResult activities. Receivers are also expected to explicitly * reject unsupported command activities. * - * @param context A context object for this turn. + * @param _context A context object for this turn. * @returns A promise that represents the work queued to execute. */ - protected async onCommandActivity(context: TurnContext): Promise { + protected async onCommandActivity(_context: TurnContext): Promise { return; } @@ -358,10 +359,10 @@ export class ActivityHandlerBase { * `onTurn()` is used. * CommandResult activity can be used to communicate the result of a command execution. * - * @param context A context object for this turn. + * @param _context A context object for this turn. * @returns A promise that represents the work queued to execute. */ - protected async onCommandResultActivity(context: TurnContext): Promise { + protected async onCommandResultActivity(_context: TurnContext): Promise { return; } @@ -390,15 +391,15 @@ export class ActivityHandlerBase { */ public async run(context: TurnContext): Promise { if (!context) { - throw new Error(`Missing TurnContext parameter`); + throw new Error('Missing TurnContext parameter'); } if (!context.activity) { - throw new Error(`TurnContext does not include an activity`); + throw new Error('TurnContext does not include an activity'); } if (!context.activity.type) { - throw new Error(`Activity is missing its type`); + throw new Error('Activity is missing its type'); } // List of all Activity Types: diff --git a/libraries/botbuilder-core/src/adapterExtensions.ts b/libraries/botbuilder-core/src/adapterExtensions.ts index f312b4e476..b4f6b86d4e 100644 --- a/libraries/botbuilder-core/src/adapterExtensions.ts +++ b/libraries/botbuilder-core/src/adapterExtensions.ts @@ -13,8 +13,10 @@ import { RegisterClassMiddleware } from './registerClassMiddleware'; /** * Adds middleware to the adapter to register one or more BotState objects on the turn context. * The middleware registers the state objects on the turn context at the start of each turn. + * * @param botAdapter The adapter on which to register the state objects. * @param botStates The state objects to register. + * @returns The updated adapter. */ export function useBotState(botAdapter: BotAdapter, ...botStates: BotState[]): BotAdapter { for (const botState of botStates) { diff --git a/libraries/botbuilder-core/src/autoSaveStateMiddleware.ts b/libraries/botbuilder-core/src/autoSaveStateMiddleware.ts index b2e055cdfe..d7dcd559cc 100644 --- a/libraries/botbuilder-core/src/autoSaveStateMiddleware.ts +++ b/libraries/botbuilder-core/src/autoSaveStateMiddleware.ts @@ -50,6 +50,7 @@ export class AutoSaveStateMiddleware implements Middleware { public botStateSet: BotStateSet; /** * Creates a new AutoSaveStateMiddleware instance. + * * @param botStates One or more BotState plugins to automatically save at the end of the turn. */ constructor(...botStates: BotState[]) { @@ -59,6 +60,7 @@ export class AutoSaveStateMiddleware implements Middleware { /** * Called by the adapter (for example, a `BotFrameworkAdapter`) at runtime in order to process an inbound [Activity](xref:botframework-schema.Activity). + * * @param context The context object for this turn. * @param next {function} The next delegate function. */ @@ -69,7 +71,9 @@ export class AutoSaveStateMiddleware implements Middleware { /** * Adds additional `BotState` plugins to be saved. + * * @param botStates One or more BotState plugins to add. + * @returns The updated BotStateSet object. */ public add(...botStates: BotState[]): this { BotStateSet.prototype.add.apply(this.botStateSet, botStates); diff --git a/libraries/botbuilder-core/src/botAdapter.ts b/libraries/botbuilder-core/src/botAdapter.ts index 8e9c4a9da9..eb35fdc101 100644 --- a/libraries/botbuilder-core/src/botAdapter.ts +++ b/libraries/botbuilder-core/src/botAdapter.ts @@ -149,10 +149,10 @@ export abstract class BotAdapter { * @internal */ async continueConversationAsync( - botAppIdOrClaimsIdentity: string | ClaimsIdentity, - reference: Partial, - logicOrAudience: ((context: TurnContext) => Promise) | string, - maybeLogic?: (context: TurnContext) => Promise + _botAppIdOrClaimsIdentity: string | ClaimsIdentity, + _reference: Partial, + _logicOrAudience: ((context: TurnContext) => Promise) | string, + _maybeLogic?: (context: TurnContext) => Promise ): Promise { throw new Error('NotImplemented'); } @@ -160,13 +160,13 @@ export abstract class BotAdapter { /** * Creates a conversation on the specified channel. * - * @param botAppId The application ID of the bot. - * @param channelId The ID for the channel. - * @param serviceUrl The ID for the channel. - * @param audience The audience for the connector. + * @param _botAppId The application ID of the bot. + * @param _channelId The ID for the channel. + * @param _serviceUrl The ID for the channel. + * @param _audience The audience for the connector. * - * @param conversationParameters The conversation information to use to create the conversation - * @param logic The method to call for the resulting bot turn. + * @param _conversationParameters The conversation information to use to create the conversation + * @param _logic The method to call for the resulting bot turn. * @returns A promise that represents the asynchronous operation * * @remarks @@ -180,12 +180,12 @@ export abstract class BotAdapter { * the ID of the new conversation. */ async createConversationAsync( - botAppId: string, - channelId: string, - serviceUrl: string, - audience: string, - conversationParameters: ConversationParameters, - logic: (context: TurnContext) => Promise + _botAppId: string, + _channelId: string, + _serviceUrl: string, + _audience: string, + _conversationParameters: ConversationParameters, + _logic: (context: TurnContext) => Promise ): Promise { throw new Error('NotImplemented'); } @@ -200,6 +200,7 @@ export abstract class BotAdapter { * | :--- | :--- | :--- | * | `context` | [TurnContext](xref:botbuilder-core.TurnContext) | The context object for the turn. | * | `error` | `Error` | The Node.js error thrown. | + * @returns {Promise} A promise representing the async operation. */ public get onTurnError(): (context: TurnContext, error: Error) => Promise { return this.turnError; @@ -223,10 +224,9 @@ export abstract class BotAdapter { /** * Adds middleware to the adapter's pipeline. * - * @param middleware The middleware or middleware handlers to add. - * - * @remarks - * Middleware is added to the adapter at initialization time. + * @param {...any} middlewares The middleware or middleware handlers to add. + * @returns The updated adapter object. + * @remarks Middleware is added to the adapter at initialization time. * Each turn, the adapter calls its middleware in the order in which you added it. */ public use(...middlewares: (MiddlewareHandler | Middleware)[]): this { diff --git a/libraries/botbuilder-core/src/botState.ts b/libraries/botbuilder-core/src/botState.ts index 20906eddf5..6b7e27c925 100644 --- a/libraries/botbuilder-core/src/botState.ts +++ b/libraries/botbuilder-core/src/botState.ts @@ -41,6 +41,7 @@ export class BotState implements PropertyManager { /** * Creates a new BotState instance. + * * @param storage Storage provider to persist the state object to. * @param storageKey Function called anytime the storage key for a given turn needs to be calculated. */ @@ -49,8 +50,10 @@ export class BotState implements PropertyManager { /** * Creates a new property accessor for reading and writing an individual property to the bot * states storage object. - * @param T (Optional) type of property to create. Defaults to `any` type. + * + * @template T The type of property to create. Defaults to `any` type. * @param name Name of the property to add. + * @returns An accessor for the property. */ public createProperty(name: string): StatePropertyAccessor { const prop: BotStatePropertyAccessor = new BotStatePropertyAccessor(this, name); @@ -71,6 +74,7 @@ export class BotState implements PropertyManager { * ``` * @param context Context for current turn of conversation with the user. * @param force (Optional) If `true` the cache will be bypassed and the state will always be read in directly from storage. Defaults to `false`. + * @returns {Promise} The cached state. */ public load(context: TurnContext, force = false): Promise { const cached: CachedBotState = context.turnState.get(this.stateKey); @@ -102,6 +106,7 @@ export class BotState implements PropertyManager { * ``` * @param context Context for current turn of conversation with the user. * @param force (Optional) if `true` the state will always be written out regardless of its change state. Defaults to `false`. + * @returns {Promise} A promise representing the async operation. */ public saveChanges(context: TurnContext, force = false): Promise { let cached: CachedBotState = context.turnState.get(this.stateKey); @@ -137,6 +142,7 @@ export class BotState implements PropertyManager { * await botState.saveChanges(context); * ``` * @param context Context for current turn of conversation with the user. + * @returns {Promise} A promise representing the async operation. */ public clear(context: TurnContext): Promise { // Just overwrite cached value with a new object and empty hash. The empty hash will force the @@ -156,6 +162,7 @@ export class BotState implements PropertyManager { * await botState.delete(context); * ``` * @param context Context for current turn of conversation with the user. + * @returns {Promise} A promise representing the async operation. */ public delete(context: TurnContext): Promise { if (context.turnState.has(this.stateKey)) { @@ -175,6 +182,7 @@ export class BotState implements PropertyManager { * const state = botState.get(context); * ``` * @param context Context for current turn of conversation with the user. + * @returns A cached state object or undefined if not cached. */ public get(context: TurnContext): any | undefined { const cached: CachedBotState = context.turnState.get(this.stateKey); diff --git a/libraries/botbuilder-core/src/botStatePropertyAccessor.ts b/libraries/botbuilder-core/src/botStatePropertyAccessor.ts index 98b2cb20ed..32dc4d6cb8 100644 --- a/libraries/botbuilder-core/src/botStatePropertyAccessor.ts +++ b/libraries/botbuilder-core/src/botStatePropertyAccessor.ts @@ -12,7 +12,7 @@ import { TurnContext } from './turnContext'; * Defines methods for accessing a state property created in a * [BotState](xref:botbuilder-core.BotState) object. * - * @typeparam T Optional. The type of the state property to access. Default type is `any`. + * @template T The type of the state property to access. Default type is `any`. * * @remarks * To create a state property in a state management objet, use the @@ -84,6 +84,7 @@ export interface StatePropertyAccessor { export class BotStatePropertyAccessor implements StatePropertyAccessor { /** * Creates a new BotStatePropertyAccessor instance. + * * @param state Parent BotState instance. * @param name Unique name of the property for the parent BotState. */ @@ -91,17 +92,19 @@ export class BotStatePropertyAccessor implements StatePropertyAccessor< /** * Deletes the persisted property from its backing storage object. + * * @param context [TurnContext](xref:botbuilder-core.TurnContext) object for this turn. */ public async delete(context: TurnContext): Promise { const obj: any = await this.state.load(context); - if (obj.hasOwnProperty(this.name)) { + if (Object.prototype.hasOwnProperty.call(obj, this.name)) { delete obj[this.name]; } } /** * Reads a persisted property from its backing storage object. + * * @param context [TurnContext](xref:botbuilder-core.TurnContext) object for this turn. * @returns A JSON representation of the cached state. */ @@ -109,13 +112,14 @@ export class BotStatePropertyAccessor implements StatePropertyAccessor< public async get(context: TurnContext, defaultValue: T): Promise; /** * Reads a persisted property from its backing storage object. + * * @param context [TurnContext](xref:botbuilder-core.TurnContext) object for this turn. * @param defaultValue Optional. Default value for the property. * @returns A JSON representation of the cached state. */ public async get(context: TurnContext, defaultValue?: T): Promise { const obj: any = await this.state.load(context); - if (!obj.hasOwnProperty(this.name) && defaultValue !== undefined) { + if (!Object.prototype.hasOwnProperty.call(obj, this.name) && defaultValue !== undefined) { const clone: any = typeof defaultValue === 'object' || Array.isArray(defaultValue) ? JSON.parse(JSON.stringify(defaultValue)) @@ -128,6 +132,7 @@ export class BotStatePropertyAccessor implements StatePropertyAccessor< /** * Assigns a new value to the properties backing storage object. + * * @param context [TurnContext](xref:botbuilder-core.TurnContext) object for this turn. * @param value Value to set on the property. */ diff --git a/libraries/botbuilder-core/src/botStateSet.ts b/libraries/botbuilder-core/src/botStateSet.ts index d8670f326d..e6f717c0aa 100644 --- a/libraries/botbuilder-core/src/botStateSet.ts +++ b/libraries/botbuilder-core/src/botStateSet.ts @@ -20,6 +20,7 @@ export class BotStateSet { /** * Creates a new BotStateSet instance. + * * @param botStates One or more BotState plugins to register. */ public constructor(...botStates: BotState[]) { @@ -27,15 +28,17 @@ export class BotStateSet { } /** - * Registers One or more `BotState` plugins with the set. + * Registers one or more `BotState` plugins with the set. + * * @param botStates One or more BotState plugins to register. + * @returns The updated BotStateSet. */ public add(...botStates: BotState[]): this { botStates.forEach((botstate: BotState) => { if (typeof botstate.load === 'function' && typeof botstate.saveChanges === 'function') { this.botStates.push(botstate); } else { - throw new Error(`BotStateSet: a object was added that isn't an instance of BotState.`); + throw new Error("BotStateSet: a object was added that isn't an instance of BotState."); } }); diff --git a/libraries/botbuilder-core/src/botTelemetryClient.ts b/libraries/botbuilder-core/src/botTelemetryClient.ts index 7692b43676..916215da7a 100644 --- a/libraries/botbuilder-core/src/botTelemetryClient.ts +++ b/libraries/botbuilder-core/src/botTelemetryClient.ts @@ -76,49 +76,55 @@ export interface TelemetryPageView { export class NullTelemetryClient implements BotTelemetryClient, BotPageViewTelemetryClient { /** * Creates a new instance of the [NullTelemetryClient](xref:botbuilder-core.NullTelemetryClient) class. - * @param settings Optional. Settings for the telemetry client. + * + * @param _settings Optional. Settings for the telemetry client. */ - constructor(settings?: any) { + constructor(_settings?: any) { // noop } /** * Logs an Application Insights page view. - * @param telemetry An object implementing [TelemetryPageView](xref:botbuilder-core.TelemetryPageView). + * + * @param _telemetry An object implementing [TelemetryPageView](xref:botbuilder-core.TelemetryPageView). */ - trackPageView(telemetry: TelemetryPageView) { + trackPageView(_telemetry: TelemetryPageView) { // noop } /** * Sends information about an external dependency (outgoing call) in the application. - * @param telemetry An object implementing [TelemetryDependency](xref:botbuilder-core.TelemetryDependency). + * + * @param _telemetry An object implementing [TelemetryDependency](xref:botbuilder-core.TelemetryDependency). */ - trackDependency(telemetry: TelemetryDependency) { + trackDependency(_telemetry: TelemetryDependency) { // noop } /** * Logs custom events with extensible named fields. - * @param telemetry An object implementing [TelemetryEvent](xref:botbuilder-core.TelemetryEvent). + * + * @param _telemetry An object implementing [TelemetryEvent](xref:botbuilder-core.TelemetryEvent). */ - trackEvent(telemetry: TelemetryEvent) { + trackEvent(_telemetry: TelemetryEvent) { // noop } /** * Logs a system exception. - * @param telemetry An object implementing [TelemetryException](xref:botbuilder-core.TelemetryException). + * + * @param _telemetry An object implementing [TelemetryException](xref:botbuilder-core.TelemetryException). */ - trackException(telemetry: TelemetryException) { + trackException(_telemetry: TelemetryException) { // noop } /** * Sends a trace message. - * @param telemetry An object implementing [TelemetryTrace](xref:botbuilder-core.TelemetryTrace). + * + * @param _telemetry An object implementing [TelemetryTrace](xref:botbuilder-core.TelemetryTrace). */ - trackTrace(telemetry: TelemetryTrace) { + trackTrace(_telemetry: TelemetryTrace) { // noop } @@ -133,6 +139,7 @@ export class NullTelemetryClient implements BotTelemetryClient, BotPageViewTelem /** * Logs a DialogView using the [trackPageView](xref:botbuilder-core.BotTelemetryClient.trackPageView) method on the [BotTelemetryClient](xref:botbuilder-core.BotTelemetryClient) if [BotPageViewTelemetryClient](xref:botbuilder-core.BotPageViewTelemetryClient) has been implemented. * Alternatively logs the information out via TrackTrace. + * * @param telemetryClient TelemetryClient that implements [BotTelemetryClient](xref:botbuilder-core.BotTelemetryClient). * @param dialogName Name of the dialog to log the entry / start for. * @param properties Named string values you can use to search and classify events. diff --git a/libraries/botbuilder-core/src/cardFactory.ts b/libraries/botbuilder-core/src/cardFactory.ts index f0e9b6e755..6d4316b05b 100644 --- a/libraries/botbuilder-core/src/cardFactory.ts +++ b/libraries/botbuilder-core/src/cardFactory.ts @@ -242,10 +242,9 @@ export class CardFactory { * @param title The title for the card's sign-in button. * @param text Optional. Additional text to include on the card. * @param link Optional. The sign-in link to use. + * @param tokenExchangeResource optional. The resource to try to perform token exchange with. * @returns An [Attachment](xref:botframework-schema.Attachment). - * - * @remarks - * OAuth cards support the Bot Framework's single sign on (SSO) service. + * @remarks OAuth cards support the Bot Framework's single sign on (SSO) service. */ public static oauthCard( connectionName: string, @@ -267,29 +266,29 @@ export class CardFactory { } /** - * Returns an attachment for an Office 365 connector card. - * - * @param card a description of the Office 365 connector card to return. - * @returns An [Attachment](xref:botframework-schema.Attachment). - * - * @remarks - * For example: - * ```JavaScript - * const card = CardFactory.o365ConnectorCard({ - * "title": "card title", - * "text": "card text", - * "summary": "O365 card summary", - * "themeColor": "#E67A9E", - * "sections": [ - * { - * "title": "**section title**", - * "text": "section text", - * "activityTitle": "activity title", - * } - * ] - * }); - * ``` - */ + * Returns an attachment for an Office 365 connector card. + * + * @param card a description of the Office 365 connector card to return. + * @returns An [Attachment](xref:botframework-schema.Attachment). + * + * @remarks + * For example: + * ```JavaScript + * const card = CardFactory.o365ConnectorCard({ + * "title": "card title", + * "text": "card text", + * "summary": "O365 card summary", + * "themeColor": "#E67A9E", + * "sections": [ + * { + * "title": "**section title**", + * "text": "section text", + * "activityTitle": "activity title", + * } + * ] + * }); + * ``` + */ public static o365ConnectorCard(card: O365ConnectorCard): Attachment { return { contentType: CardFactory.contentTypes.o365ConnectorCard, content: card }; } @@ -446,6 +445,7 @@ export class CardFactory { * * @param actions The array of action to include on the card. Each `string` in the array * is converted to an `imBack` button with a title and value set to the value of the string. + * @returns A properly formatted array of actions. */ public static actions(actions: (CardAction | string)[] | undefined): CardAction[] { const list: CardAction[] = []; @@ -470,6 +470,7 @@ export class CardFactory { * * @param images The array of images to include on the card. Each element can be a * [CardImage](ref:botframework-schema.CardImage) or the URL of the image to include. + * @returns A properly formatted array of card images. */ public static images(images: (CardImage | string)[] | undefined): CardImage[] { const list: CardImage[] = []; @@ -488,6 +489,7 @@ export class CardFactory { * Returns a properly formatted array of media URL objects. * * @param links The media URLs. Each `string` is converted to a media URL object. + * @returns A properly formatted array of media URL objects. */ public static media(links: (MediaUrl | string)[] | undefined): MediaUrl[] { const list: MediaUrl[] = []; diff --git a/libraries/botbuilder-core/src/cloudAdapterBase.ts b/libraries/botbuilder-core/src/cloudAdapterBase.ts index 295b6c888a..935aad2207 100644 --- a/libraries/botbuilder-core/src/cloudAdapterBase.ts +++ b/libraries/botbuilder-core/src/cloudAdapterBase.ts @@ -31,6 +31,9 @@ import { StatusCodes, } from 'botframework-schema'; +/** + * An adapter that implements the Bot Framework Protocol and can be hosted in different cloud environments both public and private. + */ export abstract class CloudAdapterBase extends BotAdapter { readonly ConnectorFactoryKey = Symbol('ConnectorFactory'); readonly UserTokenClientKey = Symbol('UserTokenClient'); @@ -148,8 +151,8 @@ export abstract class CloudAdapterBase extends BotAdapter { * @deprecated */ async continueConversation( - reference: Partial, - logic: (context: TurnContext) => Promise + _reference: Partial, + _logic: (context: TurnContext) => Promise ): Promise { throw new Error( '`CloudAdapterBase.continueConversation` is deprecated, please use `CloudAdapterBase.continueConversationAsync`' diff --git a/libraries/botbuilder-core/src/componentRegistration.ts b/libraries/botbuilder-core/src/componentRegistration.ts index f1f29cbd8b..14c093ed7f 100644 --- a/libraries/botbuilder-core/src/componentRegistration.ts +++ b/libraries/botbuilder-core/src/componentRegistration.ts @@ -14,6 +14,7 @@ export class ComponentRegistration { /** * Gets list of all ComponentRegistration objects registered. + * * @returns A list of ComponentRegistration objects. */ public static get components(): ComponentRegistration[] { @@ -22,10 +23,11 @@ export class ComponentRegistration { /** * Add a component, only one instance per type is allowed for components. + * * @param componentRegistration The component to be registered. */ public static add(componentRegistration: ComponentRegistration): void { const name = componentRegistration.constructor.name; ComponentRegistration._components.set(name, componentRegistration); } -} \ No newline at end of file +} diff --git a/libraries/botbuilder-core/src/configurationBotFrameworkAuthentication.ts b/libraries/botbuilder-core/src/configurationBotFrameworkAuthentication.ts index 6a78b8592a..456d34002c 100644 --- a/libraries/botbuilder-core/src/configurationBotFrameworkAuthentication.ts +++ b/libraries/botbuilder-core/src/configurationBotFrameworkAuthentication.ts @@ -170,26 +170,63 @@ export class ConfigurationBotFrameworkAuthentication extends BotFrameworkAuthent } } + /** + * Authenticate Bot Framework Protocol requests to Skills. + * + * @param authHeader The http auth header received in the skill request. + * @returns {Promise} A [ClaimsIdentity](xref:botframework-connector.ClaimsIdentity). + */ authenticateChannelRequest(authHeader: string): Promise { return this.inner.authenticateChannelRequest(authHeader); } + /** + * Validate Bot Framework Protocol requests. + * + * @param activity The inbound Activity. + * @param authHeader The HTTP auth header. + * @returns {Promise} An [AuthenticateRequestResult](xref:botframework-connector.AuthenticateRequestResult). + */ authenticateRequest(activity: Activity, authHeader: string): Promise { return this.inner.authenticateRequest(activity, authHeader); } + /** + * Validate Bot Framework Protocol requests. + * + * @param authHeader The HTTP auth header. + * @param channelIdHeader The channel ID HTTP header. + * @returns {Promise} An [AuthenticateRequestResult](xref:botframework-connector.AuthenticateRequestResult). + */ authenticateStreamingRequest(authHeader: string, channelIdHeader: string): Promise { return this.inner.authenticateStreamingRequest(authHeader, channelIdHeader); } + /** + * Creates a BotFrameworkClient for calling Skills. + * + * @returns A [BotFrameworkClient](xref:botframework-connector.BotFrameworkClient). + */ createBotFrameworkClient(): BotFrameworkClient { return this.inner.createBotFrameworkClient(); } + /** + * Creates a ConnectorFactory that can be used to create ConnectorClients that can use credentials from this particular Cloud Environment. + * + * @param claimsIdentity The inbound Activity's ClaimsIdentity. + * @returns A [ConnectorFactory](xref:botframework-connector.ConnectorFactory). + */ createConnectorFactory(claimsIdentity: ClaimsIdentity): ConnectorFactory { return this.inner.createConnectorFactory(claimsIdentity); } + /** + * Creates the appropriate UserTokenClient instance. + * + * @param claimsIdentity The inbound Activity's ClaimsIdentity. + * @returns {Promise} An [UserTokenClient](xref:botframework-connector.UserTokenClient). + */ createUserTokenClient(claimsIdentity: ClaimsIdentity): Promise { return this.inner.createUserTokenClient(claimsIdentity); } diff --git a/libraries/botbuilder-core/src/conversationState.ts b/libraries/botbuilder-core/src/conversationState.ts index b591d3b8cf..b82e06576d 100644 --- a/libraries/botbuilder-core/src/conversationState.ts +++ b/libraries/botbuilder-core/src/conversationState.ts @@ -10,7 +10,7 @@ import { BotState } from './botState'; import { Storage } from './storage'; import { TurnContext } from './turnContext'; -const NO_KEY = `ConversationState: overridden getStorageKey method did not return a key.`; +const NO_KEY = 'ConversationState: overridden getStorageKey method did not return a key.'; /** * Reads and writes conversation state for your bot to storage. @@ -29,6 +29,7 @@ const NO_KEY = `ConversationState: overridden getStorageKey method did not retur export class ConversationState extends BotState { /** * Creates a new ConversationState instance. + * * @param storage Storage provider to persist conversation state to. * @param namespace (Optional) namespace to append to storage keys. Defaults to an empty string. */ @@ -43,7 +44,9 @@ export class ConversationState extends BotState { /** * Returns the storage key for the current conversation state. + * * @param context Context for current turn of conversation with the user. + * @returns The storage key for the current conversation state. */ public getStorageKey(context: TurnContext): string | undefined { const activity: Activity = context.activity; diff --git a/libraries/botbuilder-core/src/coreAppCredentials.ts b/libraries/botbuilder-core/src/coreAppCredentials.ts index a5db5a4c2b..8d7d63c46f 100644 --- a/libraries/botbuilder-core/src/coreAppCredentials.ts +++ b/libraries/botbuilder-core/src/coreAppCredentials.ts @@ -18,6 +18,7 @@ interface CoreWebResource { /** * CoreAppCredentials + * * @remarks * Runtime-agnostic interface representing "ServiceClientCredentials" from @azure/ms-rest-js */ @@ -25,8 +26,8 @@ export interface CoreAppCredentials { /** * Signs a request with the Authentication header. * - * @param {WebResource} webResource The WebResource/request to be signed. - * @returns {Promise} The signed request object; + * @param {CoreWebResource} webResource The CoreWebResource/request to be signed. + * @returns {Promise} The signed request object; */ signRequest(webResource: CoreWebResource): Promise; } diff --git a/libraries/botbuilder-core/src/extendedUserTokenProvider.ts b/libraries/botbuilder-core/src/extendedUserTokenProvider.ts index 0eab40bae0..8373f01936 100644 --- a/libraries/botbuilder-core/src/extendedUserTokenProvider.ts +++ b/libraries/botbuilder-core/src/extendedUserTokenProvider.ts @@ -14,11 +14,12 @@ import { SignInUrlResponse, TokenResponse, TokenExchangeRequest } from 'botframe /** * Interface for User Token OAuth Single Sign On and Token Exchange APIs for BotAdapters * - * @obsolete Use `UserTokenClient` instead. + * @deprecated Use `UserTokenClient` instead. */ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Retrieves the OAuth token for a user that is in a sign-in flow. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param magicCode (Optional) Optional user entered code to validate. @@ -32,6 +33,7 @@ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Signs the user out with the token server. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId User id of user to sign out. @@ -46,6 +48,7 @@ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Gets a signin link from the token server that can be sent as part of a SigninCard. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param oAuthAppCredentials AppCredentials for OAuth. @@ -54,6 +57,7 @@ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Signs the user out with the token server. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param oAuthAppCredentials AppCredentials for OAuth. @@ -69,6 +73,7 @@ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Get the raw signin resource to be sent to the user for signin for a connection name. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. */ @@ -76,6 +81,7 @@ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Get the raw signin resource to be sent to the user for signin for a connection name. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId The user id that will be associated with the token. @@ -90,6 +96,7 @@ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Get the raw signin resource to be sent to the user for signin for a connection name. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId The user id that will be associated with the token. @@ -105,6 +112,7 @@ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Performs a token exchange operation such as for single sign-on. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId The user id that will be associated with the token. @@ -119,6 +127,7 @@ export interface ExtendedUserTokenProvider extends IUserTokenProvider { /** * Performs a token exchange operation such as for single sign-on. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId The user id that will be associated with the token. diff --git a/libraries/botbuilder-core/src/invokeException.ts b/libraries/botbuilder-core/src/invokeException.ts index 3115e46631..8ef46eb159 100644 --- a/libraries/botbuilder-core/src/invokeException.ts +++ b/libraries/botbuilder-core/src/invokeException.ts @@ -4,13 +4,25 @@ import { StatusCodes } from 'botframework-schema'; import { InvokeResponse } from './invokeResponse'; +/** + * A custom exception for invoke response errors. + */ export class InvokeException extends Error { + /** + * @param status The Http status code of the error. + * @param response optional. The body of the exception. Default is null. + */ constructor(private readonly status: StatusCodes, private readonly response?: T) { super(); this.name = 'InvokeException'; } + /** + * A factory method that creates a new [InvokeResponse](xref:botbuilder-core.InvokeResponse) object with the status code and body of the current object. + * + * @returns A new [InvokeResponse](xref:botbuilder-core.InvokeResponse) object. + */ createInvokeResponse(): InvokeResponse { return { status: this.status, diff --git a/libraries/botbuilder-core/src/memoryStorage.ts b/libraries/botbuilder-core/src/memoryStorage.ts index d0133aefc0..370b7d83c1 100644 --- a/libraries/botbuilder-core/src/memoryStorage.ts +++ b/libraries/botbuilder-core/src/memoryStorage.ts @@ -31,6 +31,7 @@ export class MemoryStorage implements Storage { protected etag: number; /** * Creates a new MemoryStorage instance. + * * @param memory (Optional) memory to use for storing items. By default it will create an empty JSON object `{}`. */ public constructor(protected memory: { [k: string]: string } = {}) { @@ -39,13 +40,14 @@ export class MemoryStorage implements Storage { /** * Reads storage items from storage. + * * @param keys Keys of the [StoreItems](xref:botbuilder-core.StoreItems) objects to read. * @returns The read items. */ public read(keys: string[]): Promise { - return new Promise((resolve: any, reject: any): void => { + return new Promise((resolve: any): void => { if (!keys) { - throw new ReferenceError(`Keys are required when reading.`); + throw new ReferenceError('Keys are required when reading.'); } const data: StoreItems = {}; keys.forEach((key: string) => { @@ -60,19 +62,20 @@ export class MemoryStorage implements Storage { /** * Writes storage items to storage. + * * @param changes The [StoreItems](xref:botbuilder-core.StoreItems) to write, indexed by key. + * @returns {Promise} A promise representing the async operation. */ public write(changes: StoreItems): Promise { - const that: MemoryStorage = this; - function saveItem(key: string, item: any): void { + const saveItem = (key: string, item: any) => { const clone: any = { ...item }; - clone.eTag = (that.etag++).toString(); - that.memory[key] = JSON.stringify(clone); - } + clone.eTag = (this.etag++).toString(); + this.memory[key] = JSON.stringify(clone); + }; return new Promise((resolve: any, reject: any): void => { if (!changes) { - throw new ReferenceError(`Changes are required when writing.`); + throw new ReferenceError('Changes are required when writing.'); } Object.keys(changes).forEach((key: any) => { const newItem: any = changes[key]; @@ -94,10 +97,12 @@ export class MemoryStorage implements Storage { /** * Deletes storage items from storage. + * * @param keys Keys of the [StoreItems](xref:botbuilder-core.StoreItems) objects to delete. + * @returns {Promise} A promise representing the async operation. */ public delete(keys: string[]): Promise { - return new Promise((resolve: any, reject: any): void => { + return new Promise((resolve: any): void => { keys.forEach((key: string) => (this.memory[key] = undefined)); resolve(); }); diff --git a/libraries/botbuilder-core/src/memoryTranscriptStore.ts b/libraries/botbuilder-core/src/memoryTranscriptStore.ts index fbc3cd14fc..5708ccd4d8 100644 --- a/libraries/botbuilder-core/src/memoryTranscriptStore.ts +++ b/libraries/botbuilder-core/src/memoryTranscriptStore.ts @@ -23,7 +23,9 @@ export class MemoryTranscriptStore implements TranscriptStore { /** * Log an activity to the transcript. + * * @param activity Activity to log. + * @returns {Promise} A promise representing the async operation. */ public logActivity(activity: Activity): void | Promise { if (!activity) { @@ -54,11 +56,13 @@ export class MemoryTranscriptStore implements TranscriptStore { } /** - * Get activities from the memory transcript store + * Get activities from the memory transcript store. + * * @param channelId Channel Id. * @param conversationId Conversation Id. * @param continuationToken Continuation token to page through results. * @param startDate Earliest time to include. + * @returns {Promise>} A page of matching activities. */ public getTranscriptActivities( channelId: string, @@ -103,8 +107,10 @@ export class MemoryTranscriptStore implements TranscriptStore { /** * List conversations in the channelId. + * * @param channelId Channel Id. * @param continuationToken Continuation token to page through results. + * @returns {Promise>} A page of conversations for a channel from the store. */ public listTranscripts(channelId: string, continuationToken?: string): Promise> { if (!channelId) { @@ -146,8 +152,10 @@ export class MemoryTranscriptStore implements TranscriptStore { /** * Delete a specific conversation and all of it's activities. + * * @param channelId Channel Id where conversation took place. * @param conversationId Id of the conversation to delete. + * @returns {Promise} A promise representing the async operation. */ public deleteTranscript(channelId: string, conversationId: string): Promise { if (!channelId) { diff --git a/libraries/botbuilder-core/src/messageFactory.ts b/libraries/botbuilder-core/src/messageFactory.ts index 240bf6135c..f18750a550 100644 --- a/libraries/botbuilder-core/src/messageFactory.ts +++ b/libraries/botbuilder-core/src/messageFactory.ts @@ -48,6 +48,7 @@ export class MessageFactory { * @param text Text to include in the message. * @param speak (Optional) SSML to include in the message. * @param inputHint (Optional) input hint for the message. Defaults to `acceptingInput`. + * @returns A message activity containing the text. */ public static text(text: string, speak?: string, inputHint?: InputHints | string): Partial { const msg: Partial = { @@ -75,6 +76,7 @@ export class MessageFactory { * @param text (Optional) text of the message. * @param speak (Optional) SSML to include with the message. * @param inputHint (Optional) input hint for the message. Defaults to `acceptingInput`. + * @returns A message activity that contains the suggested actions. */ public static suggestedActions( actions: (CardAction | string)[], @@ -118,6 +120,7 @@ export class MessageFactory { * @param text (Optional) text of the message. * @param speak (Optional) SSML to include with the message. * @param inputHint (Optional) input hint for the message. Defaults to `acceptingInput`. + * @returns A message activity containing the attachment. */ public static attachment( attachment: Attachment, @@ -145,6 +148,7 @@ export class MessageFactory { * @param text (Optional) text of the message. * @param speak (Optional) SSML to include with the message. * @param inputHint (Optional) input hint for the message. + * @returns A message activity that will display a set of attachments in list form. */ public static list( attachments: Attachment[], @@ -172,6 +176,7 @@ export class MessageFactory { * @param text (Optional) text of the message. * @param speak (Optional) SSML to include with the message. * @param inputHint (Optional) input hint for the message. + * @returns A message activity that will display a set of attachments using a carousel layout. */ public static carousel( attachments: Attachment[], @@ -197,6 +202,7 @@ export class MessageFactory { * @param text (Optional) text of the message. * @param speak (Optional) SSML to include with the message. * @param inputHint (Optional) input hint for the message. + * @returns A message activity that will display a single image or video to a user. */ public static contentUrl( url: string, diff --git a/libraries/botbuilder-core/src/middlewareSet.ts b/libraries/botbuilder-core/src/middlewareSet.ts index 7889fa10c6..f877827564 100644 --- a/libraries/botbuilder-core/src/middlewareSet.ts +++ b/libraries/botbuilder-core/src/middlewareSet.ts @@ -71,7 +71,8 @@ export class MiddlewareSet implements Middleware { /** * Creates a new MiddlewareSet instance. - * @param middleware One or more middleware handlers(s) to register. + * + * @param {...any} middlewares One or more middleware handlers(s) to register. */ constructor(...middlewares: (MiddlewareHandler | Middleware)[]) { this.use(...middlewares); @@ -79,8 +80,10 @@ export class MiddlewareSet implements Middleware { /** * Processes an incoming activity. + * * @param context [TurnContext](xref:botbuilder-core.TurnContext) object for this turn. * @param next Delegate to call to continue the bot middleware pipeline. + * @returns {Promise} A Promise representing the async operation. */ public onTurn(context: TurnContext, next: () => Promise): Promise { return this.run(context, next); @@ -89,9 +92,7 @@ export class MiddlewareSet implements Middleware { /** * Registers middleware handlers(s) with the set. * - * @remarks - * This example adds a new piece of middleware to a set: - * + * @remarks This example adds a new piece of middleware to a set: * ```JavaScript * set.use(async (context, next) => { * console.log(`Leading Edge`); @@ -99,7 +100,8 @@ export class MiddlewareSet implements Middleware { * console.log(`Trailing Edge`); * }); * ``` - * @param middleware One or more middleware handlers(s) to register. + * @param {...any} middlewares One or more middleware handlers(s) to register. + * @returns The updated middleware set. */ public use(...middlewares: (MiddlewareHandler | Middleware)[]): this { middlewares.forEach((plugin) => { @@ -108,7 +110,7 @@ export class MiddlewareSet implements Middleware { } else if (typeof plugin === 'object' && plugin.onTurn) { this.middleware.push((context, next) => plugin.onTurn(context, next)); } else { - throw new Error(`MiddlewareSet.use(): invalid plugin type being added.`); + throw new Error('MiddlewareSet.use(): invalid plugin type being added.'); } }); @@ -117,6 +119,7 @@ export class MiddlewareSet implements Middleware { /** * Executes a set of middleware in series. + * * @param context Context for the current turn of conversation with the user. * @param next Function to invoke at the end of the middleware chain. * @returns A promise that resolves after the handler chain is complete. diff --git a/libraries/botbuilder-core/src/privateConversationState.ts b/libraries/botbuilder-core/src/privateConversationState.ts index 368e222d4b..1d2abd0bfd 100644 --- a/libraries/botbuilder-core/src/privateConversationState.ts +++ b/libraries/botbuilder-core/src/privateConversationState.ts @@ -10,7 +10,7 @@ import { BotState } from './botState'; import { Storage } from './storage'; import { TurnContext } from './turnContext'; -const NO_KEY = `PrivateConversationState: overridden getStorageKey method did not return a key.`; +const NO_KEY = 'PrivateConversationState: overridden getStorageKey method did not return a key.'; /** * Reads and writes PrivateConversation state for your bot to storage. @@ -29,6 +29,7 @@ const NO_KEY = `PrivateConversationState: overridden getStorageKey method did no export class PrivateConversationState extends BotState { /** * Creates a new PrivateConversationState instance. + * * @param storage Storage provider to persist PrivateConversation state to. * @param namespace (Optional) namespace to append to storage keys. Defaults to an empty string. */ @@ -43,7 +44,9 @@ export class PrivateConversationState extends BotState { /** * Returns the storage key for the current PrivateConversation state. + * * @param context Context for current turn of PrivateConversation with the user. + * @returns The storage key for the current PrivateConversation state. */ public getStorageKey(context: TurnContext): string | undefined { const activity: Activity = context.activity; diff --git a/libraries/botbuilder-core/src/propertyManager.ts b/libraries/botbuilder-core/src/propertyManager.ts index 6c89021a11..ec7ac92eec 100644 --- a/libraries/botbuilder-core/src/propertyManager.ts +++ b/libraries/botbuilder-core/src/propertyManager.ts @@ -14,6 +14,7 @@ export interface PropertyManager { /** * Creates a new property accessor for reading and writing an individual property to the bots * state management system. + * * @param T (Optional) type of property to create. Defaults to `any` type. * @param name Name of the property being created. */ diff --git a/libraries/botbuilder-core/src/recognizerResult.ts b/libraries/botbuilder-core/src/recognizerResult.ts index f948545854..a54aee7066 100644 --- a/libraries/botbuilder-core/src/recognizerResult.ts +++ b/libraries/botbuilder-core/src/recognizerResult.ts @@ -46,7 +46,7 @@ export const getTopScoringIntent = (result: RecognizerResult): { intent: string; throw new Error('result is empty'); } - let topIntent: string = ''; + let topIntent = ''; let topScore = -1; for (const [intentName, intent] of Object.entries(result.intents)) { const score = intent.score ?? -1; @@ -56,7 +56,6 @@ export const getTopScoringIntent = (result: RecognizerResult): { intent: string; } } - return { intent: topIntent, score: topScore, diff --git a/libraries/botbuilder-core/src/registerClassMiddleware.ts b/libraries/botbuilder-core/src/registerClassMiddleware.ts index 28a16f11f5..1cb32d1730 100644 --- a/libraries/botbuilder-core/src/registerClassMiddleware.ts +++ b/libraries/botbuilder-core/src/registerClassMiddleware.ts @@ -17,6 +17,7 @@ export class RegisterClassMiddleware implements Middleware { /** * Initialize a new instance of the RegisterClassMiddleware class. + * * @param service The object or service to add. * @param key The key for service object in turn state. */ @@ -32,6 +33,7 @@ export class RegisterClassMiddleware implements Middleware { /** * Adds the associated object or service to the current turn context. + * * @param turnContext The context object for this turn. * @param next The delegate to call to continue the bot middleware pipeline. */ @@ -41,4 +43,4 @@ export class RegisterClassMiddleware implements Middleware { await next(); } } -} \ No newline at end of file +} diff --git a/libraries/botbuilder-core/src/showTypingMiddleware.ts b/libraries/botbuilder-core/src/showTypingMiddleware.ts index 042bb641f2..91a25eddb2 100644 --- a/libraries/botbuilder-core/src/showTypingMiddleware.ts +++ b/libraries/botbuilder-core/src/showTypingMiddleware.ts @@ -23,6 +23,7 @@ import { TurnContext } from './turnContext'; export class ShowTypingMiddleware implements Middleware { /** * Create the SendTypingIndicator middleware + * * @param delay {number} Number of milliseconds to wait before sending the first typing indicator. * @param period {number} Number of milliseconds to wait before sending each following indicator. */ @@ -38,6 +39,7 @@ export class ShowTypingMiddleware implements Middleware { /** * Processes an incoming activity. + * * @param context {TurnContext} An incoming TurnContext object. * @param next {function} The next delegate function. */ diff --git a/libraries/botbuilder-core/src/skills/skillConversationIdFactory.ts b/libraries/botbuilder-core/src/skills/skillConversationIdFactory.ts index 6b6fd29e24..a1759479ea 100644 --- a/libraries/botbuilder-core/src/skills/skillConversationIdFactory.ts +++ b/libraries/botbuilder-core/src/skills/skillConversationIdFactory.ts @@ -9,11 +9,25 @@ import { Storage } from '../storage'; import { TurnContext } from '../turnContext'; import { v4 as uuid } from 'uuid'; +/** + * A SkillConversationIdFactory that stores and retrieves [ConversationReference](xref:botframework-schema:ConversationReference) instances. + */ export class SkillConversationIdFactory extends SkillConversationIdFactoryBase { + /** + * Creates a new instance of the SkillConversationIdFactory class. + * + * @param storage The storage for the [ConversationReference](xref:botframework-schema:ConversationReference) instances. + */ constructor(private readonly storage: Storage) { super(); } + /** + * Creates a conversation ID for a skill conversation based on the caller's [ConversationReference](xref:botframework-schema:ConversationReference). + * + * @param options The [SkillConversationIdFactoryOptions](xref:botbuilder-core.SkillConversationIdFactoryOptions) to use. + * @returns {Promise} A unique conversation ID used to communicate with the skill. + */ public async createSkillConversationIdWithOptions(options: SkillConversationIdFactoryOptions): Promise { const conversationReference = TurnContext.getConversationReference(options.activity); @@ -29,6 +43,12 @@ export class SkillConversationIdFactory extends SkillConversationIdFactoryBase { return skillConversationId; } + /** + * Gets the ConversationReference created using createSkillConversationId() for a skillConversationId. + * + * @param skillConversationId A skill conversationId created using createSkillConversationId(). + * @returns {Promise} The caller's ConversationReference for a skillConversationId. Null if not found. + */ public async getSkillConversationReference(skillConversationId: string): Promise { const skillConversationInfo = await this.storage.read([skillConversationId]); if (!skillConversationInfo) { @@ -43,6 +63,12 @@ export class SkillConversationIdFactory extends SkillConversationIdFactoryBase { return skillConversationReference as SkillConversationReference; } + /** + * Deletes the [SkillConversationReference](xref:botbuilder-core.SkillConversationReference) from the storage. + * + * @param skillConversationId The skill conversation id to use as key for the delete. + * @returns {Promise} A promise representing the asynchronous operation. + */ deleteConversationReference(skillConversationId: string): Promise { return this.storage.delete([skillConversationId]); } diff --git a/libraries/botbuilder-core/src/skills/skillConversationIdFactoryBase.ts b/libraries/botbuilder-core/src/skills/skillConversationIdFactoryBase.ts index 7289e8072c..86617e92c6 100644 --- a/libraries/botbuilder-core/src/skills/skillConversationIdFactoryBase.ts +++ b/libraries/botbuilder-core/src/skills/skillConversationIdFactoryBase.ts @@ -16,47 +16,50 @@ import { SkillConversationReference } from './skillConversationReference'; export abstract class SkillConversationIdFactoryBase { /** * Creates a conversation ID for a skill conversation based on the caller's ConversationReference. - * @remarks - * It should be possible to use the returned string on a request URL and it should not contain special characters. - * @param conversationReference The skill's caller ConversationReference. - * @returns A unique conversation ID used to communicate with the skill. + * + * @param _options The [SkillConversationIdFactoryOptions](xref:botbuilder-core.SkillConversationIdFactoryOptions) to use. + * @remarks It should be possible to use the returned string on a request URL and it should not contain special characters. + * Returns A unique conversation ID used to communicate with the skill. */ - public createSkillConversationIdWithOptions(options: SkillConversationIdFactoryOptions): Promise { + public createSkillConversationIdWithOptions(_options: SkillConversationIdFactoryOptions): Promise { throw new Error('Not Implemented'); } /** * Creates a conversation ID for a skill conversation based on the caller's ConversationReference. + * * @deprecated Method is deprecated, please use createSkillConversationIdWithOptions() with SkillConversationIdFactoryOptions instead. - * @remarks - * It should be possible to use the returned string on a request URL and it should not contain special characters. - * @param conversationReference The skill's caller ConversationReference. - * @returns A unique conversation ID used to communicate with the skill. + * @param _conversationReference The skill's caller ConversationReference. + * @remarks It should be possible to use the returned string on a request URL and it should not contain special characters. + * Returns A unique conversation ID used to communicate with the skill. */ - public createSkillConversationId(conversationReference: ConversationReference): Promise { + public createSkillConversationId(_conversationReference: ConversationReference): Promise { throw new Error('Not Implemented'); } /** * Gets the ConversationReference created using createSkillConversationId() for a skillConversationId. + * * @deprecated Method is deprecated, please use getSkillConversationReference() instead. - * @param skillConversationId >A skill conversationId created using createSkillConversationId(). - * @returns The caller's ConversationReference for a skillConversationId. null if not found. + * @param _skillConversationId A skill conversationId created using createSkillConversationId(). + * @remarks Returns The caller's ConversationReference for a skillConversationId. null if not found. */ - public getConversationReference(skillConversationId: string): Promise { + public getConversationReference(_skillConversationId: string): Promise { throw new Error('Not Implemented'); } /** * Gets the SkillConversationReference created using createSkillConversationId() for a skillConversationId. - * @param skillConversationId Gets the SkillConversationReference used during createSkillConversationId for a skillConversationId. + * + * @param _skillConversationId Gets the SkillConversationReference used during createSkillConversationId for a skillConversationId. */ - public getSkillConversationReference(skillConversationId: string): Promise { + public getSkillConversationReference(_skillConversationId: string): Promise { throw new Error('Not Implemented'); } /** * Deletes a ConversationReference. + * * @param skillConversationId A skill conversationId created using createSkillConversationId(). */ public abstract deleteConversationReference(skillConversationId: string): Promise; diff --git a/libraries/botbuilder-core/src/skypeMentionNormalizeMiddleware.ts b/libraries/botbuilder-core/src/skypeMentionNormalizeMiddleware.ts index 2bdbd0deee..a32332b6a9 100644 --- a/libraries/botbuilder-core/src/skypeMentionNormalizeMiddleware.ts +++ b/libraries/botbuilder-core/src/skypeMentionNormalizeMiddleware.ts @@ -23,6 +23,7 @@ import { TurnContext } from './turnContext'; export class SkypeMentionNormalizeMiddleware implements Middleware { /** * Performs the normalization of Skype mention Entities. + * * @param activity [Activity](xref:botframework-schema.Activity) containing the mentions to normalize. */ public static normalizeSkypeMentionText(activity: Activity): void { @@ -42,6 +43,7 @@ export class SkypeMentionNormalizeMiddleware implements Middleware { /** * Middleware implementation which corrects the Entity text of type [Mention](xref:botframework-schema.Mention) to a value that [removeMentionText](xref:botbuilder-core.TurnContext.removeMentionText) can work with. + * * @param turnContext [TurnContext](xref:botbuilder-core.TurnContext) for the current turn of conversation. * @param next Delegate to call to continue the bot middleware pipeline. */ diff --git a/libraries/botbuilder-core/src/stringUtils.ts b/libraries/botbuilder-core/src/stringUtils.ts index 6d5186ceb7..4b43584144 100644 --- a/libraries/botbuilder-core/src/stringUtils.ts +++ b/libraries/botbuilder-core/src/stringUtils.ts @@ -12,8 +12,10 @@ export class StringUtils { /** * Truncate string with ... + * * @param text Text. * @param length Length to truncate text. + * @returns Original string modified. */ public static ellipsis(text: string, length: number): string { text = text || ''; @@ -33,6 +35,7 @@ export class StringUtils { * https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/ * * @param text Text to hash. + * @returns A string which is an unique hash. */ public static hash(text: string): string { const length = text.length; @@ -47,8 +50,10 @@ export class StringUtils { /** * EllipsisHash - create truncated string with unique hash for the truncated part. + * * @param text Text to truncate. * @param length Length to truncate at. + * @returns The truncated string with unique hash for the truncated part. */ public static ellipsisHash(text: string, length: number): string { text = text || ''; diff --git a/libraries/botbuilder-core/src/telemetryLoggerMiddleware.ts b/libraries/botbuilder-core/src/telemetryLoggerMiddleware.ts index 55fbdff0c0..130ce59fff 100644 --- a/libraries/botbuilder-core/src/telemetryLoggerMiddleware.ts +++ b/libraries/botbuilder-core/src/telemetryLoggerMiddleware.ts @@ -50,6 +50,7 @@ export class TelemetryLoggerMiddleware implements Middleware { /** * Initializes a new instance of the TelemetryLoggerMiddleware class. + * * @param telemetryClient The BotTelemetryClient used for logging. * @param logPersonalInformation (Optional) Enable/Disable logging original message name within Application Insights. */ @@ -59,7 +60,9 @@ export class TelemetryLoggerMiddleware implements Middleware { } /** - * Gets a value indicating whether determines whether to log personal information that came from the user. + * Gets a value indicating whether to log personal information that came from the user. + * + * @returns A value indicating whether to log personal information or not. */ public get logPersonalInformation(): boolean { return this._logPersonalInformation; @@ -67,6 +70,8 @@ export class TelemetryLoggerMiddleware implements Middleware { /** * Gets the currently configured botTelemetryClient that logs the events. + * + * @returns The currently configured [BotTelemetryClient](xref:botbuilder-core.BotTelemetryClient) that logs the events. */ public get telemetryClient(): BotTelemetryClient { return this._telemetryClient; @@ -74,6 +79,7 @@ export class TelemetryLoggerMiddleware implements Middleware { /** * Logs events based on incoming and outgoing activities using the botTelemetryClient class. + * * @param context The context object for this turn. * @param next The delegate to call to continue the bot middleware pipeline */ @@ -147,6 +153,7 @@ export class TelemetryLoggerMiddleware implements Middleware { * Invoked when a message is received from the user. * Performs logging of telemetry data using the IBotTelemetryClient.TrackEvent() method. * The event name logged is "BotMessageReceived". + * * @param activity Current activity sent from user. */ protected async onReceiveActivity(activity: Activity): Promise { @@ -160,6 +167,7 @@ export class TelemetryLoggerMiddleware implements Middleware { * Invoked when the bot sends a message to the user. * Performs logging of telemetry data using the botTelemetryClient.trackEvent() method. * The event name logged is "BotMessageSend". + * * @param activity Last activity sent from user. */ protected async onSendActivity(activity: Activity): Promise { @@ -173,7 +181,8 @@ export class TelemetryLoggerMiddleware implements Middleware { * Invoked when the bot updates a message. * Performs logging of telemetry data using the botTelemetryClient.trackEvent() method. * The event name used is "BotMessageUpdate". - * @param activity + * + * @param activity Current activity sent from user. */ protected async onUpdateActivity(activity: Activity): Promise { this.telemetryClient.trackEvent({ @@ -186,7 +195,8 @@ export class TelemetryLoggerMiddleware implements Middleware { * Invoked when the bot deletes a message. * Performs logging of telemetry data using the botTelemetryClient.trackEvent() method. * The event name used is "BotMessageDelete". - * @param activity + * + * @param activity Current activity sent from user. */ protected async onDeleteActivity(activity: Activity): Promise { this.telemetryClient.trackEvent({ @@ -198,6 +208,7 @@ export class TelemetryLoggerMiddleware implements Middleware { /** * Fills the Application Insights Custom Event properties for BotMessageReceived. * These properties are logged in the custom event when a new message is received from the user. + * * @param activity Last activity sent from user. * @param telemetryProperties Additional properties to add to the event. * @returns A dictionary that is sent as "Properties" to botTelemetryClient.trackEvent method. @@ -254,6 +265,7 @@ export class TelemetryLoggerMiddleware implements Middleware { /** * Fills the Application Insights Custom Event properties for BotMessageSend. * These properties are logged in the custom event when a response message is sent by the Bot to the user. + * * @param activity - Last activity sent from user. * @param telemetryProperties Additional properties to add to the event. * @returns A dictionary that is sent as "Properties" to botTelemetryClient.trackEvent method. @@ -308,6 +320,7 @@ export class TelemetryLoggerMiddleware implements Middleware { * These properties are logged when an activity message is updated by the Bot. * For example, if a card is interacted with by the use, and the card needs to be updated to reflect * some interaction. + * * @param activity - Last activity sent from user. * @param telemetryProperties Additional properties to add to the event. * @returns A dictionary that is sent as "Properties" to botTelemetryClient.trackEvent method. @@ -345,6 +358,7 @@ export class TelemetryLoggerMiddleware implements Middleware { /** * Fills the Application Insights Custom Event properties for BotMessageDelete. * These properties are logged in the custom event when an activity message is deleted by the Bot. This is a relatively rare case. + * * @param activity - Last activity sent from user. * @param telemetryProperties Additional properties to add to the event. * @returns A dictionary that is sent as "Properties" to botTelemetryClient.trackEvent method. diff --git a/libraries/botbuilder-core/src/testAdapter.ts b/libraries/botbuilder-core/src/testAdapter.ts index 44e1c69a71..2548f9103b 100644 --- a/libraries/botbuilder-core/src/testAdapter.ts +++ b/libraries/botbuilder-core/src/testAdapter.ts @@ -33,6 +33,7 @@ import { TurnContext } from './turnContext'; * ```TypeScript * type TestActivityInspector = (activity: Partial, description: string) => void; * ``` + * * @param TestActivityInspector.activity The activity being inspected. * @param TestActivityInspector.description Text to log in the event of an error. */ @@ -59,8 +60,10 @@ export type TestActivityInspector = (activity: Partial, description?: export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider { /** * Creates a new TestAdapter instance. + * * @param logicOrConversation The bots logic that's under test. * @param template (Optional) activity containing default values to assign to all test messages received. + * @param sendTraceActivity Indicates whether the adapter should add to its queue any trace activities generated by the bot. */ public constructor( logicOrConversation?: ((context: TurnContext) => Promise) | ConversationReference, @@ -100,6 +103,8 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Gets a value indicating whether to send trace activities. + * + * @returns A value indicating whether to send trace activities. */ public get enableTrace(): boolean { return this._sendTraceActivity; @@ -129,9 +134,11 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Create a ConversationReference. + * * @param name name of the conversation (also id). * @param user name of the user (also id) default: User1. * @param bot name of the bot (also id) default: Bot. + * @returns The [ConversationReference](xref:botframework-schema.ConversationReference). */ public static createConversation(name: string, user = 'User1', bot = 'Bot'): ConversationReference { const conversationReference: ConversationReference = { @@ -146,7 +153,9 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider } /** - * Dequeues and returns the next bot response from the activeQueue + * Dequeues and returns the next bot response from the activeQueue. + * + * @returns The next activity in the queue; or undefined, if the queue is empty. */ public getNextReply(): Partial { if (this.activeQueue.length > 0) { @@ -157,7 +166,9 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Creates a message activity from text and the current conversational context. + * * @param text The message text. + * @returns An appropriate message activity. */ public makeActivity(text?: string): Partial { const activity: Partial = { @@ -175,8 +186,10 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Processes a message activity from a user. + * * @param userSays The text of the user's message. * @param callback The bot logic to invoke. + * @returns {Promise} A promise representing the async operation. */ public sendTextToBot(userSays: string, callback: (context: TurnContext) => Promise): Promise { return this.processActivity(this.makeActivity(userSays), callback); @@ -195,8 +208,10 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Receives an activity and runs it through the middleware pipeline. + * * @param activity The activity to process. * @param callback The bot logic to invoke. + * @returns {Promise} A promise representing the async operation. */ public async processActivity( activity: string | Partial, @@ -324,25 +339,30 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * The `TestAdapter` doesn't implement `continueConversation()` and will return an error if it's * called. + * + * @param _reference A reference to the conversation to continue. + * @param _logic The asynchronous method to call after the adapter middleware runs. + * @returns {Promise} A promise representing the async operation. */ public continueConversation( - reference: Partial, - logic: (revocableContext: TurnContext) => Promise + _reference: Partial, + _logic: (revocableContext: TurnContext) => Promise ): Promise { - return Promise.reject(new Error(`not implemented`)); + return Promise.reject(new Error('not implemented')); } /** * Creates a turn context. * * @param request An incoming request body. - * + * @returns The created [TurnContext](xref:botbuilder-core.TurnContext). * @remarks * Override this in a derived class to modify how the adapter creates a turn context. */ protected createContext(request: Partial): TurnContext { return new TurnContext(this, request); } + /** * Sends something to the bot. This returns a new `TestFlow` instance which can be used to add * additional steps for inspecting the bots reply and then sending additional activities. @@ -356,6 +376,8 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider * .then(() => done()); * ``` * @param userSays Text or activity simulating user input. + * @returns a new [TestFlow](xref:botbuilder-core.TestFlow) instance which can be used to add additional steps + * for inspecting the bots reply and then sending additional activities. */ public send(userSays: string | Partial): TestFlow { return new TestFlow(this.processActivity(userSays), this); @@ -375,13 +397,14 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider * @param userSays Text or activity simulating user input. * @param expected Expected text or activity of the reply sent by the bot. * @param description (Optional) Description of the test case. If not provided one will be generated. - * @param timeout (Optional) number of milliseconds to wait for a response from bot. Defaults to a value of `3000`. + * @param _timeout (Optional) number of milliseconds to wait for a response from bot. Defaults to a value of `3000`. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public test( userSays: string | Partial, expected: string | Partial | ((activity: Partial, description?: string) => void), description?: string, - timeout?: number + _timeout?: number ): TestFlow { return this.send(userSays).assertReply(expected, description); } @@ -395,6 +418,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider * @param activities Array of activities. * @param description (Optional) Description of the test case. If not provided one will be generated. * @param timeout (Optional) number of milliseconds to wait for a response from bot. Defaults to a value of `3000`. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public testActivities(activities: Partial[], description?: string, timeout?: number): TestFlow { if (!activities) { @@ -422,6 +446,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Adds a fake user token so it can later be retrieved. + * * @param connectionName The connection name. * @param channelId The channel id. * @param userId The user id. @@ -453,7 +478,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider * @param userId The ID of the user to retrieve the token status for. * @param includeFilter Optional. A comma-separated list of connection's to include. If present, * the `includeFilter` parameter limits the tokens this method returns. - * @param oAuthAppCredentials AppCredentials for OAuth. + * @param _oAuthAppCredentials AppCredentials for OAuth. * * @returns The [TokenStatus](xref:botframework-connector.TokenStatus) objects retrieved. */ @@ -461,14 +486,14 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider context: TurnContext, userId: string, includeFilter?: string, - oAuthAppCredentials?: any + _oAuthAppCredentials?: any ): Promise { if (!context || !context.activity) { throw new Error('testAdapter.getTokenStatus(): context with activity is required'); } if (!userId && (!context.activity.from || !context.activity.from.id)) { - throw new Error(`testAdapter.getTokenStatus(): missing userId, from or from.id`); + throw new Error('testAdapter.getTokenStatus(): missing userId, from or from.id'); } const filter = includeFilter ? includeFilter.split(',') : undefined; @@ -492,9 +517,11 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Retrieves the OAuth token for a user that is in a sign-in flow. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param magicCode (Optional) Optional user entered code to validate. + * @returns The OAuth token for a user that is in a sign-in flow. */ public async getUserToken( context: TurnContext, @@ -526,6 +553,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Signs the user out with the token server. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId User ID to sign out. @@ -542,8 +570,10 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Gets a signin link from the token server that can be sent as part of a SigninCard. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. + * @returns A signin link from the token server that can be sent as part of a SigninCard. */ public async getSignInLink(context: TurnContext, connectionName: string): Promise { return `https://fake.com/oauthsignin/${connectionName}/${context.activity.channelId}/${context.activity.from.id}`; @@ -551,13 +581,16 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Signs the user out with the token server. - * @param context Context for the current turn of conversation with the user. - * @param connectionName Name of the auth connection to use. + * + * @param _context Context for the current turn of conversation with the user. + * @param _connectionName Name of the auth connection to use. + * @param _resourceUrls The list of resource URLs to retrieve tokens for. + * @returns A Dictionary of resourceUrl to the corresponding TokenResponse. */ public async getAadTokens( - context: TurnContext, - connectionName: string, - resourceUrls: string[] + _context: TurnContext, + _connectionName: string, + _resourceUrls: string[] ): Promise<{ [propertyName: string]: TokenResponse; }> { @@ -568,6 +601,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Adds a fake exchangeable token so it can be exchanged later. + * * @param connectionName Name of the auth connection to use. * @param channelId Channel ID. * @param userId User ID. @@ -592,17 +626,18 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Gets a sign-in resource. + * * @param context [TurnContext](xref:botbuilder-core.TurnContext) for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId User ID - * @param finalRedirect Final redirect URL. + * @param _finalRedirect Final redirect URL. * @returns A `Promise` with a new [SignInUrlResponse](xref:botframework-schema.SignInUrlResponse) object. */ public async getSignInResource( context: TurnContext, connectionName: string, userId?: string, - finalRedirect?: string + _finalRedirect?: string ): Promise { return { signInLink: `https://botframeworktestadapter.com/oauthsignin/${connectionName}/${context.activity.channelId}/${userId}`, @@ -616,6 +651,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Performs a token exchange operation such as for single sign-on. + * * @param context [TurnContext](xref:botbuilder-core.TurnContext) for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId User id associated with the token. @@ -654,6 +690,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider /** * Adds an instruction to throw an exception during exchange requests. + * * @param connectionName The connection name. * @param channelId The channel id. * @param userId The user id. @@ -683,6 +720,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider * Checks to see if the from property and if from.role exists on the Activity before * checking to see who the activity is from. Otherwise returns false by default. * @param activity Activity to check. + * @returns True if the activity is a reply from the bot, otherwise, false. */ private isReply(activity: Partial): boolean { if (activity.from && activity.from.role) { @@ -767,10 +805,12 @@ export class TestFlow { * Send something to the bot and expects the bot to return with a given reply. This is simply a * wrapper around calls to `send()` and `assertReply()`. This is such a common pattern that a * helper is provided. + * * @param userSays Text or activity simulating user input. * @param expected Expected text or activity of the reply sent by the bot. * @param description (Optional) Description of the test case. If not provided one will be generated. * @param timeout (Optional) number of milliseconds to wait for a response from bot. Defaults to a value of `3000`. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public test( userSays: string | Partial, @@ -783,7 +823,9 @@ export class TestFlow { /** * Sends something to the bot. + * * @param userSays Text or activity simulating user input. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public send(userSays: string | Partial): TestFlow { return new TestFlow( @@ -813,9 +855,11 @@ export class TestFlow { /** * Generates an assertion if the bots response doesn't match the expected text/activity. + * * @param expected Expected text or activity from the bot. Can be a callback to inspect the response using custom logic. * @param description (Optional) Description of the test case. If not provided one will be generated. * @param timeout (Optional) number of milliseconds to wait for a response from bot. Defaults to a value of `3000`. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public assertReply( expected: string | Partial | TestActivityInspector, @@ -893,14 +937,16 @@ export class TestFlow { /** * Generates an assertion that the turn processing logic did not generate a reply from the bot, as expected. + * * @param description (Optional) Description of the test case. If not provided one will be generated. * @param timeout (Optional) number of milliseconds to wait for a response from bot. Defaults to a value of `3000`. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public assertNoReply(description?: string, timeout?: number): TestFlow { return new TestFlow( this.previous.then(() => { // tslint:disable-next-line:promise-must-complete - return new Promise((resolve: any, reject: any): void => { + return new Promise((resolve: any): void => { if (!timeout) { timeout = 3000; } @@ -935,9 +981,11 @@ export class TestFlow { /** * Generates an assertion if the bots response is not one of the candidate strings. + * * @param candidates List of candidate responses. * @param description (Optional) Description of the test case. If not provided one will be generated. * @param timeout (Optional) number of milliseconds to wait for a response from bot. Defaults to a value of `3000`. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public assertReplyOneOf(candidates: string[], description?: string, timeout?: number): TestFlow { return this.assertReply( @@ -960,12 +1008,14 @@ export class TestFlow { /** * Inserts a delay before continuing. - * @param ms ms to wait + * + * @param ms ms to wait. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public delay(ms: number): TestFlow { return new TestFlow( this.previous.then(() => { - return new Promise((resolve: any, reject: any): void => { + return new Promise((resolve: any, _reject: any): void => { setTimeout(resolve, ms); }); }), @@ -976,7 +1026,10 @@ export class TestFlow { /** * Adds a `then()` step to the tests promise chain. + * * @param onFulfilled Code to run if the test is currently passing. + * @param onRejected Code to run if the test has thrown an error. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public then(onFulfilled?: () => void, onRejected?: (err) => void): TestFlow { return new TestFlow(this.previous.then(onFulfilled, onRejected), this.adapter, this.callback); @@ -984,8 +1037,9 @@ export class TestFlow { /** * Adds a finally clause. Note that you can't keep chaining afterwards. - * @param onFinally - * @returns + * + * @param onFinally Code to run after the test chain. + * @returns {Promise} A promise representing the async operation. */ public finally(onFinally: () => void): Promise { return Promise.resolve(this.previous.finally(onFinally)); @@ -993,14 +1047,18 @@ export class TestFlow { /** * Adds a `catch()` clause to the tests promise chain. + * * @param onRejected Code to run if the test has thrown an error. + * @returns A new [TestFlow](xref:botbuilder-core.TestFlow) object that appends this exchange to the modeled exchange. */ public catch(onRejected?: (reason: any) => void): TestFlow { return new TestFlow(this.previous.catch(onRejected), this.adapter, this.callback); } /** - * Start the test sequence, returning a promise to await + * Start the test sequence, returning a promise to await. + * + * @returns {Promise} A promise representing the async operation. */ public startTest(): Promise { return this.previous; diff --git a/libraries/botbuilder-core/src/transcriptLogger.ts b/libraries/botbuilder-core/src/transcriptLogger.ts index 0998a65aa8..08efd76ed6 100644 --- a/libraries/botbuilder-core/src/transcriptLogger.ts +++ b/libraries/botbuilder-core/src/transcriptLogger.ts @@ -25,6 +25,7 @@ export class TranscriptLoggerMiddleware implements Middleware { /** * Middleware for logging incoming and outgoing activities to a transcript store. + * * @param logger Transcript logger */ constructor(logger: TranscriptLogger) { @@ -37,6 +38,7 @@ export class TranscriptLoggerMiddleware implements Middleware { /** * Initialization for middleware turn. + * * @param context Context for the current turn of conversation with the user. * @param next Function to call at the end of the middleware chain. */ @@ -145,6 +147,8 @@ export class TranscriptLoggerMiddleware implements Middleware { /** * Logs the Activity. + * + * @param transcript Array where the activity will be pushed. * @param activity Activity to log. */ private logActivity(transcript: Activity[], activity: Activity): void { @@ -160,7 +164,9 @@ export class TranscriptLoggerMiddleware implements Middleware { /** * Clones the Activity entity. + * * @param activity Activity to clone. + * @returns The cloned activity. */ private cloneActivity(activity: Partial): Activity { return Object.assign({}, activity); @@ -168,6 +174,7 @@ export class TranscriptLoggerMiddleware implements Middleware { /** * Error logging helper function. + * * @param err Error or object to console.error out. */ private transcriptLoggerErrorHandler(err: Error | any): void { @@ -188,6 +195,7 @@ export class TranscriptLoggerMiddleware implements Middleware { export class ConsoleTranscriptLogger implements TranscriptLogger { /** * Log an activity to the transcript. + * * @param activity Activity being logged. */ public logActivity(activity: Activity): void | Promise { @@ -206,6 +214,7 @@ export class ConsoleTranscriptLogger implements TranscriptLogger { export interface TranscriptLogger { /** * Log an activity to the transcript. + * * @param activity Activity being logged. */ logActivity(activity: Activity): void | Promise; @@ -217,6 +226,7 @@ export interface TranscriptLogger { export interface TranscriptStore extends TranscriptLogger { /** * Get activities for a conversation (Aka the transcript) + * * @param channelId Channel Id. * @param conversationId Conversation Id. * @param continuationToken Continuation token to page through results. @@ -231,6 +241,7 @@ export interface TranscriptStore extends TranscriptLogger { /** * List conversations in the channelId. + * * @param channelId Channel Id. * @param continuationToken Continuation token to page through results. */ @@ -238,6 +249,7 @@ export interface TranscriptStore extends TranscriptLogger { /** * Delete a specific conversation and all of its activities. + * * @param channelId Channel Id where conversation took place. * @param conversationId Id of the conversation to delete. */ @@ -266,6 +278,7 @@ export interface TranscriptInfo { /** * Page of results. + * * @param T type of items being paged in. */ // tslint:disable-next-line:max-classes-per-file diff --git a/libraries/botbuilder-core/src/turnContext.ts b/libraries/botbuilder-core/src/turnContext.ts index 9df2ef0084..5eb85b5665 100644 --- a/libraries/botbuilder-core/src/turnContext.ts +++ b/libraries/botbuilder-core/src/turnContext.ts @@ -133,7 +133,7 @@ function getAppropriateReplyToId(source: Partial): string | undefined return undefined; } -// tslint:disable-next-line:no-empty-interface +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface TurnContext {} /** @@ -192,7 +192,7 @@ export class TurnContext { * Use with caution; this function alters the activity's [text](xref:botframework-schema.Activity.text) property. * * @param activity The activity to remove at mentions from. - * + * @returns The updated activity's text. * @remarks * Some channels, for example Microsoft Teams, add at-mention details to the text of a message activity. * @@ -217,7 +217,7 @@ export class TurnContext { * * @param activity The activity to remove at mentions from. * @param id The ID of the user or bot to remove at mentions for. - * + * @returns The updated activity's text. * @remarks * Some channels, for example Microsoft Teams, add at mentions to the text of a message activity. * @@ -254,7 +254,7 @@ export class TurnContext { * Gets all at-mention entities included in an activity. * * @param activity The activity. - * + * @returns All the at-mention entities included in an activity. * @remarks * The activity's [entities](xref:botframework-schema.Activity.entities) property contains a flat * list of metadata objects pertaining to this activity and can contain @@ -282,7 +282,7 @@ export class TurnContext { * Copies conversation reference information from an activity. * * @param activity The activity to get the information from. - * + * @returns A conversation reference for the conversation that contains this activity. * @remarks * You can save the conversation reference as a JSON object and use it later to proactively message the user. * @@ -315,7 +315,7 @@ export class TurnContext { * @param isIncoming Optional. `true` to treat the activity as an incoming activity, where the * bot is the recipient; otherwise, `false`. Default is `false`, and the activity will show * the bot as the sender. - * + * @returns This activity, updated with the delivery information. * @remarks * Call the [getConversationReference](xref:botbuilder-core.TurnContext.getConversationReference) * method on an incoming activity to get a conversation reference that you can then use @@ -354,7 +354,7 @@ export class TurnContext { * @param reply The resource response for the activity, returned by the * [sendActivity](xref:botbuilder-core.TurnContext.sendActivity) or * [sendActivities](xref:botbuilder-core.TurnContext.sendActivities) method. - * + * @returns A ConversationReference that can be stored and used later to delete or update the activity. * @remarks * You can save the conversation reference as a JSON object and use it later to update or delete the message. * @@ -393,7 +393,7 @@ export class TurnContext { * @param value Optional. The text to be spoken by your bot on a speech-enabled channel. * @param valueType Optional. Indicates whether your bot is accepting, expecting, or ignoring user * @param label Optional. Indicates whether your bot is accepting, expecting, or ignoring user - * + * @returns A promise with a ResourceResponse. * @remarks * Creates and sends a Trace activity. Trace activities are only sent when the channel is the emulator. * @@ -431,7 +431,7 @@ export class TurnContext { * @param inputHint Optional. Indicates whether your bot is accepting, expecting, or ignoring user * input after the message is delivered to the client. One of: 'acceptingInput', 'ignoringInput', * or 'expectingInput'. Default is 'acceptingInput'. - * + * @returns A promise with a ResourceResponse. * @remarks * If the activity is successfully sent, results in a * [ResourceResponse](xref:botframework-schema.ResourceResponse) object containing the ID that the @@ -476,7 +476,7 @@ export class TurnContext { * Asynchronously sends a set of activities to the sender of the incoming activity. * * @param activities The activities to send. - * + * @returns A promise with a ResourceResponse. * @remarks * If the activities are successfully sent, results in an array of * [ResourceResponse](xref:botframework-schema.ResourceResponse) objects containing the IDs that @@ -560,7 +560,7 @@ export class TurnContext { * Asynchronously updates a previously sent activity. * * @param activity The replacement for the original activity. - * + * @returns A promise with a ResourceResponse. * @remarks * The [id](xref:botframework-schema.Activity.id) of the replacement activity indicates the activity * in the conversation to replace. @@ -590,7 +590,7 @@ export class TurnContext { * Asynchronously deletes a previously sent activity. * * @param idOrReference ID or conversation reference for the activity to delete. - * + * @returns A promise representing the async operation. * @remarks * If an ID is specified, the conversation reference for the current request is used * to get the rest of the information needed. @@ -626,7 +626,7 @@ export class TurnContext { * Adds a response handler for send activity operations. * * @param handler The handler to add to the context object. - * + * @returns The updated context object. * @remarks * This method returns a reference to the turn context object. * @@ -657,7 +657,7 @@ export class TurnContext { * Adds a response handler for update activity operations. * * @param handler The handler to add to the context object. - * + * @returns The updated context object. * @remarks * This method returns a reference to the turn context object. * @@ -687,7 +687,7 @@ export class TurnContext { * Adds a response handler for delete activity operations. * * @param handler The handler to add to the context object. - * + * @returns The updated context object. * @remarks * This method returns a reference to the turn context object. * @@ -739,6 +739,8 @@ export class TurnContext { /** * Gets the bot adapter that created this context object. + * + * @returns The bot adapter that created this context object. */ public get adapter(): BotAdapter { return this._adapter as BotAdapter; @@ -747,6 +749,7 @@ export class TurnContext { /** * Gets the activity associated with this turn. * + * @returns The activity associated with this turn. * @remarks * This example shows how to get the users trimmed utterance from the activity: * @@ -761,6 +764,7 @@ export class TurnContext { /** * Indicates whether the bot has replied to the user this turn. * + * @returns True if at least one response was sent for the current turn; otherwise, false. * @remarks * **true** if at least one response was sent for the current turn; otherwise, **false**. * Use this to determine if your bot needs to run fallback logic after other normal processing. @@ -779,8 +783,26 @@ export class TurnContext { return this._respondedRef.responded; } + /** + * Sets the response flag on the current turn context. + * + * @remarks + * The [sendActivity](xref:botbuilder-core.TurnContext.sendActivity) and + * [sendActivities](xref:botbuilder-core.TurnContext.sendActivities) methods call this method to + * update the responded flag. You can call this method directly to indicate that your bot has + * responded appropriately to the incoming activity. + */ + public set responded(value: boolean) { + if (!value) { + throw new Error("TurnContext: cannot set 'responded' to a value of 'false'."); + } + this._respondedRef.responded = true; + } + /** * Gets the locale stored in the turnState. + * + * @returns The locale stored in the turnState. */ public get locale(): string | undefined { const turnObj = this._turnState[this._turn]; @@ -804,25 +826,10 @@ export class TurnContext { } } - /** - * Sets the response flag on the current turn context. - * - * @remarks - * The [sendActivity](xref:botbuilder-core.TurnContext.sendActivity) and - * [sendActivities](xref:botbuilder-core.TurnContext.sendActivities) methods call this method to - * update the responded flag. You can call this method directly to indicate that your bot has - * responded appropriately to the incoming activity. - */ - public set responded(value: boolean) { - if (!value) { - throw new Error(`TurnContext: cannot set 'responded' to a value of 'false'.`); - } - this._respondedRef.responded = true; - } - /** * Gets the services registered on this context object. * + * @returns The services registered on this context object. * @remarks * Middleware, other components, and services will typically use this to cache information * that could be asked for by a bot multiple times during a turn. You can use this cache to diff --git a/libraries/botbuilder-core/src/turnContextStateCollection.ts b/libraries/botbuilder-core/src/turnContextStateCollection.ts index 5d4c310c3d..7f14621fea 100644 --- a/libraries/botbuilder-core/src/turnContextStateCollection.ts +++ b/libraries/botbuilder-core/src/turnContextStateCollection.ts @@ -7,28 +7,38 @@ const TURN_STATE_SCOPE_CACHE = Symbol('turnStateScopeCache'); /** * Values persisted for the lifetime of the turn as part of the [TurnContext](xref:botbuilder-core.TurnContext). + * * @remarks Typical values stored here are objects which are needed for the lifetime of a turn, such * as [Storage](xref:botbuilder-core.Storage), [BotState](xref:botbuilder-core.BotState), [ConversationState](xref:botbuilder-core.ConversationState), [LanguageGenerator](xref:botbuilder-dialogs-adaptive.LanguageGenerator), [ResourceExplorer](xref:botbuilder-dialogs-declarative.ResourceExplorer), etc. */ export class TurnContextStateCollection extends Map { - /** * Gets a typed value from the [TurnContextStateCollection](xref:botbuilder-core.TurnContextStateCollection). + * * @param key The values key. */ public get(key: any): T; /** * Gets a value from the [TurnContextStateCollection](xref:botbuilder-core.TurnContextStateCollection). + * * @param key The values key. */ public get(key: any): any; + + /** + * Gets a value from the [TurnContextStateCollection](xref:botbuilder-core.TurnContextStateCollection). + * + * @param key The values key. + * @returns The object; or null if no service is registered by the key. + */ public get(key: any): unknown { return super.get(key); } /** * Push a value by key to the turn's context. + * * @remarks * The keys current value (if any) will be saved and can be restored by calling [pop()](#pop). * @param key The values key. @@ -54,6 +64,7 @@ export class TurnContextStateCollection extends Map { /** * Restores a keys previous value, and returns the value that was removed. + * * @param key The values key. * @returns The removed value. */ diff --git a/libraries/botbuilder-core/src/userState.ts b/libraries/botbuilder-core/src/userState.ts index 8c9b5d6b10..9bc6038578 100644 --- a/libraries/botbuilder-core/src/userState.ts +++ b/libraries/botbuilder-core/src/userState.ts @@ -10,7 +10,7 @@ import { BotState } from './botState'; import { Storage } from './storage'; import { TurnContext } from './turnContext'; -const NO_KEY = `UserState: overridden getStorageKey method did not return a key.`; +const NO_KEY = 'UserState: overridden getStorageKey method did not return a key.'; /** * Reads and writes user state for your bot to storage. @@ -28,6 +28,7 @@ const NO_KEY = `UserState: overridden getStorageKey method did not return a key. export class UserState extends BotState { /** * Creates a new UserState instance. + * * @param storage Storage provider to persist user state to. * @param namespace (Optional) namespace to append to storage keys. Defaults to an empty string. */ @@ -42,7 +43,9 @@ export class UserState extends BotState { /** * Returns the storage key for the current user state. + * * @param context Context for current turn of conversation with the user. + * @returns The storage key for the current user state. */ public getStorageKey(context: TurnContext): string | undefined { const activity: Activity = context.activity; diff --git a/libraries/botbuilder-core/src/userTokenProvider.ts b/libraries/botbuilder-core/src/userTokenProvider.ts index 7f9cd11dd3..15a542a3b2 100644 --- a/libraries/botbuilder-core/src/userTokenProvider.ts +++ b/libraries/botbuilder-core/src/userTokenProvider.ts @@ -12,11 +12,12 @@ import { TokenResponse } from 'botframework-schema'; /** * Interface for User Token OAuth APIs for BotAdapters * - * @obsolete Use `UserTokenClient` instead. + * @deprecated Use `UserTokenClient` instead. */ export interface IUserTokenProvider { /** * Retrieves the OAuth token for a user that is in a sign-in flow. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param magicCode (Optional) Optional user entered code to validate. @@ -25,6 +26,7 @@ export interface IUserTokenProvider { /** * Signs the user out with the token server. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. * @param userId User id of user to sign out. @@ -33,6 +35,7 @@ export interface IUserTokenProvider { /** * Retrieves the token status for each configured connection for the given user, using the bot's AppCredentials. + * * @param context Context for the current turn of conversation with the user. * @param userId The user Id for which token status is retrieved. * @param includeFilter Comma separated list of connection's to include. Blank will return token status for all configured connections. @@ -47,6 +50,7 @@ export interface IUserTokenProvider { /** * Gets a signin link from the token server that can be sent as part of a SigninCard. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. */ @@ -54,6 +58,7 @@ export interface IUserTokenProvider { /** * Signs the user out with the token server. + * * @param context Context for the current turn of conversation with the user. * @param connectionName Name of the auth connection to use. */ From 000a6f281d2c8403ad5f45f28a9263c34cf8e1b9 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Mon, 2 May 2022 12:06:20 -0300 Subject: [PATCH 2/4] Fix depcheck error --- .../botbuilder-core/tests/botAdapter.test.js | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/libraries/botbuilder-core/tests/botAdapter.test.js b/libraries/botbuilder-core/tests/botAdapter.test.js index 655ed1c25a..3ac1eca9ff 100644 --- a/libraries/botbuilder-core/tests/botAdapter.test.js +++ b/libraries/botbuilder-core/tests/botAdapter.test.js @@ -1,5 +1,4 @@ const assert = require('assert'); -const { uniqueId } = require('lodash'); const sinon = require('sinon'); const { BotAdapter, TurnContext } = require('../'); @@ -12,13 +11,13 @@ class SimpleAdapter extends BotAdapter { } } -describe('BotAdapter', () => { +describe('BotAdapter', function () { let sandbox; - beforeEach(() => { + beforeEach(function () { sandbox = sinon.createSandbox(); }); - afterEach(() => { + afterEach(function () { sandbox.restore(); }); @@ -26,18 +25,18 @@ describe('BotAdapter', () => { const getAdapter = () => new SimpleAdapter(); - describe('middleware handling', () => { - it('should use() middleware individually', () => { + describe('middleware handling', function () { + it('should use() middleware individually', function () { const adapter = getAdapter(); adapter.use(getNextFake()).use(getNextFake()); }); - it('should use() a list of middleware', () => { + it('should use() a list of middleware', function () { const adapter = getAdapter(); adapter.use(getNextFake(), getNextFake(), getNextFake()); }); - it('should run all middleware', async () => { + it('should run all middleware', async function () { const adapter = getAdapter(); const middlewares = [getNextFake(), getNextFake()]; @@ -57,8 +56,8 @@ describe('BotAdapter', () => { }); }); - describe('Get locale from activity', () => { - it('should have locale', async () => { + describe('Get locale from activity', function () { + it('should have locale', async function () { const adapter = getAdapter(); const activity = testMessage; activity.locale = 'de-DE'; @@ -71,7 +70,7 @@ describe('BotAdapter', () => { }); }); - describe('onTurnError', () => { + describe('onTurnError', function () { const testCases = [ { label: 'promise is rejected', logic: () => Promise.reject('error') }, { @@ -83,7 +82,7 @@ describe('BotAdapter', () => { ]; testCases.forEach(({ label, logic }) => { - it(`should reach onTurnError when a ${label}`, async () => { + it(`should reach onTurnError when a ${label}`, async function () { const adapter = getAdapter(); adapter.onTurnError = sandbox.fake((context, error) => { @@ -99,7 +98,7 @@ describe('BotAdapter', () => { assert(handler.called, 'handler was called'); }); - it(`should propagate error when onTurnError is not defined and a ${label}`, async () => { + it(`should propagate error when onTurnError is not defined and a ${label}`, async function () { const adapter = getAdapter(); const handler = sandbox.fake(logic); @@ -112,7 +111,7 @@ describe('BotAdapter', () => { assert(handler.called, 'handler was called'); }); - it(`should propagate error if a ${label} in onTurnError when a ${label} in handler`, async () => { + it(`should propagate error if a ${label} in onTurnError when a ${label} in handler`, async function () { const adapter = getAdapter(); adapter.onTurnError = sandbox.fake((context, error) => { @@ -134,8 +133,8 @@ describe('BotAdapter', () => { }); }); - describe('proxy context revocation', () => { - it('should revoke after execution', async () => { + describe('proxy context revocation', function () { + it('should revoke after execution', async function () { const adapter = getAdapter(); const handler = sandbox.fake((context) => { @@ -149,7 +148,7 @@ describe('BotAdapter', () => { assert.throws(() => context.activity, 'accessing context property should throw since it has been revoked'); }); - it('should revoke after onTurnError', async () => { + it('should revoke after onTurnError', async function () { const adapter = getAdapter(); adapter.onTurnError = sandbox.fake((context) => { @@ -165,7 +164,7 @@ describe('BotAdapter', () => { assert.throws(() => context.activity, 'accessing context property should throw since it has been revoked'); }); - it('should revoke after unhandled error', async () => { + it('should revoke after unhandled error', async function () { const adapter = getAdapter(); const handler = sandbox.fake(() => Promise.reject('error')); From a11832fead13b32706017b257079116bc58de121 Mon Sep 17 00:00:00 2001 From: Tracy Boehrer Date: Thu, 16 Jun 2022 10:25:50 -0500 Subject: [PATCH 3/4] Corrected conflict resolution error --- libraries/botbuilder-core/src/turnContext.ts | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/libraries/botbuilder-core/src/turnContext.ts b/libraries/botbuilder-core/src/turnContext.ts index 7e3fdb57b5..c245f3f7f4 100644 --- a/libraries/botbuilder-core/src/turnContext.ts +++ b/libraries/botbuilder-core/src/turnContext.ts @@ -798,7 +798,7 @@ export class TurnContext { } this._respondedRef.responded = true; } - + /** * Gets the locale stored in the turnState. * @@ -826,22 +826,6 @@ export class TurnContext { } } - /** - * Sets the response flag on the current turn context. - * - * @remarks - * The [sendActivity](xref:botbuilder-core.TurnContext.sendActivity) and - * [sendActivities](xref:botbuilder-core.TurnContext.sendActivities) methods call this method to - * update the responded flag. You can call this method directly to indicate that your bot has - * responded appropriately to the incoming activity. - */ - set responded(value: boolean) { - if (!value) { - throw new Error(`TurnContext: cannot set 'responded' to a value of 'false'.`); - } - this._respondedRef.responded = true; - } - /** * Gets the services registered on this context object. * From 77ee4ddde55c6316df9ce91a74352702c5d1986b Mon Sep 17 00:00:00 2001 From: Tracy Boehrer Date: Thu, 16 Jun 2022 10:30:43 -0500 Subject: [PATCH 4/4] Fixed accessor conflict --- libraries/botbuilder-core/src/turnContext.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/botbuilder-core/src/turnContext.ts b/libraries/botbuilder-core/src/turnContext.ts index c245f3f7f4..db0d721934 100644 --- a/libraries/botbuilder-core/src/turnContext.ts +++ b/libraries/botbuilder-core/src/turnContext.ts @@ -792,7 +792,7 @@ export class TurnContext { * update the responded flag. You can call this method directly to indicate that your bot has * responded appropriately to the incoming activity. */ - public set responded(value: boolean) { + set responded(value: boolean) { if (!value) { throw new Error("TurnContext: cannot set 'responded' to a value of 'false'."); }