Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log(`${server.name} listening to ${server.url}`);
});
// Create adapter
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
// Add conversation state middleware
const conversationState = new ConversationState(new MemoryStorage());
adapter.use(conversationState);
// Add language translator middleware
const languageTranslator = new LanguageTranslator({
translatorKey: "xxxxxx",
nativeLanguages: ['fr', 'de']
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new LocaleConverter({
toLocale: 'fr-fr',
fromLocale: 'en-us'
})
adapter.use(localeConverter);
// Listen for incoming requests
server.post('/api/messages', (req, res) => {
// Route received request to adapter for processing
adapter.processActivity(req, res, (context) => {
const restify = require("restify");
// Create server
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log(`${server.name} listening to ${server.url}`);
});
// Create adapter
const adapter = new botbuilder_1.BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
// Add conversation state middleware
const conversationState = new botbuilder_1.ConversationState(new botbuilder_1.MemoryStorage());
adapter.use(conversationState);
// Add language translator middleware
const languageTranslator = new botbuilder_ai_1.LanguageTranslator({
translatorKey: "xxxxxx",
noTranslatePatterns: new Set(),
nativeLanguages: ['fr', 'de']
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new botbuilder_ai_1.LocaleConverter({
toLocale: 'fr-fr',
fromLocale: 'en-us'
});
adapter.use(localeConverter);
// Listen for incoming requests
server.post('/api/messages', (req, res) => {
// Route received request to adapter for processing
adapter.processActivity(req, res, (context) => __awaiter(this, void 0, void 0, function* () {
if (context.activity.type === 'message') {
}
function setUserLocale(context) {
return __awaiter(this, void 0, void 0, function* () {
let state = conversationState.get(context);
if (context.activity.text.toLowerCase().startsWith('set my locale to')) {
state.locale = context.activity.text.toLowerCase().replace('set my locale to', '').trim();
yield context.sendActivity(`Setting your locale to ${state.locale}`);
return Promise.resolve(true);
}
else {
return Promise.resolve(false);
}
});
}
// Add language translator middleware
const languageTranslator = new botbuilder_ai_1.LanguageTranslator({
translatorKey: "xxxxxx",
noTranslatePatterns: new Set(),
nativeLanguages: ['en'],
setUserLanguage: setUserLanguage,
getUserLanguage: getUserLanguage
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new botbuilder_ai_1.LocaleConverter({
toLocale: 'en-us',
setUserLocale: setUserLocale,
getUserLocale: getUserLocale
});
adapter.use(localeConverter);
// Add Qna Maker middleware
const qnaMaker = new botbuilder_ai_1.QnAMaker({
}
function setUserLocale(context) {
return __awaiter(this, void 0, void 0, function* () {
let state = conversationState.get(context);
if (context.activity.text.toLowerCase().startsWith('set my locale to')) {
state.locale = context.activity.text.toLowerCase().replace('set my locale to', '').trim();
yield context.sendActivity(`Setting your locale to ${state.locale}`);
return Promise.resolve(true);
}
else {
return Promise.resolve(false);
}
});
}
// Add language translator middleware
const languageTranslator = new botbuilder_ai_1.LanguageTranslator({
translatorKey: "xxxxxx",
noTranslatePatterns: new Set(),
nativeLanguages: ['en'],
setUserLanguage: setUserLanguage,
getUserLanguage: getUserLanguage
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new botbuilder_ai_1.LocaleConverter({
toLocale: 'en-us',
setUserLocale: setUserLocale,
getUserLocale: getUserLocale
});
adapter.use(localeConverter);
// Add Luis recognizer middleware
const luisRecognizer = new botbuilder_ai_1.LuisRecognizer({
}
}
async function setUserLocale(context) {
let state = conversationState.get(context)
if (context.activity.text.toLowerCase().startsWith('set my locale to')) {
state.locale = context.activity.text.toLowerCase().replace('set my locale to', '').trim();
await context.sendActivity(`Setting your locale to ${state.locale}`);
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
}
// Add language translator middleware
const languageTranslator = new LanguageTranslator({
translatorKey: "xxxxxx",
nativeLanguages: ['en'],
setUserLanguage: setUserLanguage,
getUserLanguage: getUserLanguage,
translateBackToUserLanguage: true
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new LocaleConverter({
toLocale: 'en-us',
setUserLocale: setUserLocale,
getUserLocale: getUserLocale,
});
adapter.use(localeConverter);
}
}
async function setUserLocale(context: TurnContext): Promise {
let state = conversationState.get(context)
if (context.activity.text.toLowerCase().startsWith('set my locale to')) {
state.locale = context.activity.text.toLowerCase().replace('set my locale to', '').trim();
await context.sendActivity(`Setting your locale to ${state.locale}`);
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
}
// Add language translator middleware
const languageTranslator = new LanguageTranslator({
translatorKey: "xxxxxx",
nativeLanguages: ['en'],
setUserLanguage: setUserLanguage,
getUserLanguage: getUserLanguage
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new LocaleConverter({
toLocale: 'en-us',
setUserLocale: setUserLocale,
getUserLocale: getUserLocale
});
adapter.use(localeConverter);
// Add Luis recognizer middleware
const adapter = new BotFrameworkAdapter( {
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
// Define conversation state shape
interface EchoState {
count: number;
}
// Add conversation state middleware
const conversationState = new ConversationState(new MemoryStorage());
adapter.use(conversationState);
// Add language translator middleware
const languageTranslator = new LanguageTranslator({
translatorKey: "xxxxxx",
nativeLanguages: ['fr', 'de']
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new LocaleConverter({
toLocale: 'fr-fr',
fromLocale: 'en-us'
})
adapter.use(localeConverter);
// Listen for incoming requests
server.post('/api/messages', (req, res) => {
// Route received request to adapter for processing
adapter.processActivity(req, res, async (context) => {
}
}
async function setUserLocale(context: TurnContext): Promise {
let state = conversationState.get(context)
if (context.activity.text.toLowerCase().startsWith('set my locale to')) {
state.locale = context.activity.text.toLowerCase().replace('set my locale to', '').trim();
await context.sendActivity(`Setting your locale to ${state.locale}`);
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
}
// Add language translator middleware
const languageTranslator = new LanguageTranslator({
translatorKey: "xxxxxx",
nativeLanguages: ['en'],
setUserLanguage: setUserLanguage,
getUserLanguage: getUserLanguage
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new LocaleConverter({
toLocale: 'en-us',
setUserLocale: setUserLocale,
getUserLocale: getUserLocale
});
adapter.use(localeConverter);
// Add Qna Maker middleware