How to use the botbuilder.UniversalBot function in botbuilder

To help you get started, we’ve selected a few botbuilder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sebsylvester / reminder-bot / test / newReminder.js View on Github external
it('should call Reminder.create to save a reminder to MongoDB (1)', function (done) {
        const connector = new builder.ConsoleConnector();
        const bot = new builder.UniversalBot(connector);
        const args = {
            reminder: { type: 'reminder', entity: 'make coffee' },
            datetime: { rawEntity: { type: 'value', value: '2016-11-28T15:00:00.000Z'}},
            message: 'Remind me to make coffee at 3pm'
        };
        const normalizedDatetime = '2016-11-28T14:00:00.000Z';

        // Create a stub on the Reminder model
        sinon.stub(Reminder, 'create').callsFake(reminder => {
            expect(reminder.user_address).to.be.an('object');
            expect(reminder.value).to.equal(args.reminder.entity);
            expect(reminder.expiration).to.deep.equal(new Date(normalizedDatetime));
            Reminder.create.restore();
            done();
        });
github microsoft / BotBuilder-Samples / Node / core-proactiveMessages / startNewDialog / index.js View on Github external
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) {
  if (session.message.text === "done") {
    session.send("Great, back to the original conversation");
    session.endDialog();
  } else {
    session.send('Hello, I\'m the survey dialog. I\'m interrupting your conversation to ask you a question. Type "done" to resume');
  }
});

// initiate a dialog proactively 
function startProactiveDialog(address) {
  bot.beginDialog(address, "*:/survey");
}
github lodev09 / sbotify / src / app.js View on Github external
// Create chat bot
const connector = new ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD,
    gzipData: true
});

const parseName = function(session, def) {
    if (!session.message.user) return def;
    var name = session.message.user.name.trim().toLowerCase().match(/^[\w]+/i);

    return name === '' ? def : name;
}

const bot = new UniversalBot(connector, function (session) {
    session.send("sorry %s, I didn't understand", parseName(session));
    session.beginDialog('ShowHelp');
});

const getSpotify = function(session, options) {
    var message = null;
    if (session.conversationData.spotifyToken && session.conversationData.spotifyUser) {
        return new Spotify(session.conversationData.spotifyToken, session.conversationData.spotifyUser);
    } else {
        message = 'okay before I do that, do you have a **premium** spotify account?'
        session.replaceDialog('AuthorizeSpotify', { message, options });
    }
}

const createTrackCard = function(session, track) {
    var artist = track.artists && track.artists.length > 0 ? track.artists[0].name : 'not sure who';
github microsoft / BotBuilder-Samples / Node / core-SendAttachment / app.js View on Github external
var connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

// Listen for messages
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();

// Bot Dialogs
var bot = new builder.UniversalBot(connector, [
    function (session) {
        session.send('Welcome, here you can see attachment alternatives:');
        builder.Prompts.choice(session, 'What sample option would you like to see?', Options, {
            maxRetries: 3
        });
    },
    function (session, results) {
        var option = results.response ? results.response.entity : Inline;
        switch (option) {
            case Inline:
                return sendInline(session, './images/small-image.png', 'image/png', 'BotFrameworkLogo.png');
            case Upload:
                return uploadFileAndSend(session, './images/big-image.png', 'image/png', 'BotFramework.png');
            case External:
                var url = 'https://docs.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png';
                return sendInternetUrl(session, url, 'image/png', 'BotFrameworkOverview.png');
github nzthiago / BotInsightsTests / Node / bot.js View on Github external
function create(connector) {
    
    appInsights.setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY).start();
    var appInsightsClient = appInsights.getClient();

    var HelpMessage = '\n * If you want to know which city I\'m using for my searches type \'current city\'. \n * Want to change the current city? Type \'change city to cityName\'. \n * Want to change it just for your searches? Type \'change my city to cityName\'';
    var UserNameKey = 'UserName';
    var UserWelcomedKey = 'UserWelcomed';
    var CityKey = 'City';

    // Setup bot with default dialog
    var bot = new builder.UniversalBot(connector, function (session) {

        var telemetry = telemetryModule.createTelemetry(session, { setDefault: false });

        // initialize with default city
        if (!session.conversationData[CityKey]) {
            session.conversationData[CityKey] = 'Seattle';

            telemetry.setDefault = true;
        }

        var defaultCity = session.conversationData[CityKey];
        session.send('Welcome to the Search City bot. I\'m currently configured to search for things in %s', defaultCity);

        appInsightsClient.trackTrace('start', telemetry);

        session.beginDialog('search');
github microsoftly / BotTester / test / BotTesterFailure.spec.ts View on Github external
beforeEach(() => {
        bot = new UniversalBot(connector);
    });
github gudwin / botbuilder-unit / example / spec / botSpec.js View on Github external
beforeEach( () => {
    let connector = new builder.ConsoleConnector().listen();
    bot = new builder.UniversalBot(connector);
    bot.dialog('/', [
      session => builder.Prompts.text(session,'How should I call you?'),
      (session, response) => session.endDialog(`Nice to meet you, ${JSON.stringify(response.response)}!`)
    ]);
  });
  it('Test welcome flow', (done) => {
github broidHQ / integrations / broid-ms-teams / lib / core / Adapter.js View on Github external
connect() {
        if (this.connected) {
            return Rx_1.Observable.of({ type: 'connected', serviceID: this.serviceId() });
        }
        if (!this.token || !this.tokenSecret) {
            return Rx_1.Observable.throw(new Error('Credentials should exist.'));
        }
        this.sessionConnector = new botbuilder.ChatConnector({
            appId: this.token,
            appPassword: this.tokenSecret,
        });
        this.session = new botbuilder.UniversalBot(this.sessionConnector);
        this.router.post('/', this.sessionConnector.listen());
        if (this.webhookServer) {
            this.webhookServer.listen();
        }
        this.connected = true;
        return Rx_1.Observable.of({ type: 'connected', serviceID: this.serviceId() });
    }
    disconnect() {
github SAPConversationalAI / bot-connector / src / channel_integrations / microsoft / utils.js View on Github external
export function microsoftGetBot (channel) {
  const connector = new ChatConnector({
    appId: channel.clientId,
    appPassword: channel.clientSecret,
  })
  const bot = new UniversalBot(connector).set('storage', new MemoryBotStorage())
  return bot
}