Freigeben über


TeamsBotSsoPrompt class

Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and help receive oauth token, asks the user to consent if needed.

Example

When used with your bots DialogSet you can simply add a new instance of the prompt as a named dialog using DialogSet.add(). You can then start the prompt from a waterfall step using either DialogContext.beginDialog() or DialogContext.prompt(). The user will be prompted to sign in as needed and their access token will be passed as an argument to the callers next waterfall step:

const { ConversationState, MemoryStorage } = require('botbuilder');
const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');

const convoState = new ConversationState(new MemoryStorage());
const dialogState = convoState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);

dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
   scopes: ["User.Read"],
}));

dialogs.add(new WaterfallDialog('taskNeedingLogin', [
     async (step) => {
         return await step.beginDialog('TeamsBotSsoPrompt');
     },
     async (step) => {
         const token = step.result;
         if (token) {

             // ... continue with task needing access token ...

         } else {
             await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
             return await step.endDialog();
         }
     }
]));
Extends

Dialog

Remarks

The prompt will attempt to retrieve the users current token of the desired scopes and store it in the token store.

User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO): https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots

Constructors

TeamsBotSsoPrompt(OnBehalfOfCredentialAuthConfig, string, string, TeamsBotSsoPromptSettings)

Constructor of TeamsBotSsoPrompt.

TeamsBotSsoPrompt(TeamsFx, string, TeamsBotSsoPromptSettings)

Constructor of TeamsBotSsoPrompt.

Properties

id

Unique ID of the dialog.

telemetryClient

Gets the telemetry client for this dialog.

Inherited Properties

EndOfTurn

Gets a default end-of-turn result.

Methods

beginDialog(DialogContext)

Called when a prompt dialog is pushed onto the dialog stack and is being activated.

continueDialog(DialogContext)

Called when a prompt dialog is the active dialog and the user replied with a new activity.

Inherited Methods

configure(Record<string, unknown>)

Fluent method for configuring the object.

endDialog(TurnContext, DialogInstance<any>, DialogReason)

When overridden in a derived class, performs clean up for the dialog before it ends.

getConverter(string)
getVersion()

An encoded string used to aid in the detection of bot changes on re-deployment.

onDialogEvent(DialogContext, DialogEvent)

Called when an event has been raised, using DialogContext.emitEvent(), by either the current dialog or a dialog that the current dialog started.

repromptDialog(TurnContext, DialogInstance<any>)

When overridden in a derived class, reprompts the user for input.

resumeDialog(DialogContext, DialogReason, any)

When overridden in a derived class, resumes the dialog after the dialog above it on the stack completes.

Constructor Details

TeamsBotSsoPrompt(OnBehalfOfCredentialAuthConfig, string, string, TeamsBotSsoPromptSettings)

Constructor of TeamsBotSsoPrompt.

new TeamsBotSsoPrompt(authConfig: OnBehalfOfCredentialAuthConfig, initiateLoginEndpoint: string, dialogId: string, settings: TeamsBotSsoPromptSettings)

Parameters

authConfig
OnBehalfOfCredentialAuthConfig

Used to provide configuration and auth

initiateLoginEndpoint

string

Login URL for Teams to redirect to

dialogId

string

Unique ID of the dialog within its parent DialogSet or ComponentDialog.

settings
TeamsBotSsoPromptSettings

Settings used to configure the prompt.

TeamsBotSsoPrompt(TeamsFx, string, TeamsBotSsoPromptSettings)

Constructor of TeamsBotSsoPrompt.

new TeamsBotSsoPrompt(teamsfx: TeamsFx, dialogId: string, settings: TeamsBotSsoPromptSettings)

Parameters

teamsfx
TeamsFx

Used to provide configuration and auth

dialogId

string

Unique ID of the dialog within its parent DialogSet or ComponentDialog.

settings
TeamsBotSsoPromptSettings

Settings used to configure the prompt.

Property Details

id

Unique ID of the dialog.

string id

Property Value

string

The Id for the dialog.

telemetryClient

Gets the telemetry client for this dialog.

BotTelemetryClient telemetryClient

Property Value

BotTelemetryClient

The BotTelemetryClient to use for logging.

Inherited Property Details

EndOfTurn

Gets a default end-of-turn result.

static EndOfTurn: DialogTurnResult<any>

Property Value

DialogTurnResult<any>

Remarks

This result indicates that a dialog (or a logical step within a dialog) has completed processing for the current turn, is still active, and is waiting for more input.

Inherited From Dialog.EndOfTurn

Method Details

beginDialog(DialogContext)

Called when a prompt dialog is pushed onto the dialog stack and is being activated.

function beginDialog(dc: DialogContext): Promise<DialogTurnResult<any>>

Parameters

dc

DialogContext

The DialogContext for the current turn of the conversation.

Returns

Promise<DialogTurnResult<any>>

A Promise representing the asynchronous operation.

Remarks

If the task is successful, the result indicates whether the prompt is still active after the turn has been processed by the prompt.

continueDialog(DialogContext)

Called when a prompt dialog is the active dialog and the user replied with a new activity.

function continueDialog(dc: DialogContext): Promise<DialogTurnResult<any>>

Parameters

dc

DialogContext

The DialogContext for the current turn of the conversation.

Returns

Promise<DialogTurnResult<any>>

A Promise representing the asynchronous operation.

Remarks

If the task is successful, the result indicates whether the dialog is still active after the turn has been processed by the dialog. The prompt generally continues to receive the user's replies until it accepts the user's reply as valid input for the prompt.

Inherited Method Details

configure(Record<string, unknown>)

Fluent method for configuring the object.

function configure(config: Record<string, unknown>): TeamsBotSsoPrompt

Parameters

config

Record<string, unknown>

Configuration settings to apply.

Returns

The Configurable after the operation is complete.

Inherited From Dialog.configure

endDialog(TurnContext, DialogInstance<any>, DialogReason)

When overridden in a derived class, performs clean up for the dialog before it ends.

function endDialog(_context: TurnContext, _instance: DialogInstance<any>, _reason: DialogReason): Promise<void>

Parameters

_context

TurnContext

The context object for the turn.

_instance

DialogInstance<any>

Current state information for this dialog.

_reason

DialogReason

The reason the dialog is ending.

Returns

Promise<void>

Remarks

Derived dialogs that need to perform logging or cleanup before ending should override this method. By default, this method has no effect.

The DialogContext calls this method when the current dialog is ending.

See also

Inherited From Dialog.endDialog

getConverter(string)

function getConverter(_property: string): Converter<unknown, unknown> | ConverterFactory<unknown, unknown>

Parameters

_property

string

The key of the conditional selector configuration.

Returns

Converter<unknown, unknown> | ConverterFactory<unknown, unknown>

The converter for the selector configuration.

Inherited From Dialog.getConverter

getVersion()

An encoded string used to aid in the detection of bot changes on re-deployment.

function getVersion(): string

Returns

string

Unique string which should only change when dialog has changed in a way that should restart the dialog.

Remarks

This defaults to returning the dialogs id but can be overridden to provide more precise change detection logic. Any dialog on the stack that has its version change will result in a versionChanged event will be raised. If this event is not handled by the bot, an error will be thrown resulting in the bots error handler logic being run.

Returning an empty string will disable version tracking for the component all together.

Inherited From Dialog.getVersion

onDialogEvent(DialogContext, DialogEvent)

Called when an event has been raised, using DialogContext.emitEvent(), by either the current dialog or a dialog that the current dialog started.

function onDialogEvent(dc: DialogContext, e: DialogEvent): Promise<boolean>

Parameters

dc

DialogContext

The dialog context for the current turn of conversation.

e

DialogEvent

The event being raised.

Returns

Promise<boolean>

True if the event is handled by the current dialog and bubbling should stop.

Inherited From Dialog.onDialogEvent

repromptDialog(TurnContext, DialogInstance<any>)

When overridden in a derived class, reprompts the user for input.

function repromptDialog(_context: TurnContext, _instance: DialogInstance<any>): Promise<void>

Parameters

_context

TurnContext

The context object for the turn.

_instance

DialogInstance<any>

Current state information for this dialog.

Returns

Promise<void>

Remarks

Derived dialogs that support validation and re-prompt logic should override this method. By default, this method has no effect.

The DialogContext calls this method when the current dialog should re-request input from the user. This method is implemented for prompt dialogs.

See also

Inherited From Dialog.repromptDialog

resumeDialog(DialogContext, DialogReason, any)

When overridden in a derived class, resumes the dialog after the dialog above it on the stack completes.

function resumeDialog(dc: DialogContext, reason: DialogReason, result?: any): Promise<DialogTurnResult<any>>

Parameters

dc

DialogContext

The context for the current dialog turn.

reason

DialogReason

The reason the dialog is resuming. This will typically be DialogReason.endCalled

result

any

Optional. The return value, if any, from the dialog that ended.

Returns

Promise<DialogTurnResult<any>>

A promise resolving to the dialog turn result.

Remarks

Derived dialogs that support multiple-turn conversations should override this method. By default, this method signals that the dialog is complete and returns.

The DialogContext calls this method when it resumes the dialog. If the previous dialog on the stack returned a value, that value is in the result parameter.

To start a child dialog, use DialogContext.beginDialog or DialogContext.prompt; however, this dialog will not necessarily be the one that started the child dialog. To signal to the dialog context that this dialog has completed, await DialogContext.endDialog before exiting this method.

See also

Inherited From Dialog.resumeDialog