Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create connector and listen for messages
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
// Bot Storage: Here we register the state storage for your bot.
// Default store: volatile in-memory store - Only for prototyping!
// 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 inMemoryStorage = new builder.MemoryBotStorage();
var bot = new builder.UniversalBot(connector, function (session) {
session.send('Sorry, I did not understand \'%s\'. Type \'help\' if you need assistance.', session.message.text);
}).set('storage', inMemoryStorage); // Register in memory storage
// You can provide your own model by specifing the 'LUIS_MODEL_URL' environment variable
// This Url can be obtained by uploading or creating your model from the LUIS portal: https://www.luis.ai/
var recognizer = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL);
bot.recognizer(recognizer);
bot.dialog('SearchHotels', [
function (session, args, next) {
session.send('Welcome to the Hotels finder! We are analyzing your message: \'%s\'', session.message.text);
// try extracting entities
var cityEntity = builder.EntityRecognizer.findEntity(args.intent.entities, 'builtin.geography.city');
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// setup bot credentials
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
// Bot Storage: Here we register the state storage for your bot.
// Default store: volatile in-memory store - Only for prototyping!
// 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 inMemoryStorage = new builder.MemoryBotStorage();
var bot = new builder.UniversalBot(connector).set('storage', inMemoryStorage); // Register in memory storage
// handle the proactive initiated dialog
bot.dialog('/survey', [
function (session, args, next) {
var prompt = ('Hello, I\'m the survey dialog. I\'m interrupting your conversation to ask you a question. Type "done" to resume');
builder.Prompts.choice(session, prompt, "done");
},
function (session, results) {
session.send("Great, back to the original conversation");
session.endDialog();
}
]);
// initiate a dialog proactively
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
// Bot Storage: Here we register the state storage for your bot.
// Default store: volatile in-memory store - Only for prototyping!
// 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 inMemoryStorage = new builder.MemoryBotStorage();
var bot = new builder.UniversalBot(connector, function (session) {
if (hasAudioAttachment(session)) {
var stream = getAudioStreamFromMessage(session.message);
speechService.getTextFromAudioStream(stream)
.then(function (text) {
session.send(processText(text));
})
.catch(function (error) {
session.send('Oops! Something went wrong. Try again later.');
console.error(error);
});
} else {
session.send('Did you upload an audio file? I\'m more of an audible person. Try sending me a wav file');
}
}).set('storage', inMemoryStorage); // Register in memory storage
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
// Bot Storage: Here we register the state storage for your bot.
// Default store: volatile in-memory store - Only for prototyping!
// 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 inMemoryStorage = new builder.MemoryBotStorage();
// Gets the caption by checking the type of the image (stream vs URL) and calling the appropriate caption service method.
var bot = new builder.UniversalBot(connector, function (session) {
if (hasImageAttachment(session)) {
var stream = getImageStreamFromMessage(session.message);
captionService
.getCaptionFromStream(stream)
.then(function (caption) { handleSuccessResponse(session, caption); })
.catch(function (error) { handleErrorResponse(session, error); });
} else {
var imageUrl = parseAnchorTag(session.message.text) || (validUrl.isUri(session.message.text) ? session.message.text : null);
if (imageUrl) {
captionService
.getCaptionFromUrl(imageUrl)
.then(function (caption) { handleSuccessResponse(session, caption); })
.catch(function (error) { handleErrorResponse(session, error); });
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
var DialogLabels = {
Hotels: 'Hotels',
Flights: 'Flights',
Support: 'Support'
};
// Bot Storage: Here we register the state storage for your bot.
// Default store: volatile in-memory store - Only for prototyping!
// 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 inMemoryStorage = new builder.MemoryBotStorage();
var bot = new builder.UniversalBot(connector, [
function (session) {
// prompt for search option
builder.Prompts.choice(
session,
'Are you looking for a flight or a hotel?',
[DialogLabels.Flights, DialogLabels.Hotels],
{
maxRetries: 3,
retryPrompt: 'Not a valid option'
});
},
function (session, result) {
if (!result.response) {
// exhausted attemps and no selection, start over
// Create chat connector for communicating with the Bot Framework Service
const connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
stateEndpoint: process.env.BotStateEndpoint,
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
// Create an "in memory" bot storage.
// In production scenario, Microsoft provides 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 botStorage = new builder.MemoryBotStorage();
const bot = new builder.UniversalBot(connector);
// Register in-memory storage for the bot
bot.set('storage', botStorage);
//=========================================================
// Bot events
//=========================================================
bot.on("event", (event) => {
switch (event.name) {
// Event when an access token has been received for an user
case "userAuthenticated":
if (event.value) {
module.exports.setup = function(app) {
var builder = require('botbuilder');
var teams = require('botbuilder-teams');
var config = require('config');
// Create a connector to handle the conversations
var connector = new teams.TeamsChatConnector({
// It is a bad idea to store secrets in config files. We try to read the settings from
// the config file (src/config/default.json) OR then environment variables.
// See node config module (https://www.npmjs.com/package/config) on how to create config files for your Node.js environment.
appId: config.get("bot.appId"),
appPassword: config.get("bot.appPassword")
});
var inMemoryBotStorage = new builder.MemoryBotStorage();
// Define a simple bot with the above connector that echoes what it received
var bot = new builder.UniversalBot(connector, function(session) {
// Message might contain @mentions which we would like to strip off in the response
var text = teams.TeamsMessage.getTextWithoutMentions(session.message);
session.send('You said: %s', text);
}).set('storage', inMemoryBotStorage);
// Setup an endpoint on the router for the bot to listen.
// NOTE: This endpoint cannot be changed and must be api/messages
app.post('/api/messages', connector.listen());
// Export the connector for any downstream integration - e.g. registering a messaging extension
module.exports.connector = connector;
};
const connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
// Create your bot with a function to receive messages from the user
var bot = new builder.UniversalBot(connector, function (session, args) {
session.send("I'm sorry I didn't understand, that.\nI'm not smart, I'm only made of code 😞", session.message.text);
//session.beginDialog('HelpDialog');
});
var inMemoryStorage = new builder.MemoryBotStorage();
bot.set('storage', inMemoryStorage);
bot.set('persistConversationData', true);
// Create a recognizer that gets intents from LUIS, and add it to the bot
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
bot.recognizer(recognizer);
// Send welcome when conversation with bot is started, by initiating the GreetingDialog
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.beginDialog(message.address, 'ActiveEventsDialog');//'GreetingDialog');
}
});
}
var botbuilder_azure = require('botbuilder-azure');
var lifx = require('lifx-http-api'),
lifxClient;
lifxClient = new lifx({
bearerToken: process.env['LifxApiKey']
});
var connector = new botbuilder_azure.BotServiceConnector({
appId: process.env['MicrosoftAppId'],
appPassword: process.env['MicrosoftAppPassword']
// openIdMetadata: process.env['BotOpenIdMetadata']
});
var bot = new builder.UniversalBot(connector, {
storage: new builder.MemoryBotStorage()
});
let luisModelUrl = `https://${process.env['LuisAPIHostName']}/luis/v2.0/apps/${
process.env['LuisAppId']
}?subscription-key=${process.env['LuisAPIKey']}`;
// Main dialog with LUIS
const recognizer = new builder.LuisRecognizer(luisModelUrl);
const intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('Greeting', session => {
session.send('Sup, yo!');
})
.matches('Thank You', session => {
session.send('No problem! Glad I could help.');
})
.matches('Help', session => {
beforeEach(() => {
audioCard = new AudioCard();
const cardMedia: ICardMediaUrl = {
profile: "",
url: "http://example.com/audio.mp3",
};
audioCard.media([cardMedia]);
const storage = new MemoryBotStorage();
const rawEvent = prepIncomingMessage(
_.cloneDeep(require("../requests/botframework/conversationUpdate.json")),
);
event = new BotFrameworkEvent({ message: rawEvent, stateData });
reply = new BotFrameworkReply(event);
simple.mock(storage, "saveData").callbackWith(null, {});
});