Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
app = new VoxaApp({ views, variables });
azureTableClient = new azure.AzureTableClient();
storage = new azure.AzureBotStorage({ gzipData: false }, azureTableClient);
// we need to mock this before instantiating the platforms cause otherwise
// we try to get the authorization token
adapter = new BotFrameworkPlatform(app, { recognizer, storage });
simple.mock(storage, 'getData')
.callbackWith(null, {});
simple.mock(storage, 'saveData')
.callbackWith(null, {});
simple.mock(adapter, 'botApiRequest')
.resolveWith(true);
});
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
/*----------------------------------------------------------------------------------------
* Bot Storage: This is a great spot to register the private state storage for your bot.
* We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
* For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure
* ---------------------------------------------------------------------------------------- */
var tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
// Create your bot with a function to receive messages from the user
// This default message handler is invoked if the user's utterance doesn't
// match any intents handled by other dialogs.
var bot = new builder.UniversalBot(connector, function (session, args) {
session.send('You reached the default message handler. You said \'%s\'.', session.message.text);
});
bot.set('storage', tableStorage);
// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';
const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v2.0/apps/' + luisAppId + '?subscription-key=' + luisAPIKey;
// Graph
var graph = {};
// Listen for messages from users
server.post('/api/messages', connector.listen());
/*----------------------------------------------------------------------------------------
* Bot Storage: This is a great spot to register the private state storage for your bot.
* We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
* For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure
* ---------------------------------------------------------------------------------------- */
var tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
// Create your bot with a function to receive messages from the user
var bot = new builder.UniversalBot(connector);
bot.set('storage', tableStorage);
bot.dialog('/', [
function (session) {
if (session.privateConversationData["welcome"]) {
session.send("Hi I'm your SharePoint Bot to assist you to request a new SharePoint site or Teams, what do you want to request?");
}
session.privateConversationData["welcome"] = 'true';
session.beginDialog('makeYourChoice');
},
function (session, results) {
session.privateConversationData["SiteType"] = results.response;
session.beginDialog('askForTitle');
if (!session.privateConversationData[UserWelcomedKey]) {
session.privateConversationData[UserWelcomedKey] = true;
return session.send('Welcome back %s! Remember the rules: %s', userName, HelpMessage);
}
session.beginDialog('search');
}).set('storage', inMemoryStorage); // Register in memory storage
// Azure DocumentDb State Store
var docDbClient = new azure.DocumentDbClient({
host: process.env.DOCUMENT_DB_HOST,
masterKey: process.env.DOCUMENT_DB_MASTER_KEY,
database: process.env.DOCUMENT_DB_DATABASE,
collection: process.env.DOCUMENT_DB_COLLECTION
});
var botStorage = new azure.AzureBotStorage({ gzipData: false }, docDbClient);
// Set Custom Store
bot.set('storage', botStorage);
// Enable Conversation Data persistence
bot.set('persistConversationData', true);
// search dialog
bot.dialog('search', function (session, args, next) {
// perform search
var city = session.privateConversationData[CityKey] || session.conversationData[CityKey];
var userName = session.userData[UserNameKey];
var messageText = session.message.text.trim();
session.send('%s, wait a few seconds. Searching for \'%s\' in \'%s\'...', userName, messageText, city);
session.send('https://www.bing.com/search?q=%s', encodeURIComponent(messageText + ' in ' + city));
session.endDialog();
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
/*----------------------------------------------------------------------------------------
* Bot Storage: This is a great spot to register the private state storage for your bot.
* We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
* For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure
* ---------------------------------------------------------------------------------------- */
var tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
// Create your bot with a function to receive messages from the user
// This default message handler is invoked if the user's utterance doesn't
// match any intents handled by other dialogs.
var bot = new builder.UniversalBot(connector, function (session, args) {
session.send('You reached the default message handler. You said \'%s\'.', session.message.text);
});
bot.set('storage', tableStorage);
// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';
const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v2.0/apps/' + luisAppId + '?subscription-key=' + luisAPIKey;
// Create chat connector for communicating with the Bot Framework Service
const connector = new builder.ChatConnector({
appId: microsoftAppId,
appPassword: microsoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
})
/*----------------------------------------------------------------------------------------
* Bot Storage: This is a great spot to register the private state storage for your bot.
* We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
* For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure
* ---------------------------------------------------------------------------------------- */
const tableName = 'botdata'
const azureTableClient = new botbuilder_azure.AzureTableClient(tableName, azureWebJobsStorage)
const tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient)
const dialogs = require('require-all')(__dirname + '/dialogs')
const luis = require('./luis.js')
const _initialize = (server) => {
// Listen for messages from users
server.post('/api/messages', connector.listen())
// Create your bot with a function to receive messages from the user
const bot = new builder.UniversalBot(connector, (session, args) => {
// Prevent open dialogs when LUIS is enabled
if(!session.userData.luisEnabled) {
session.beginDialog('/menu')
}