Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// configuration instructions.
console.error(lgTemplates.evaluate('SomethingWentWrong', {
message: `${ error }`
}));
// Send a trace activity, which will be displayed in Bot Framework Emulator
await context.sendTraceActivity(
'OnTurnError Trace',
`${ error }`,
'https://www.botframework.com/schemas/error',
'TurnError'
);
// Send a message to the user
let onTurnErrorMessage = 'The bot encountered an error or bug.';
await context.sendActivity(onTurnErrorMessage, onTurnErrorMessage, InputHints.ExpectingInput);
onTurnErrorMessage = 'To continue to run this bot, please fix the bot source code.';
await context.sendActivity(onTurnErrorMessage, onTurnErrorMessage, InputHints.ExpectingInput);
// Clear out state
await conversationState.delete(context);
};
async function sendErrorMessage(context, error) {
try {
// Send a message to the user.
let onTurnErrorMessage = 'The skill encountered an error or bug.';
await context.sendActivity(onTurnErrorMessage, onTurnErrorMessage, InputHints.ExpectingInput);
onTurnErrorMessage = 'To continue to run this bot, please fix the bot source code.';
await context.sendActivity(onTurnErrorMessage, onTurnErrorMessage, InputHints.ExpectingInput);
// Send a trace activity, which will be displayed in the Bot Framework Emulator.
// Note: we return the entire exception in the value property to help the developer;
// this should not be done in production.
await context.sendTraceActivity('OnTurnError Trace', error.toString(), 'https://www.botframework.com/schemas/error', 'TurnError');
} catch (err) {
console.error(`\n [onTurnError] Exception caught in sendErrorMessage: ${ err }`);
}
}
// configuration instructions.
console.error(`\n [onTurnError] unhandled error: ${ error }`);
// Send a trace activity, which will be displayed in Bot Framework Emulator
await context.sendTraceActivity(
'OnTurnError Trace',
`${ error }`,
'https://www.botframework.com/schemas/error',
'TurnError'
);
// Send a message to the user
let onTurnErrorMessage = 'The bot encountered an error or bug.';
await context.sendActivity(onTurnErrorMessage, onTurnErrorMessage, InputHints.ExpectingInput);
onTurnErrorMessage = 'To continue to run this bot, please fix the bot source code.';
await context.sendActivity(onTurnErrorMessage, onTurnErrorMessage, InputHints.ExpectingInput);
// Clear out state
await conversationState.delete(context);
};
async function sendErrorMessage(context, error) {
try {
// Send a message to the user.
let onTurnErrorMessage = 'The skill encountered an error or bug.';
await context.sendActivity(onTurnErrorMessage, onTurnErrorMessage, InputHints.ExpectingInput);
onTurnErrorMessage = 'To continue to run this bot, please fix the bot source code.';
await context.sendActivity(onTurnErrorMessage, onTurnErrorMessage, InputHints.ExpectingInput);
// Send a trace activity, which will be displayed in the Bot Framework Emulator.
// Note: we return the entire exception in the value property to help the developer;
// this should not be done in production.
await context.sendTraceActivity('OnTurnError Trace', error.toString(), 'https://www.botframework.com/schemas/error', 'TurnError');
} catch (err) {
console.error(`\n [onTurnError] Exception caught in sendErrorMessage: ${ err }`);
}
}
async initialStep(stepContext) {
const timex = stepContext.options.date;
const promptMessageText = 'On what date would you like to travel?';
const promptMessage = MessageFactory.text(promptMessageText, promptMessageText, InputHints.ExpectingInput);
const repromptMessageText = "I'm sorry, for best results, please enter your travel date including the month, day and year.";
const repromptMessage = MessageFactory.text(repromptMessageText, repromptMessageText, InputHints.ExpectingInput);
if (!timex) {
// We were not given any date at all so prompt the user.
return await stepContext.prompt(DATETIME_PROMPT,
{
prompt: promptMessage,
retryPrompt: repromptMessage
});
}
// We have a Date we just need to check it is unambiguous.
const timexProperty = new TimexProperty(timex);
if (!timexProperty.types.has('definite')) {
// This is essentially a "reprompt" of the data we were given up front.
return await stepContext.prompt(DATETIME_PROMPT, { prompt: repromptMessage });
}
return await stepContext.next([{ timex: timex }]);
export function sendPrompt(context: TurnContext, prompt: string|Partial, speak?: string): Promise {
// Compose activity
const msg: Partial = typeof prompt === 'string' ? { text: prompt } : Object.assign({}, prompt);
if (speak) { msg.speak = speak }
if (!msg.type) { msg.type = ActivityTypes.Message }
if (!msg.inputHint) { msg.inputHint = InputHints.ExpectingInput }
// Send activity and eat response.
return context.sendActivity(msg).then(() => { });
}
async initialStep(stepContext) {
const timex = stepContext.options.date;
const promptMessageText = 'When would you like to travel?';
const promptMessage = MessageFactory.text(promptMessageText, promptMessageText, InputHints.ExpectingInput);
const repromptMessageText = "I'm sorry, to make your booking please enter a full travel date, including Day, Month, and Year.";
const repromptMessage = MessageFactory.text(repromptMessageText, repromptMessageText, InputHints.ExpectingInput);
// This value will be a TIMEX. We are only interested in the Date part, so grab the first result and drop the Time part.
// TIMEX is a format that represents DateTime expressions that include some ambiguity, such as a missing Year.
if (!timex) {
// We were not given any date at all so prompt the user.
return await stepContext.prompt(DATETIME_PROMPT,
{
prompt: promptMessage,
retryPrompt: repromptMessage
});
}
// We have a Date we just need to check it is unambiguous.
const timexProperty = new TimexProperty(timex);
async initialStep(stepContext) {
const timex = stepContext.options.date;
const promptMessageText = 'On what date would you like to travel?';
const promptMessage = MessageFactory.text(promptMessageText, promptMessageText, InputHints.ExpectingInput);
const repromptMessageText = "I'm sorry, for best results, please enter your travel date including the month, day and year.";
const repromptMessage = MessageFactory.text(repromptMessageText, repromptMessageText, InputHints.ExpectingInput);
if (!timex) {
// We were not given any date at all so prompt the user.
return await stepContext.prompt(DATETIME_PROMPT,
{
prompt: promptMessage,
retryPrompt: repromptMessage
});
}
// We have a Date we just need to check it is unambiguous.
const timexProperty = new TimexProperty(timex);
if (!timexProperty.types.has('definite')) {
// This is essentially a "reprompt" of the data we were given up front.
async initialStep(stepContext) {
const timex = stepContext.options.date;
const promptMessageText = 'When would you like to travel?';
const promptMessage = MessageFactory.text(promptMessageText, promptMessageText, InputHints.ExpectingInput);
const repromptMessageText = "I'm sorry, to make your booking please enter a full travel date, including Day, Month, and Year.";
const repromptMessage = MessageFactory.text(repromptMessageText, repromptMessageText, InputHints.ExpectingInput);
// This value will be a TIMEX. We are only interested in the Date part, so grab the first result and drop the Time part.
// TIMEX is a format that represents DateTime expressions that include some ambiguity, such as a missing Year.
if (!timex) {
// We were not given any date at all so prompt the user.
return await stepContext.prompt(DATETIME_PROMPT,
{
prompt: promptMessage,
retryPrompt: repromptMessage
});
}
// We have a Date we just need to check it is unambiguous.
const timexProperty = new TimexProperty(timex);
// If this is a definite Date that includes year, month and day we are good; otherwise, reprompt.
if (!timexProperty.types.has('definite')) {
// This is essentially a "reprompt" of the data we were given up front.
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();
}
}
}
}