Last active
June 6, 2017 10:36
-
-
Save alexzaitsev/c2baa8dd83bd583b45a8647ba8165cc5 to your computer and use it in GitHub Desktop.
How To Write Reusable and Testable Code with Microsoft Bot Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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