Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (dialogTurnResult === undefined) return await dc.endDialog();
// Examine result from dc.continue() or from the call to beginChildDialog().
switch (dialogTurnResult.status) {
case DialogTurnStatus.complete: {
// The active dialog finished successfully. Ask user if they need help with anything else.
await dc.context.sendActivity(MessageFactory.suggestedActions(GenSuggestedQueries(), `Is there anything else I can help you with?`));
break;
}
case DialogTurnStatus.waiting: {
// The active dialog is waiting for a response from the user, so do nothing
break;
}
case DialogTurnStatus.cancelled: {
// The active dialog's stack has been cancelled
await dc.cancelAllDialogs();
break;
}
}
return dialogTurnResult;
}
protected async onEndOfActions(sequence: SequenceContext): Promise {
// End dialog and return result
if (sequence.activeDialog) {
if (this.shouldEnd(sequence)) {
const state: AdaptiveDialogState = sequence.activeDialog.state;
return await sequence.endDialog(state.result);
}
return Dialog.EndOfTurn;
} else {
return { status: DialogTurnStatus.cancelled };
}
}
activities.forEach(a => {
if (a.type === ActivityTypes.EndOfConversation) {
skillEnded = true;
}
});
return await next();
});
// Run turn
result = await this.onRunTurn(innerDC, options);
}
// Check for end of skill and clear the conversation state if detected.
if (skillEnded) {
this.conversationState.clear(innerDC.context);
result = { status: DialogTurnStatus.cancelled };
}
return result;
}
// When the token is cached we get a TokenResponse object.
const providerTokenResponse: IProviderTokenResponse | undefined = sc.result as IProviderTokenResponse;
if (providerTokenResponse !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/tslint/config
const state: any = await this.stateAccessor.get(sc.context);
// tslint:disable-next-line: no-any no-unsafe-any
state.token = providerTokenResponse.tokenResponse.token;
}
return await sc.next();
} catch (err) {
await this.handleDialogExceptions(sc, err as Error);
return {
status: DialogTurnStatus.cancelled,
result: CommonUtil.dialogTurnResultCancelAllDialogs
};
}
}
// Validators
async onTurn(turnContext) {
// By checking the incoming Activity type, the bot only calls QnA Maker in appropriate cases.
if (turnContext.activity.type === ActivityTypes.Message) {
const dialogContext = await this.dialogs.createContext(turnContext);
const results = await dialogContext.continueDialog();
if ((results.status === DialogTurnStatus.cancelled) || (results.status === DialogTurnStatus.empty)) {
await dialogContext.beginDialog(this.dialogHelper.activeLearningDialogName, this.qnaMakerOptions);
}
await this.conversationState.saveChanges(turnContext);
// If the Activity is a ConversationUpdate, send a greeting message to the user.
} else if (turnContext.activity.type === ActivityTypes.ConversationUpdate &&
turnContext.activity.recipient.id !== turnContext.activity.membersAdded[0].id) {
await turnContext.sendActivity('Welcome to the QnA Maker sample! Ask me a question and I will try to answer it.');
// Respond to all other Activity types.
} else if (turnContext.activity.type !== ActivityTypes.ConversationUpdate) {
await turnContext.sendActivity(`[${ turnContext.activity.type }]-type activity detected.`);
}
}
}
activities.forEach(a => {
if (a.type === ActivityTypes.EndOfConversation) {
skillEnded = true;
}
});
return await next();
});
// Run turn
result = await this.onRunTurn(innerDC, options);
}
// Check for end of skill and clear the conversation state if detected.
if (skillEnded) {
this.conversationState.clear(innerDC.context);
result = { status: DialogTurnStatus.cancelled };
}
return result;
}
protected async getAuthToken(sc: WaterfallStepContext): Promise {
try {
return await sc.prompt(MultiProviderAuthDialog.name, {});
} catch (err) {
await this.handleDialogExceptions(sc, err as Error);
return {
status: DialogTurnStatus.cancelled,
result: CommonUtil.dialogTurnResultCancelAllDialogs
};
}
}