Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async beginDialog(dc) {
// Don't do anything for non-message activities.
if (dc.context.activity.type !== ActivityTypes.Message) {
return Dialog.EndOfTurn;
}
// Run dialog logic.
return await this.runStateMachine(dc);
}
protected async route(dc: DialogContext): Promise {
const localeConfig: Partial | undefined = this.services.getCognitiveModel();
// Populate state from SkillContext slots as required
await this.populateStateFromSemanticAction(dc.context);
// Get skill LUIS model from configuration
if (localeConfig.luisServices !== undefined) {
const luisService: LuisRecognizerTelemetryClient | undefined = localeConfig.luisServices.get(this.solutionName);
if (luisService === undefined) {
throw new Error('The specified LUIS Model could not be found in your Bot Services configuration.');
} else {
let turnResult: DialogTurnResult = Dialog.EndOfTurn;
const result: RecognizerResult = await luisService.recognize(dc.context);
const intent: string = LuisRecognizer.topIntent(result);
switch (intent) {
case 'Sample': {
turnResult = await dc.beginDialog(SampleDialog.name);
break;
}
case 'None': {
// No intent was identified, send confused message
await dc.context.sendActivity(this.responseManager.getResponse(SharedResponses.didntUnderstandMessage));
turnResult = {
status: DialogTurnStatus.complete
};
break;
}
public async resumeDialog(dc, reason, result): Promise {
// Increment step index and run step
if (dc.activeDialog) {
const state = dc.activeDialog.state;
return await this.runStep(dc, state.stepIndex + 1, state.thread || 'default', reason, result);
} else {
return Dialog.EndOfTurn;
}
}
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 };
}
}
async continueDialog(dc) {
// Don't do anything for non-message activities
if (dc.context.activity.type !== ActivityTypes.Message) {
return Dialog.EndOfTurn;
}
// Run next step with the message text as the result.
return await this.resumeDialog(dc, DialogReason.continueCalled, dc.context.activity.text);
}
async continueDialog(dc) {
// Skip non-message activities.
if (dc.context.activity.type !== ActivityTypes.Message) {
return Dialog.EndOfTurn;
}
// Call runPrompt, which will find the next slot to fill.
return await this.runPrompt(dc);
}
protected async onEndOfPlan(planning: PlanningContext): Promise {
// Evaluate current status
const state = planning.activeDialog.state as InputDialogState;
if (state.fulfilled) {
// Return result
return await planning.endDialog(state.result);
} else if (state.continuingAction) {
// The action just completed so we need to re-evaluate our state and re-prompt as
// needed.
delete state.continuingAction;
await this.onValidateSlot(planning);
return await this.continuePlan(planning);
} else {
// Just wait for user to reply
return Dialog.EndOfTurn;
}
}
// No intent was identified, send confused message
await dc.context.sendActivity(this.responseManager.getResponse(SharedResponses.didntUnderstandMessage));
turnResult = {
status: DialogTurnStatus.complete
};
break;
}
default: {
// intent was identified but not yet implemented
await dc.context.sendActivity(this.responseManager.getResponse(MainResponses.featureNotAvailable));
turnResult = {
status: DialogTurnStatus.complete
};
}
}
if (turnResult !== Dialog.EndOfTurn) {
await this.complete(dc);
}
}
}
}
public async beginDialog(dc: DialogContext): Promise {
return Dialog.EndOfTurn;
}