Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [#4204] Fix remaining eslint warnings - botbuilder-dialogs (2/2) #4232

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export enum DialogReason {
replaceCalled = "replaceCalled"
}

// @public (undocumented)
// @public
export class DialogsBotComponent extends BotComponent {
// (undocumented)
configureServices(services: ServiceCollection, configuration: Configuration): void;
Expand Down
6 changes: 5 additions & 1 deletion libraries/botbuilder-dialogs/src/choices/choiceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class ChoiceFactory {
* @param text (Optional) text of the message.
* @param speak (Optional) SSML to speak for the message.
* @param options (Optional) formatting options to use when rendering as a list.
* @returns The created message activity.
*/
static forChannel(
channelOrContext: string | TurnContext,
Expand Down Expand Up @@ -134,7 +135,6 @@ export class ChoiceFactory {
}
}


/**
* Creates a message [Activity](xref:botframework-schema.Activity) that includes a [Choice](xref:botbuilder-dialogs.Choice) list that have been added as `HeroCard`'s.
*
Expand Down Expand Up @@ -172,6 +172,7 @@ export class ChoiceFactory {
* @param text (Optional) text of the message.
* @param speak (Optional) SSML to speak for the message.
* @param options (Optional) formatting options to tweak rendering of list.
* @returns The created message activity.
*/
static inline(
choices: (string | Choice)[],
Expand Down Expand Up @@ -222,6 +223,7 @@ export class ChoiceFactory {
* @param text (Optional) text of the message.
* @param speak (Optional) SSML to speak for the message.
* @param options (Optional) formatting options to tweak rendering of list.
* @returns The created message activity.
*/
static list(
choices: (string | Choice)[],
Expand Down Expand Up @@ -263,6 +265,7 @@ export class ChoiceFactory {
* @param choices List of choices to add.
* @param text (Optional) text of the message.
* @param speak (Optional) SSML to speak for the message.
* @returns An activity with choices as suggested actions.
*/
static suggestedAction(choices: (string | Choice)[], text?: string, speak?: string): Partial<Activity> {
// Map choices to actions
Expand Down Expand Up @@ -291,6 +294,7 @@ export class ChoiceFactory {
* const choices = ChoiceFactory.toChoices(['red', 'green', 'blue']);
* ```
* @param choices List of choices to add.
* @returns A list of choices.
*/
static toChoices(choices: (string | Choice)[] | undefined): Choice[] {
return (choices || [])
Expand Down
1 change: 1 addition & 0 deletions libraries/botbuilder-dialogs/src/choices/findChoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export interface FoundChoice {
* @param utterance The text or user utterance to search over. For an incoming 'message' activity you can simply use `context.activity.text`.
* @param choices List of choices to search over.
* @param options (Optional) options used to tweak the search that's performed.
* @returns A list of found choices, sorted by most relevant first.
*/
export function findChoices(
utterance: string,
Expand Down
4 changes: 3 additions & 1 deletion libraries/botbuilder-dialogs/src/choices/findValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ export interface SortedValue {
* functions like `findChoices()` and `recognizeChoices()` are layered above this function. In most
* cases its easier to just call one of the higher level functions instead but this function contains
* the fuzzy search algorithm that drives choice recognition.
*
* @param utterance The text or user utterance to search over.
* @param values List of values to search over.
* @param options (Optional) options used to tweak the search that's performed.
* @returns A list of found values.
*/
// tslint:disable-next-line:max-func-body-length
export function findValues(
Expand Down Expand Up @@ -233,7 +235,7 @@ export function findValues(
const usedTokens: { [index: number]: boolean } = {};
matches.forEach((match: ModelResult<FoundValue>) => {
// Apply filters
let add = !foundIndexes.hasOwnProperty(match.resolution.index);
let add = !Object.prototype.hasOwnProperty.call(foundIndexes, match.resolution.index);
for (let i: number = match.start; i <= match.end; i++) {
if (usedTokens[i]) {
add = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { ModelResult } from './modelResult';
* @param utterance The text or user utterance to search over. For an incoming 'message' activity you can simply use `context.activity.text`.
* @param choices List of choices to search over.
* @param options (Optional) options used to tweak the search that's performed.
* @returns A list of found choices, sorted by most relevant first.
*/
export function recognizeChoices(
utterance: string,
Expand All @@ -63,7 +64,7 @@ export function recognizeChoices(
},
});
}
} catch (e) {
} catch {
// noop
// TODO: Should this log an error or do something?
}
Expand Down
6 changes: 6 additions & 0 deletions libraries/botbuilder-dialogs/src/configurable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { Converter, ConverterFactory } from './converter';
export abstract class Configurable {
/**
* Fluent method for configuring the object.
*
* @param config Configuration settings to apply.
* @returns The [Configurable](xref:botbuilder-dialogs.Configurable) after the operation is complete.
*/
configure(config: Record<string, unknown>): this {
for (const key in config) {
Expand Down Expand Up @@ -46,6 +48,10 @@ export abstract class Configurable {
return this;
}

/**
* @param _property The key of the conditional selector configuration.
* @returns The converter for the selector configuration.
*/
getConverter(_property: string): Converter | ConverterFactory {
return undefined;
}
Expand Down
6 changes: 6 additions & 0 deletions libraries/botbuilder-dialogs/src/dialogContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ export abstract class DialogContainer<O extends object = {}> extends Dialog<O> {

/**
* Creates an inner dialog context for the containers active child.
*
* @param dc Parents dialog context.
* @returns A new dialog context for the active child or `undefined` if there is no active child.
*/
abstract createChildContext(dc: DialogContext): DialogContext | undefined;

/**
* Finds a child dialog that was previously added to the container.
*
* @param dialogId ID of the dialog to lookup.
* @returns The Dialog if found; otherwise null.
*/
findDialog(dialogId: string): Dialog | undefined {
return this.dialogs.find(dialogId);
Expand All @@ -41,6 +44,7 @@ export abstract class DialogContainer<O extends object = {}> extends Dialog<O> {
*
* @param dc The dialog context for the current turn of conversation.
* @param e The event being raised.
* @returns True if the event is handled by the current dialog and bubbling should stop.
*/
async onDialogEvent(dc: DialogContext, e: DialogEvent): Promise<boolean> {
const handled = await super.onDialogEvent(dc, e);
Expand Down Expand Up @@ -104,6 +108,8 @@ export abstract class DialogContainer<O extends object = {}> extends Dialog<O> {

/**
* Get the current telemetry client.
*
* @returns The [BotTelemetryClient](xref:botbuilder.BotTelemetryClient) to use for logging.
*/
get telemetryClient(): BotTelemetryClient {
return this._telemetryClient;
Expand Down
18 changes: 14 additions & 4 deletions libraries/botbuilder-dialogs/src/dialogHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export async function runDialog(
}

const dialogSet = new DialogSet(accessor);
dialogSet.telemetryClient = context.turnState.get<BotTelemetryClient>(BotTelemetryClientKey) ?? dialog.telemetryClient;
dialogSet.telemetryClient =
context.turnState.get<BotTelemetryClient>(BotTelemetryClientKey) ?? dialog.telemetryClient;

dialogSet.add(dialog);

Expand All @@ -64,6 +65,13 @@ export async function runDialog(
await internalRun(context, dialog.id, dialogContext);
}

/**
* @param context The [TurnContext](xref:botbuilder-core.TurnContext) for the turn.
* @param dialogId The dialog ID.
* @param dialogContext The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation.
* @param dialogStateManagerConfiguration Configuration for the dialog state manager.
* @returns {Promise<DialogTurnResult>} a promise resolving to the dialog turn result.
*/
export async function internalRun(
context: TurnContext,
dialogId: string,
Expand Down Expand Up @@ -174,8 +182,9 @@ async function innerRun(
/**
* Helper to determine if we should send an EoC to the parent or not.
*
* @param context
* @param turnResult
* @param context The [TurnContext](xref:botbuilder-core.TurnContext) for the turn.
* @param turnResult The dialog turn result.
* @returns True if should send EoC, otherwise false.
*/
export function shouldSendEndOfConversationToParent(context: TurnContext, turnResult: DialogTurnResult): boolean {
if (!(turnResult.status == DialogTurnStatus.complete || turnResult.status == DialogTurnStatus.cancelled)) {
Expand Down Expand Up @@ -241,7 +250,8 @@ export function isFromParentToSkill(context: TurnContext): boolean {
const sendStateSnapshotTrace = async (dialogContext: DialogContext): Promise<void> => {
const adapter = dialogContext.context.adapter;
const claimIdentity = dialogContext.context.turnState.get<ClaimsIdentity>(adapter.BotIdentityKey);
const traceLabel = claimIdentity && SkillValidation.isSkillClaim(claimIdentity.claims) ? 'Skill State' : 'Bot State';
const traceLabel =
claimIdentity && SkillValidation.isSkillClaim(claimIdentity.claims) ? 'Skill State' : 'Bot State';

// Send trace of memory
const snapshot = getActiveDialogContext(dialogContext).state.getMemorySnapshot();
Expand Down
18 changes: 13 additions & 5 deletions libraries/botbuilder-dialogs/src/dialogSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class DialogSet {
/**
* Returns a 32-bit hash of the all the `Dialog.version` values in the set.
*
* @returns A version that will change when any of the child dialogs version changes.
* @remarks
* This hash is persisted to state storage and used to detect changes to a dialog set.
*/
Expand Down Expand Up @@ -123,17 +124,18 @@ export class DialogSet {
* of "duplicate2".
* @param dialog The dialog or prompt to add.
* If a telemetryClient is present on the dialog set, it will be added to each dialog.
* @returns The dialog set after the operation is complete.
*/
add<T extends Dialog>(dialog: T): this {
if (!(dialog instanceof Dialog)) {
throw new Error(`DialogSet.add(): Invalid dialog being added.`);
throw new Error('DialogSet.add(): Invalid dialog being added.');
}

// Ensure new version hash is computed
this._version = undefined;

// Ensure dialogs ID is unique.
if (this.dialogs.hasOwnProperty(dialog.id)) {
if (Object.prototype.hasOwnProperty.call(this.dialogs, dialog.id)) {
// If we are trying to add the same exact instance, it's not a name collision.
// No operation required since the instance is already in the dialog set.
if (this.dialogs[dialog.id] === dialog) {
Expand All @@ -143,9 +145,10 @@ export class DialogSet {
// If we are adding a new dialog with a conflicting name, add a suffix to avoid
// dialog name collisions.
let nextSuffix = 2;
// eslint-disable-next-line no-constant-condition
while (true) {
const suffixId = dialog.id + nextSuffix.toString();
if (!this.dialogs.hasOwnProperty(suffixId)) {
if (!Object.prototype.hasOwnProperty.call(this.dialogs, suffixId)) {
dialog.id = suffixId;
break;
} else {
Expand Down Expand Up @@ -174,12 +177,14 @@ export class DialogSet {

/**
* Creates a dialog context which can be used to work with the dialogs in the set.
*
* @param context Context for the current turn of conversation with the user.
* @returns A promise representing the asynchronous operation.
*/
async createContext(context: TurnContext): Promise<DialogContext> {
if (!this.dialogState) {
throw new Error(
`DialogSet.createContext(): the dialog set was not bound to a stateProperty when constructed.`
'DialogSet.createContext(): the dialog set was not bound to a stateProperty when constructed.'
);
}
const state: DialogState = await this.dialogState.get(context, { dialogStack: [] } as DialogState);
Expand All @@ -197,13 +202,16 @@ export class DialogSet {
* const dialog = dialogs.find('greeting');
* ```
* @param dialogId ID of the dialog or prompt to lookup.
* @returns The dialog if found; otherwise undefined.
*/
find(dialogId: string): Dialog | undefined {
return this.dialogs.hasOwnProperty(dialogId) ? this.dialogs[dialogId] : undefined;
return Object.prototype.hasOwnProperty.call(this.dialogs, dialogId) ? this.dialogs[dialogId] : undefined;
}

/**
* Set the telemetry client for this dialog set and apply it to all current dialogs.
*
* @returns The [BotTelemetryClient](xref:botbuilder.BotTelemetryClient) to use for logging.
*/
get telemetryClient(): BotTelemetryClient {
return this._telemetryClient;
Expand Down
7 changes: 7 additions & 0 deletions libraries/botbuilder-dialogs/src/dialogsBotComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ import {

const InitialSettings = z.record(z.unknown());

/**
* Bot component for bot Dialogs.
*/
export class DialogsBotComponent extends BotComponent {
/**
* @param services Services Collection to register.
* @param configuration Configuration for the bot component.
*/
configureServices(services: ServiceCollection, configuration: Configuration): void {
services.composeFactory<MemoryScope[]>('memoryScopes', (memoryScopes) => {
const rootConfiguration = configuration.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class DialogsComponentRegistration
pathResolvers: [],
});

/**
* Creates an instance of the [DialogsComponentRegistration](xref:botbuilder-dialogs.DialogsComponentRegistration) class.
*/
constructor() {
super();

Expand Down
1 change: 1 addition & 0 deletions libraries/botbuilder-dialogs/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DialogContext } from './dialogContext';
export interface TemplateInterface<T, D = Record<string, unknown>> {
/**
* Given the turn context bind to the data to create the object
*
* @param dialogContext DialogContext.
* @param data Data to bind to.
* @returns Instance of T.
Expand Down
11 changes: 10 additions & 1 deletion libraries/botbuilder-dialogs/src/waterfallDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { WaterfallStepContext } from './waterfallStepContext';
* ```TypeScript
* type WaterfallStep<O extends object = {}> = (step: WaterfallStepContext<O>) => Promise<DialogTurnResult>;
* ```
*
* @param O (Optional) type of dialog options passed into the step.
* @param WaterfallStep.step Contextual information for the current step being executed.
*/
Expand Down Expand Up @@ -91,12 +92,13 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {

/**
* Gets the dialog version, composed of the ID and number of steps.
*
* @returns Dialog version, composed of the ID and number of steps.
*/
getVersion(): string {
// Simply return the id + number of steps to help detect when new steps have
// been added to a given waterfall.
return `${ this.id }:${ this.steps.length }`;
return `${this.id}:${this.steps.length}`;
}

/**
Expand Down Expand Up @@ -136,6 +138,7 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {
* helloDialog.addStep(this.helloWorldStep.bind(this));
* ```
* @param step Asynchronous step function to call.
* @returns Waterfall dialog for fluent calls to `addStep()`.
*/
addStep(step: WaterfallStep<O>): this {
this.steps.push(step);
Expand All @@ -145,6 +148,7 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {

/**
* Called when the [WaterfallDialog](xref:botbuilder-dialogs.WaterfallDialog) is started and pushed onto the dialog stack.
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation.
* @param options Optional, initial information to pass to the [Dialog](xref:botbuilder-dialogs.Dialog).
* @returns A Promise representing the asynchronous operation.
Expand Down Expand Up @@ -177,6 +181,7 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {
/**
* Called when the [WaterfallDialog](xref:botbuilder-dialogs.WaterfallDialog) is _continued_, where it is the active dialog and the
* user replies with a new [Activity](xref:botframework-schema.Activity).
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation.
* @returns A Promise representing the asynchronous operation.
* @remarks
Expand All @@ -196,6 +201,7 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {

/**
* Called when a child [WaterfallDialog](xref:botbuilder-dialogs.WaterfallDialog) completed its turn, returning control to this dialog.
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of the conversation.
* @param reason [Reason](xref:botbuilder-dialogs.DialogReason) why the dialog resumed.
* @param result Optional, value returned from the dialog that was called. The type
Expand Down Expand Up @@ -224,6 +230,7 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {
* }
* ```
* @param step Context object for the waterfall step to execute.
* @returns A promise with the DialogTurnResult.
*/
protected async onStep(step: WaterfallStepContext<O>): Promise<DialogTurnResult> {
// Log Waterfall Step event.
Expand All @@ -242,6 +249,7 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {

/**
* Executes a step of the [WaterfallDialog](xref:botbuilder-dialogs.WaterfallDialog).
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation.
* @param index The index of the current waterfall step to execute.
* @param reason The [Reason](xref:botbuilder-dialogs.DialogReason) the waterfall step is being executed.
Expand Down Expand Up @@ -320,6 +328,7 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {

/**
* Identifies the step name by its position index.
*
* @param index Step position
* @returns A string that identifies the step name.
*/
Expand Down
Loading