Skip to content

Instantly share code, notes, and snippets.

@alexzaitsev
Last active June 6, 2017 10:36
Show Gist options
  • Save alexzaitsev/c2baa8dd83bd583b45a8647ba8165cc5 to your computer and use it in GitHub Desktop.
Save alexzaitsev/c2baa8dd83bd583b45a8647ba8165cc5 to your computer and use it in GitHub Desktop.
How To Write Reusable and Testable Code with Microsoft Bot Framework
"use strict";
const builder = require("botbuilder");
const library = new builder.Library('welcome'); // welcome is a library name
const LANGUAGES = {'English': 'en', 'Русский': 'ru'};
library.dialog('/pickLocale', [
(session) => {
// Prompt the user to select their preferred locale
builder.Prompts.choice(session, "What language do you prefer?", Object.keys(LANGUAGES).join("|"));
},
(session, results) => {
// Update preferred locale
let locale = LANGUAGES[results.response.entity];
session.preferredLocale(locale, (err) => {
if (err) {
// Problem loading the selected locale
session.error(err);
} else {
// Locale files loaded
session.endDialog("locale_set", results.response.entity);
}
});
}
]);
library.dialog('/showWelcomeMessage', [
(session) => session.endDialog("welcome")
]);
module.exports = library;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment