Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

botbuilder

Package Overview
Dependencies
Maintainers
1
Versions
631
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

botbuilder

Bot Builder is a dialog system for building rich bots on virtually any platform.

  • 3.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
98K
decreased by-2.34%
Maintainers
1
Weekly downloads
 
Created

What is botbuilder?

The botbuilder npm package is a comprehensive framework for building conversational AI experiences using Microsoft Bot Framework. It provides tools and libraries to create, test, and deploy chatbots across various platforms such as Microsoft Teams, Slack, and Facebook Messenger.

What are botbuilder's main functionalities?

Creating a Simple Echo Bot

This code sample demonstrates how to create a simple echo bot using the botbuilder package. The bot listens for incoming messages and echoes back the text received.

const { ActivityHandler, BotFrameworkAdapter } = require('botbuilder');
const restify = require('restify');

const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
    console.log(`\n${server.name} listening to ${server.url}`);
});

const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

const bot = new ActivityHandler();
bot.onMessage(async (context, next) => {
    await context.sendActivity(`You said '${context.activity.text}'`);
    await next();
});

server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        await bot.run(context);
    });
});

Adding Dialogs

This code sample demonstrates how to add dialogs to a bot using the botbuilder package. The bot prompts the user for their name and then responds with a greeting.

const { ActivityHandler, BotFrameworkAdapter, DialogSet, WaterfallDialog, TextPrompt, MemoryStorage, ConversationState } = require('botbuilder');
const restify = require('restify');

const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
    console.log(`\n${server.name} listening to ${server.url}`);
});

const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

const memoryStorage = new MemoryStorage();
const conversationState = new ConversationState(memoryStorage);
const dialogState = conversationState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);
dialogs.add(new TextPrompt('textPrompt'));
dialogs.add(new WaterfallDialog('mainDialog', [
    async (step) => {
        return await step.prompt('textPrompt', 'What is your name?');
    },
    async (step) => {
        await step.context.sendActivity(`Hello, ${step.result}!`);
        return await step.endDialog();
    }
]));

const bot = new ActivityHandler();
bot.onMessage(async (context, next) => {
    const dialogContext = await dialogs.createContext(context);
    const results = await dialogContext.continueDialog();
    if (results.status === 'empty') {
        await dialogContext.beginDialog('mainDialog');
    }
    await next();
});

server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        await bot.run(context);
    });
});

Handling Different Activity Types

This code sample demonstrates how to handle different activity types, such as messages and members being added to a conversation, using the botbuilder package.

const { ActivityHandler, BotFrameworkAdapter } = require('botbuilder');
const restify = require('restify');

const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
    console.log(`\n${server.name} listening to ${server.url}`);
});

const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

const bot = new ActivityHandler();
bot.onMessage(async (context, next) => {
    await context.sendActivity(`You said '${context.activity.text}'`);
    await next();
});
bot.onMembersAdded(async (context, next) => {
    const membersAdded = context.activity.membersAdded;
    for (let member of membersAdded) {
        if (member.id !== context.activity.recipient.id) {
            await context.sendActivity('Welcome to the bot!');
        }
    }
    await next();
});

server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        await bot.run(context);
    });
});

Other packages similar to botbuilder

Keywords

FAQs

Package last updated on 06 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc