Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ebot = await this._controller.spawn(dc);
await ebot.replaceDialog(path.execute.script, {
thread: path.execute.thread,
...step.values
});
return { status: DialogTurnStatus.waiting };
case 'beginDialog':
let rbot = await this._controller.spawn(dc);
await rbot.beginDialog(path.execute.script, {
thread: path.execute.thread,
...step.values
});
return { status: DialogTurnStatus.waiting };
case 'repeat':
return await this.runStep(dc, step.index - 1, step.thread, DialogReason.nextCalled);
case 'wait':
// reset the state so we're still on this step.
step.state.stepIndex = step.index - 1;
// send a waiting status
return { status: DialogTurnStatus.waiting };
default:
// the default behavior for unknown action in botkit is to gotothread
if (this.script[path.action]) {
return await this.gotoThreadAction(path.action, dc, step);
}
console.warn('NOT SURE WHAT TO DO WITH THIS!!', path);
break;
}
// Basic code for intents and dialogs binding
// case SOME_OTHER_INTENT:
// turnResult = await dc.beginDialog(SomeOtherDialog.name, stepOptions);
// break;
case NONE_INTENT:
default:
// None or no intent identified, either way, let's query the QnA service.
turnResult = await dc.beginDialog(QnADialog.name);
break;
}
break;
case DialogTurnStatus.waiting:
// The active dialog is waiting for a response from the user, so do nothing.
break;
case DialogTurnStatus.complete:
// All child dialogs have ended. so do nothing.
break;
default:
// Unrecognized status from child dialog. Cancel all dialogs.
await dc.cancelAllDialogs();
}
}
}
return turnResult;
}
// dc.continueDialog() returns DialogTurnStatus.empty if there are no active dialogs
case DialogTurnStatus.empty:
// Determine what we should do based on the top intent from LUIS.
switch (topIntent) {
case GREETING_INTENT:
await dc.beginDialog(GREETING_DIALOG);
break;
case NONE_INTENT:
default:
// None or no intent identified, either way, let's provide some help
// to the user
await dc.context.sendActivity(templateReferences.confusion);
break;
}
break;
case DialogTurnStatus.waiting:
// The active dialog is waiting for a response from the user, so do nothing.
break;
case DialogTurnStatus.complete:
// All child dialogs have ended. so do nothing.
break;
default:
// Unrecognized status from child dialog. Cancel all dialogs.
await dc.cancelAllDialogs();
break;
}
}
} else if (context.activity.type === ActivityTypes.ConversationUpdate) {
// Handle ConversationUpdate activity type, which is used to indicates new members add to
// the conversation.
// see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
previousContextData = dialogOptions[QnAContextData];
}
answer.context.prompts.forEach(prompt => {
previousContextData[prompt.displayText.toLowerCase()] = prompt.qnaId;
});
dialogOptions[QnAContextData] = previousContextData;
dialogOptions[PreviousQnAId] = answer.id;
stepContext.activeDialog.state.options = dialogOptions;
// Get multi-turn prompts card activity.
var message = QnACardBuilder.GetQnAPromptsCard(answer);
await stepContext.context.sendActivity(message);
return { status: DialogTurnStatus.waiting };
}
}
return await stepContext.next(stepContext.result);
}
let result = await action.continueDialog();
// Start action if not continued
if (result.status == DialogTurnStatus.empty && this.getUniqueInstanceId(sequence) == instanceId) {
const nextAction = action.actions[0];
result = await action.beginDialog(nextAction.dialogId, nextAction.options);
}
// Increment turns action count
// - This helps dialogs being resumed from an interruption to determine if they
// should re-prompt or not.
const actionCount = sequence.state.getValue('turn.actionCount').value;
sequence.state.setValue('turn.actionCount', typeof actionCount == 'number' ? actionCount + 1 : 1);
// Is the action waiting for input or were we cancelled?
if (result.status == DialogTurnStatus.waiting || this.getUniqueInstanceId(sequence) != instanceId) {
return result;
}
// End current action
await this.endCurrentAction(sequence);
// Execute next action
// - We call continueDialog() on the root dialog to ensure any changes queued up
// by the previous actions are applied.
let root: DialogContext = sequence;
while (root.parent) {
root = root.parent;
}
return await root.continueDialog();
} else {
return await this.onEndOfActions(sequence);
async mainDispatch(dc) {
let dialogTurnResult;
// get on turn property through the property accessor
let onTurnProperty = await this.onTurnAccessor.get(dc.context);
// Evaluate if the requested operation is possible/ allowed.
const reqOpStatus = await this.isRequestedOperationPossible(dc.activeDialog, onTurnProperty.intent);
if (!reqOpStatus.allowed) {
await dc.context.sendActivity(reqOpStatus.reason);
// Initiate re-prompt for the active dialog.
await dc.repromptDialog();
return { status: DialogTurnStatus.waiting };
} else {
// continue any outstanding dialogs
dialogTurnResult = await dc.continueDialog();
}
// This will only be empty if there is no active dialog in the stack.
if (!dc.context.responded && dialogTurnResult !== undefined && dialogTurnResult.status !== DialogTurnStatus.complete) {
// If incoming on turn property does not have an intent, call LUIS and get an intent.
if (onTurnProperty === undefined || onTurnProperty.intent === '') {
// Call to LUIS recognizer to get intent + entities
const LUISResults = await this.luisRecognizer.recognize(dc.context);
// Return new instance of on turn property from LUIS results.
// Leverages static fromLUISResults method
onTurnProperty = OnTurnProperty.fromLUISResults(LUISResults);
}
// dc.continueDialog() returns DialogTurnStatus.empty if there are no active dialogs
case DialogTurnStatus.empty:
// Determine what we should do based on the top intent from LUIS.
switch (topIntent) {
case GREETING_INTENT:
await dc.beginDialog(GREETING_DIALOG);
break;
case NONE_INTENT:
default:
// None or no intent identified, either way, let's provide some help
// to the user
await dc.context.sendActivity(`I didn't understand what you just said to me.`);
break;
}
break;
case DialogTurnStatus.waiting:
// The active dialog is waiting for a response from the user, so do nothing.
break;
case DialogTurnStatus.complete:
// All child dialogs have ended. so do nothing.
break;
default:
// Unrecognized status from child dialog. Cancel all dialogs.
await dc.cancelAllDialogs();
break;
}
}
} else if (context.activity.type === ActivityTypes.ConversationUpdate) {
// Handle ConversationUpdate activity type, which is used to indicates new members add to
// the conversation.
// see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
// dc.continueDialog() returns DialogTurnStatus.empty if there are no active dialogs
case DialogTurnStatus.empty:
// Determine what we should do based on the top intent from LUIS.
switch (topIntent) {
case GREETING_INTENT:
await dc.beginDialog(GREETING_DIALOG);
break;
case NONE_INTENT:
default:
// help or no intent identified, either way, let's provide some help
// to the user
await dc.context.sendActivity(`I didn't understand what you just said to me.`);
break;
}
break;
case DialogTurnStatus.waiting:
// The active dialog is waiting for a response from the user, so do nothing.
break;
case DialogTurnStatus.complete:
// All child dialogs have ended. so do nothing.
break;
default:
// Unrecognized status from child dialog. Cancel all dialogs.
await dc.cancelAllDialogs();
break;
}
}
} else if (context.activity.type === ActivityTypes.ConversationUpdate) {
// When activity type is "conversationUpdate" and the member joining the conversation is the bot
// we will send our Welcome Adaptive Card. This will only be sent once, when the Bot joins conversation
// To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
// Do we have any new members added to the conversation?
async runStateMachine(dc) {
var oldState = this.getPersistedState(dc.activeDialog);
var processResult = await this.processAsync(oldState, dc.context.activity);
var newState = processResult[0];
var output = processResult[1];
var result = processResult[2];
await dc.context.sendActivity(output);
if(newState != null){
dc.activeDialog.state[functionStateName] = newState;
return { status: DialogTurnStatus.waiting };
}
else{
return await dc.endDialog();
}
}
private async interrupt(innerDc: DialogContext): Promise {
if (innerDc.context.activity.text) {
const text = innerDc.context.activity.text.toLowerCase();
switch (text) {
case 'help':
case '?':
const helpMessageText = 'Show help here';
await innerDc.context.sendActivity(helpMessageText, helpMessageText, InputHints.ExpectingInput);
return { status: DialogTurnStatus.waiting };
case 'cancel':
case 'quit':
const cancelMessageText = 'Cancelling...';
await innerDc.context.sendActivity(cancelMessageText, cancelMessageText, InputHints.IgnoringInput);
return await innerDc.cancelAllDialogs();
}
}
}
}