Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (nextCalled) {
throw new Error(`ScriptedStepContext.next(): method already called for dialog and step '${ this.id }[${ index }]'.`);
}
return await this.resumeDialog(dc, DialogReason.nextCalled, stepResult);
}
};
// did we just start a new thread?
// if so, run the before stuff.
if (index === 0) {
await this.runBefore(step.thread, dc, step);
// did we just change threads? if so, restart
if (index !== step.index || thread_name !== step.thread) {
return await this.runStep(dc, step.index, step.thread, DialogReason.nextCalled); // , step.values);
}
}
// Execute step
const res = await this.onStep(dc, step);
return res;
}
const thread_name = step.thread;
// spawn a bot instance so devs can use API or other stuff as necessary
const bot = await this._controller.spawn(dc);
// create a convo controller object
const convo = new BotkitDialogWrapper(dc, step);
await path.handler.call(this, step.result, convo, bot);
if (!dc.activeDialog) {
return false;
}
// did we just change threads? if so, restart this turn
if (index !== step.index || thread_name !== step.thread) {
return await this.runStep(dc, step.index, step.thread, DialogReason.nextCalled, null);
}
return false;
}
switch (path.action) {
case 'next':
// noop
break;
case 'complete':
step.values._status = 'completed';
return await this.end(dc);
case 'stop':
step.values._status = 'canceled';
return await this.end(dc);
case 'timeout':
if (nextCalled) {
throw new Error(`ScriptedStepContext.next(): method already called for dialog and step '${ this.id }[${ index }]'.`);
}
return await this.resumeDialog(dc, DialogReason.nextCalled, stepResult);
}
};
// did we just start a new thread?
// if so, run the before stuff.
if (index === 0 && previous_thread != thread_name) {
await this.runBefore(step.thread, dc, step);
// did we just change threads? if so, restart
if (index != step.index || thread_name != step.thread) {
return await this.runStep(dc, step.index, step.thread, DialogReason.nextCalled, step.values);
}
}
// Execute step
const res = await this.onStep(dc, step);
return res;
} else {
// End of script so just return to parent
return await dc.endDialog(result);
}
}
private async gotoThreadAction(thread, dc, step) {
await this.gotoThread(thread, dc, step);
// await this.runBefore(step.thread, dc, step);
return await this.runStep(dc, step.index, step.thread, DialogReason.nextCalled, step.values);
}
next: async (stepResult) => {
if (nextCalled) {
throw new Error(`ScriptedStepContext.next(): method already called for dialog and step '${ this.id }[${ index }]'.`);
}
return await this.resumeDialog(dc, DialogReason.nextCalled, stepResult);
}
};
next: async (stepResult) => {
if (nextCalled) {
throw new Error(`ScriptedStepContext.next(): method already called for dialog and step '${ this.id }[${ index }]'.`);
}
return await this.resumeDialog(dc, DialogReason.nextCalled, stepResult);
}
};