Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(conversationState) {
// Create a new state accessor property. See https://aka.ms/about-bot-state-accessors to learn more about bot state and state accessors.
this.conversationState = conversationState;
this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);
this.dialogs = new DialogSet(this.dialogState);
// Add prompts that will be used by the bot.
this.dialogs.add(new ChoicePrompt(CONFIRM_PROMPT));
this.dialogs.add(new OAuthPrompt(OAUTH_PROMPT, OAUTH_SETTINGS));
// The WaterfallDialog that controls the flow of the conversation.
this.dialogs.add(new WaterfallDialog(AUTH_DIALOG, [
this.oauthPrompt,
this.loginResults,
this.displayToken
]));
}
constructor(connectionName: string) {
super(AuthenticationDialog.name);
this.initialDialogId = AuthenticationDialog.name;
this.connectionName = connectionName;
// tslint:disable-next-line:no-any
const authenticate: ((sc: WaterfallStepContext<{}>) => Promise>)[] = [
this.prompToLogin.bind(this),
this.finishLoginhDialog.bind(this)
];
this.addDialog(new WaterfallDialog(this.initialDialogId, authenticate));
this.addDialog(new OAuthPrompt(DialogIds.LoginPrompt, {
connectionName: this.connectionName,
text: i18n.__('authentication.prompt'),
title: i18n.__('authentication.title')
}));
}
if (!context.responded) {
yield dc.beginDialog('displayToken');
}
}
}
else if (context.activity.type === 'event' || context.activity.type === 'invoke') {
// Create dialog context and continue executing the "current" dialog, if any.
// This is important for OAuthCards because tokens can be received via TokenResponse events
const state = conversationState.get(context);
const dc = dialogs.createContext(context, state);
yield dc.continueDialog();
}
}));
});
// Add a dialog to get a token for the connectrion
dialogs.add('loginPrompt', new botbuilder_dialogs_1.OAuthPrompt({
connectionName: connectionName,
text: "Please Sign In",
title: "Sign In",
timeout: 300000 // User has 5 minutes to login
}));
// Add a dialog to display the token once the user has logged in
dialogs.add('displayToken', [
function (dc) {
return __awaiter(this, void 0, void 0, function* () {
yield dc.beginDialog('loginPrompt');
});
},
function (dc, token) {
return __awaiter(this, void 0, void 0, function* () {
if (token) {
// Continue with task needing access token
constructor(conversationState) {
this.conversationState = conversationState;
// Create a new state accessor property.
// See https://aka.ms/about-bot-state-accessors to learn more about bot state and state accessors.
this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);
this.dialogs = new DialogSet(this.dialogState);
// Add prompts that will be used by the bot.
this.dialogs.add(new ChoicePrompt(CONFIRM_PROMPT));
this.dialogs.add(new OAuthPrompt(OAUTH_PROMPT, OAUTH_SETTINGS));
// The WaterfallDialog that controls the flow of the conversation.
this.dialogs.add(new WaterfallDialog(AUTH_DIALOG, [
this.oauthPrompt,
this.loginResults,
this.displayToken
]));
}
if (!context.responded) {
await dc.beginDialog('displayToken');
}
}
} else if (context.activity.type === 'event' || context.activity.type === 'invoke') {
// Create dialog context and continue executing the "current" dialog, if any.
// This is important for OAuthCards because tokens can be received via TokenResponse events
const state = conversationState.get(context);
const dc = dialogs.createContext(context, state);
await dc.continueDialog();
}
});
});
// Add a dialog to get a token for the connectrion
dialogs.add('loginPrompt', new OAuthPrompt({
connectionName: connectionName,
text: "Please Sign In",
title: "Sign In",
timeout: 300000 // User has 5 minutes to login
}));
// Add a dialog to display the token once the user has logged in
dialogs.add('displayToken', [
async function (dc) {
await dc.beginDialog('loginPrompt');
},
async function (dc, token) {
if (token) {
// Continue with task needing access token
await dc.context.sendActivity(`Your token is: ` + token.token);
} else {
constructor(connectionName: string) {
super(AuthenticationDialog.name);
this.initialDialogId = AuthenticationDialog.name;
this.connectionName = connectionName;
const authenticate: ((sc: WaterfallStepContext) => Promise)[] = [
this.prompToLogin.bind(this),
this.finishLoginhDialog.bind(this)
];
this.addDialog(new WaterfallDialog(this.initialDialogId, authenticate));
this.addDialog(new OAuthPrompt(DialogIds.loginPrompt, {
connectionName: this.connectionName,
text: i18next.t('authentication.prompt'),
title: i18next.t('authentication.title')
}));
}
import { TurnContext, ActivityTypes } from 'botbuilder';
import { OAuthPrompt, DialogSet, ChoicePrompt, DialogReason, WaterfallDialog } from 'botbuilder-dialogs';
import fetch from 'node-fetch';
import conversationState from '../singletonConversationState';
const dialogState = conversationState['createProperty']('dialogState');
const dialogs = new DialogSet(dialogState);
dialogs.add(new ChoicePrompt('CONFIRM_PROMPT'));
dialogs.add(new OAuthPrompt('OAUTH_PROMPT', {
connectionName: process.env.OAUTH_CONNECTION_NAME,
text: 'Sign into GitHub',
title: 'Sign in'
}));
dialogs.add(new WaterfallDialog('AUTH_DIALOG', [
async step => await step.prompt('OAUTH_PROMPT', {}),
async step => {
if (step.result) {
await step.context.sendActivity('You have now logged in.');
return await step.next(step.result);
} else {
await step.context.sendActivity('Failed to login, please try again.');
return await step.endDialog();
constructor() {
super('MainDialog');
this.addDialog(new ChoicePrompt(CHOICE_PROMPT))
.addDialog(new OAuthPrompt(OAUTH_PROMPT, {
connectionName: process.env.ConnectionName,
text: 'Please login',
title: 'Login',
timeout: 300000
}))
.addDialog(new TextPrompt(TEXT_PROMPT))
.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.promptStep.bind(this),
this.loginStep.bind(this),
this.commandStep.bind(this),
this.processStep.bind(this)
]));
this.initialDialogId = MAIN_WATERFALL_DIALOG;
}
constructor(connectionName: string) {
super("SignInDialog");
this.initialDialogId = "SignInDialog";
this._connectionName = connectionName;
this._responder = new SignInResponses();
this.addDialog(new WaterfallDialog(this.initialDialogId, [
this.askToLogin.bind(this),
this.finishAuthDialog.bind(this),
]));
this.addDialog(new OAuthPrompt(this._loginPrompt, {
connectionName: this._connectionName,
text: "Please sign in to access this bot.",
title: "Sign In",
}));
}
constructor() {
super(MAIN_DIALOG, process.env.connectionName);
this.addDialog(new OAuthPrompt(OAUTH_PROMPT, {
connectionName: process.env.connectionName,
text: 'Please Sign In',
title: 'Sign In',
timeout: 300000
}));
this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.promptStep.bind(this),
this.loginStep.bind(this),
this.displayTokenPhase1.bind(this),
this.displayTokenPhase2.bind(this)
]));
this.initialDialogId = MAIN_WATERFALL_DIALOG;
}