Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { BotFrameworkAdapter, ConversationState, MemoryStorage, UserState, ActivityFactory } = require('botbuilder');
// Import our custom bot class that provides a turn handling function.
const { DialogBot } = require('./bots/dialogBot');
const { UserProfileDialog } = require('./dialogs/userProfileDialog');
// Create the adapter. See https://aka.ms/about-bot-adapter to learn more about using information from
// the .bot file when configuring your adapter.
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
// Create template engine for language generation.
const templatesPerLocale = new Map();
templatesPerLocale.set('', Templates.parseFile(`${__dirname}/Resources/adapterWithErrorHandler.lg`)),
templatesPerLocale.set('fr', Templates.parseFile(`${__dirname}/Resources/adapterWithErrorHandler.fr-fr.lg`));
const multiLangLG = new MultiLanguageLG(templatesPerLocale);
// Catch-all for errors.
adapter.onTurnError = async (context, error) => {
// This check writes out errors to console log .vs. app insights.
// NOTE: In production environment, you should consider logging this to Azure
// application insights. See https://aka.ms/bottelemetry for telemetry
// configuration instructions.
let langResponse = multiLangLG.generate('SomethingWentWrong', {
message: `${ error }`
}, context.activity.locale);
console.error(langResponse);
// Send a trace activity, which will be displayed in Bot Framework Emulator
await context.sendTraceActivity(
// Import required bot services.
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
const { BotFrameworkAdapter, MemoryStorage, ConversationState, UserState } = require('botbuilder');
// This bot's main dialog.
const { RichCardsBot } = require('./bots/richCardsBot');
const { MainDialog } = require('./dialogs/mainDialog');
// Create adapter. See https://aka.ms/about-bot-adapter to learn more about adapters.
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
// Create template engine for language generation.
const lgTemplates = Templates.parseFile('./resources/AdapterWithErrorHandler.lg');
// Catch-all for errors.
adapter.onTurnError = async (context, error) => {
// This check writes out errors to console log .vs. app insights.
// NOTE: In production environment, you should consider logging this to Azure
// application insights. See https://aka.ms/bottelemetry for telemetry
// 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',
// Create HTTP server
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
console.log(`\n${ server.name } listening to ${ server.url }`);
console.log('\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator');
console.log('\nTo talk to your bot, open the emulator select "Open Bot"');
});
// Create adapter.
// See https://aka.ms/about-bot-adapter to learn more about how bots work.
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
const lgTemplates = Templates.parseFile(path.join(__dirname, './resources/AdapterWithErrorHandler.lg'));
// Catch-all for errors.
const onTurnErrorHandler = async (context, error) => {
// This check writes out errors to console log .vs. app insights.
// NOTE: In production environment, you should consider logging this to Azure
// application insights. See https://aka.ms/bottelemetry for telemetry
// 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',
const { MainDialog } = require('./dialogs/mainDialog');
// the bot's booking dialog
const { BookingDialog } = require('./dialogs/bookingDialog');
const BOOKING_DIALOG = 'bookingDialog';
// Create adapter.
// See https://aka.ms/about-bot-adapter to learn more about adapters.
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
// Create template engine for language generation.
console.log(path.join(__dirname, './resources/AdapterWithErrorHandler.lg'));
const lgTemplates = Templates.parseFile(path.join(__dirname, './resources/AdapterWithErrorHandler.lg'));
// Catch-all for errors.
adapter.onTurnError = async (context, error) => {
// This check writes out errors to console log .vs. app insights.
// NOTE: In production environment, you should consider logging this to Azure
// application insights. See https://aka.ms/bottelemetry for telemetry
// 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',
constructor() {
super('MainDialog');
// Define the main dialog and its related components.
this.addDialog(new ChoicePrompt('cardPrompt'));
this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.choiceCardStep.bind(this),
this.showCardStep.bind(this)
]));
// The initial child Dialog to run.
this.initialDialogId = MAIN_WATERFALL_DIALOG;
this.lgTemplates = Templates.parseFile('./resources/MainDialog.lg');
}
constructor(conversationState, userState, dialog) {
super(conversationState, userState, dialog);
const lgTemplates = Templates.parseFile('./resources/welcomeCard.lg');
// Actions to include in the welcome card. These are passed to LG and are then included in the generated Welcome card.
const actions = {
actions: [
{
title: 'Get an overview',
url: 'https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0'
},
{
title: 'Ask a question',
url: 'https://stackoverflow.com/questions/tagged/botframework'
},
{
title: 'Learn how to deploy',
url: 'https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-deploy-azure?view=azure-bot-service-4.0'
}
constructor() {
super('userProfileDialog');
let lgFile = Templates.parseFile(path.join(__dirname, "userProfileDialog.lg"));
let userProfileAdaptiveDialog = new AdaptiveDialog(ROOT_DIALOG).configure({
generator: new TemplateEngineLanguageGenerator(lgFile),
triggers: [
new OnBeginDialog([
// Ask for user's age and set it in user.userProfile scope.
new TextInput().configure(
{
// Set the output of the text input to this property in memory.
property: new StringExpression("user.userProfile.Transport"),
prompt: new ActivityTemplate("${ModeOfTransportPrompt.Text()}")
}),
new TextInput().configure(
{
property: new StringExpression("user.userProfile.Name"),
prompt: new ActivityTemplate("${AskForName()}")
}),
constructor() {
super('MainDialog');
// Define the main dialog and its related components.
this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.showMultilingualResult.bind(this)
]));
// The initial child Dialog to run.
this.initialDialogId = MAIN_WATERFALL_DIALOG;
var lgTemplatesMap = new Map();
lgTemplatesMap.set('fr-fr', Templates.parseFile("./resources/root.lg", this.multilingualResolver('fr-fr')));
lgTemplatesMap.set('en-us', Templates.parseFile("./resources/root.lg", this.multilingualResolver('en-us')));
lgTemplatesMap.set("", Templates.parseFile("./resources/root.lg", this.multilingualResolver('')));
this.generator = new MultiLanguageLG(lgTemplatesMap, undefined);
}
super(id || 'bookingDialog');
this.addDialog(new TextPrompt(TEXT_PROMPT))
.addDialog(new ConfirmPrompt(CONFIRM_PROMPT))
.addDialog(new DateResolverDialog(DATE_RESOLVER_DIALOG))
.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.destinationStep.bind(this),
this.originStep.bind(this),
this.travelDateStep.bind(this),
this.confirmStep.bind(this),
this.finalStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
this.lgTemplates = Templates.parseFile(path.join(__dirname, '../resources/BookingDialog.lg'));
}
this.addDialog(new ChoicePrompt(CHOICE_PROMPT));
this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
this.addDialog(new NumberPrompt(NUMBER_PROMPT, this.agePromptValidator));
this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.transportStep.bind(this),
this.nameStep.bind(this),
this.nameConfirmStep.bind(this),
this.ageStep.bind(this),
this.confirmStep.bind(this),
this.summaryStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
this.lgTemplates = Templates.parseFile('./Resources/UserProfileDialog.lg');
}