@microsoft/teams-ai
Version:
SDK focused on building AI based applications for Microsoft Teams.
135 lines • 6.79 kB
TypeScript
import { DialogTurnResult } from 'botbuilder-dialogs';
import { TurnState } from '../TurnState';
import { Application } from '../Application';
import { TurnContext, Storage, TokenResponse } from 'botbuilder';
import { AuthError } from './Authentication';
/**
* @internal
* Base class to handle Teams conversational bot authentication.
* @template TState - The type of the turn state.
*/
export declare abstract class BotAuthenticationBase<TState extends TurnState> {
protected _storage: Storage;
protected _settingName: string;
private _userSignInSuccessHandler?;
private _userSignInFailureHandler?;
/**
* Creates a new instance of BotAuthenticationBase.
* @param {Application<TState>} app - The application instance.
* @param {string} settingName - The name of the setting.
* @param {Storage} [storage] - The storage to save states.
*/
constructor(app: Application<TState>, settingName: string, storage?: Storage);
/**
* Authenticates the user.
* @param {TurnContext} context - The turn context.
* @param {TState} state - The turn state.
* @returns {Promise<string | undefined>} - The authentication token, or undefined if authentication failed.
*/
authenticate(context: TurnContext, state: TState): Promise<string | undefined>;
/**
* Checks if the activity is a valid message activity
* @param {TurnContext} context - The turn context.
* @returns {boolean} - True if the activity is a valid message activity.
*/
isValidActivity(context: TurnContext): boolean;
/**
* The handler function is called when the user has successfully signed in
* @template TState
* @param {(context: TurnContext, state: TState) => Promise<void>} handler The handler function to call when the user has successfully signed in
*/
onUserSignInSuccess(handler: (context: TurnContext, state: TState) => Promise<void>): void;
/**
* The handler function is called when the user sign in flow fails
* @template TState
* @param {(context: TurnContext, state: TState) => Promise<void>} handler The handler function to call when the user failed to signed in
*/
onUserSignInFailure(handler: (context: TurnContext, state: TState, error: AuthError) => Promise<void>): void;
/**
* Handles the signin/verifyState activity. The onUserSignInSuccess and onUserSignInFailure handlers will be called based on the result.
* @param {TurnContext} context - The turn context.
* @param {TState} state - The turn state.
*/
handleSignInActivity(context: TurnContext, state: TState): Promise<void>;
/**
* Deletes the user auth state and user dialog state from the turn state. So that the next message can start a new authentication flow.
* @param {TurnContext} context - The turn context.
* @param {TState} state - The turn state.
*/
deleteAuthFlowState(context: TurnContext, state: TState): void;
/**
* Gets the property name for storing user authentication state.
* @param {TurnContext} context - The turn context.
* @returns {string} - The property name.
*/
getUserAuthStatePropertyName(context: TurnContext): string;
/**
* Gets the property name for storing user dialog state.
* @param {TurnContext} context - The turn context.
* @returns {string} - The property name.
*/
getUserDialogStatePropertyName(context: TurnContext): string;
private getUserAuthState;
private getUserDialogState;
verifyStateRouteSelector(context: TurnContext): Promise<boolean>;
tokenExchangeRouteSelector(context: TurnContext): Promise<boolean>;
/**
* Run or continue the authentication dialog.
* @param {TurnContext} context - The turn context.
* @param {TState} state - The turn state.
* @param {string} dialogStateProperty - The property name for storing dialog state.
* @returns {Promise<DialogTurnResult<TokenResponse>>} - A promise that resolves to the dialog turn result containing the token response.
*/
abstract runDialog(context: TurnContext, state: TState, dialogStateProperty: string): Promise<DialogTurnResult<TokenResponse>>;
/**
* Continues the authentication dialog.
* @param {TurnContext} context - The turn context.
* @param {TState} state - The turn state.
* @param {string} dialogStateProperty - The property name for storing dialog state.
* @returns {Promise<DialogTurnResult<TokenResponse>>} - A promise that resolves to the dialog turn result containing the token response.
*/
abstract continueDialog(context: TurnContext, state: TState, dialogStateProperty: string): Promise<DialogTurnResult<TokenResponse>>;
}
/**
* Sets the setting name in the context.activity.value object.
* The setting name is needed in signIn/verifyState` and `signIn/tokenExchange` route selector to accurately route to the correct authentication setting.
* @param {TurnContext} context The turn context object
* @param {string} settingName The auth setting name
*/
export declare function setSettingNameInContextActivityValue(context: TurnContext, settingName: string): void;
/**
* Sets the token in the turn state
* @param {TurnState} state The turn state
* @param {string} settingName The name of the setting
* @param {string} token The token to set
* @internal
*/
export declare function setTokenInState<TState extends TurnState>(state: TState, settingName: string, token: string): void;
/**
* Deletes the token from the turn state
* @param {TurnState} state The turn state
* @param {string} settingName The name of the setting
*/
export declare function deleteTokenFromState<TState extends TurnState>(state: TState, settingName: string): void;
/**
* Determines if the user is in the sign in flow.
* @template TState
* @param {TState} state - the turn state
* @returns {string | undefined} The setting name if the user is in sign in flow. Otherwise, undefined.
*/
export declare function userInSignInFlow<TState extends TurnState>(state: TState): string | undefined;
/**
* Update the turn state to indicate the user is in the sign in flow by providing the authentication setting name used.
* @template TState
* @param {TState} state - the turn state
* @param {string} settingName - the authentication setting name.
*/
export declare function setUserInSignInFlow<TState extends TurnState>(state: TState, settingName: string): void;
/**
* Deletes the user sign in flow state from the turn state.
* @template TState
* Determines if the user is in the sign in flow.
* @param {TState} state - the turn state
*/
export declare function deleteUserInSignInFlow<TState extends TurnState>(state: TState): void;
//# sourceMappingURL=BotAuthenticationBase.d.ts.map