Convert Figma logo to code with AI

microsoft logoBotBuilder-Samples

Welcome to the Bot Framework samples repository. Here you will find task-focused samples in C#, JavaScript/TypeScript, and Python to help you get started with the Bot Framework SDK!

4,363
4,871
4,363
68

Top Related Projects

12,494

The open-source hub to build & deploy GPT/LLM Agents ⚡️

11,468

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.

VS Code in the browser

43,143

Create agents that monitor and act on your behalf. Your agents are standing by!

Quick Overview

BotBuilder-Samples is a GitHub repository maintained by Microsoft that provides a collection of sample projects and resources for building conversational bots using the Bot Framework SDK. It includes examples in multiple programming languages, demonstrating various bot capabilities and integration with different channels and services.

Pros

  • Comprehensive collection of samples covering a wide range of bot scenarios and features
  • Supports multiple programming languages (C#, JavaScript, Python, Java)
  • Regularly updated with new samples and improvements
  • Includes examples for integration with popular services like LUIS, QnA Maker, and Azure Cognitive Services

Cons

  • Some samples may become outdated as the Bot Framework SDK evolves
  • Documentation within individual samples can be inconsistent in quality and depth
  • May require additional setup and configuration for certain samples (e.g., Azure resources)
  • Learning curve can be steep for beginners due to the complexity of some advanced samples

Code Examples

Here are a few short code examples from the repository:

  1. Creating a simple echo bot in C#:
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
    private readonly IBotFrameworkHttpAdapter _adapter;
    private readonly IBot _bot;

    public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
    {
        _adapter = adapter;
        _bot = bot;
    }

    [HttpPost, HttpGet]
    public async Task PostAsync()
    {
        await _adapter.ProcessAsync(Request, Response, _bot);
    }
}
  1. Handling user input in JavaScript:
class EchoBot extends ActivityHandler {
    constructor() {
        super();
        this.onMessage(async (context, next) => {
            const replyText = `Echo: ${ context.activity.text }`;
            await context.sendActivity(MessageFactory.text(replyText, replyText));
            await next();
        });
    }
}
  1. Integrating LUIS for natural language understanding in Python:
class LuisBot(ActivityHandler):
    def __init__(self, config: DefaultConfig):
        self.luis_app_id = config.LUIS_APP_ID
        self.luis_api_key = config.LUIS_API_KEY
        self.luis_api_host_name = config.LUIS_API_HOST_NAME

    async def on_message_activity(self, turn_context: TurnContext):
        luis_result = await LuisHelper.execute_luis_query(
            self.luis_app_id, self.luis_api_key, self.luis_api_host_name, turn_context
        )
        await turn_context.send_activity(f"Top intent: {luis_result.top_intent().intent}")

Getting Started

To get started with BotBuilder-Samples:

  1. Clone the repository: git clone https://github.com/microsoft/BotBuilder-Samples.git
  2. Navigate to the desired sample directory
  3. Follow the README instructions for the specific sample
  4. Install dependencies (e.g., npm install for JavaScript, pip install -r requirements.txt for Python)
  5. Run the sample locally (e.g., dotnet run for C#, node index.js for JavaScript)
  6. Test the bot using the Bot Framework Emulator or deploy it to Azure for channel integration

Competitor Comparisons

12,494

The open-source hub to build & deploy GPT/LLM Agents ⚡️

Pros of Botpress

  • Open-source, self-hosted platform with a visual flow builder
  • Supports multiple languages and NLU integrations
  • Active community and extensive documentation

Cons of Botpress

  • Steeper learning curve for developers new to the platform
  • Limited built-in integrations compared to BotBuilder-Samples

Code Comparison

Botpress (JavaScript):

bp.hear(/hello/i, (event, next) => {
  bp.messaging.sendText(event.channel, 'Hello, human!')
})

BotBuilder-Samples (JavaScript):

bot.onMessage(async (context, next) => {
  if (context.activity.text.toLowerCase() === 'hello') {
    await context.sendActivity('Hello, human!');
  }
  await next();
});

Both examples show how to respond to a "hello" message, but Botpress uses a more concise syntax with its bp.hear method, while BotBuilder-Samples uses the more verbose bot.onMessage approach.

BotBuilder-Samples offers a wider range of language samples and integration examples, making it easier for developers to get started with various platforms. However, Botpress provides a more comprehensive, all-in-one solution for building and managing chatbots, including a visual flow builder and built-in NLU capabilities.

11,468

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.

Pros of Botkit

  • More platform-agnostic, supporting a wider range of messaging platforms
  • Simpler and more intuitive API for beginners
  • Active community with extensive plugin ecosystem

Cons of Botkit

  • Less integrated with Azure and Microsoft services
  • Fewer enterprise-level features and scalability options
  • Limited support for advanced natural language processing

Code Comparison

Botkit example:

controller.hears(['hello'], 'direct_message', function(bot, message) {
    bot.reply(message, 'Hello yourself!');
});

BotBuilder-Samples example:

class EchoBot extends ActivityHandler {
    constructor() {
        super();
        this.onMessage(async (context, next) => {
            await context.sendActivity(`You said "${context.activity.text}"`);
            await next();
        });
    }
}

Key Differences

  • Botkit uses a more event-driven approach, while BotBuilder-Samples follows a more object-oriented pattern
  • BotBuilder-Samples provides deeper integration with Microsoft's Bot Framework
  • Botkit offers a more straightforward setup for simple bots, while BotBuilder-Samples provides more flexibility for complex scenarios

Use Cases

  • Botkit: Ideal for small to medium-sized projects, multi-platform bots, and rapid prototyping
  • BotBuilder-Samples: Better suited for enterprise-level applications, Azure integration, and advanced AI capabilities

VS Code in the browser

Pros of code-server

  • Enables full VS Code experience in a browser, allowing remote development
  • Supports a wide range of programming languages and extensions
  • Can be self-hosted for enhanced security and customization

Cons of code-server

  • Requires more setup and maintenance compared to BotBuilder-Samples
  • May have higher resource requirements for hosting
  • Limited to VS Code functionality, while BotBuilder-Samples offers bot-specific tools

Code Comparison

BotBuilder-Samples (JavaScript):

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

class EchoBot extends ActivityHandler {
    constructor() {
        super();
        this.onMessage(async (context, next) => {
            await context.sendActivity(MessageFactory.text(`Echo: ${context.activity.text}`));
            await next();
        });
    }
}

code-server (Server Configuration):

module.exports = {
  bind: '0.0.0.0',
  auth: 'password',
  password: 'your-password',
  cert: false,
  port: 8080,
  'proxy-domain': 'your-domain.com'
};

While BotBuilder-Samples focuses on bot development with specific examples, code-server provides a broader development environment that can be used for various projects, including bot development. The choice between the two depends on the specific needs of the developer and the project requirements.

43,143

Create agents that monitor and act on your behalf. Your agents are standing by!

Pros of Huginn

  • More versatile and can be used for a wider range of automation tasks beyond just chatbots
  • Offers a user-friendly web interface for creating and managing agents
  • Has a large community-driven library of pre-built agents for various tasks

Cons of Huginn

  • Steeper learning curve for non-technical users
  • Less focused on chatbot development specifically
  • May require more setup and configuration compared to BotBuilder-Samples

Code Comparison

Huginn (Ruby):

class Agents::WeatherAgent < Agent
  def check
    LatchKey.new(options['api_key']).get do |forecast|
      create_event :payload => forecast
    end
  end
end

BotBuilder-Samples (JavaScript):

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

class EchoBot extends ActivityHandler {
    constructor() {
        super();
        this.onMessage(async (context, next) => {
            await context.sendActivity(MessageFactory.text(`Echo: ${context.activity.text}`));
            await next();
        });
    }
}

The code snippets demonstrate the different focus areas of each project. Huginn's example shows an agent for fetching weather data, while BotBuilder-Samples' code illustrates a simple echo bot implementation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Bot Framework Samples

Click here to find out what's new with Bot Framework

Overview

This branch contains samples for the released version of the Microsoft Bot Framework V4 SDK for .NET, JS and Python. If you need samples for the Bot Framework V3 SDK, go here.

Getting the samples

To use the samples, clone this GitHub repository using Git.

    git clone https://github.com/Microsoft/BotBuilder-Samples.git
    cd BotBuilder-Samples

Sample lists

Samples are designed to illustrate functionality you'll need to implement to build great bots!

Bot essentials

Sample NameDescription.NETJavaScriptPythonJava
2Echo botDemonstrates how to receive and send messages..NET CoreJavaScript, TypeScriptPythonJava
3Welcome userIntroduces activity types and provides a welcome message on conversation update activity..NET CoreJavaScript, TypeScriptPythonJava
5Multi turn promptsDemonstrates how to use waterfall dialog, prompts, and component dialog to create a simple interaction that asks the user for name, age, and prints back that information..NET CoreJavaScript, TypeScriptPythonJava
6Using cardsIntroduces all card types including thumbnail, audio, media etc. Builds on Welcoming user + multi-prompt bot by presenting a card with buttons in welcome message that route to appropriate dialog..NET CoreJavaScript, TypeScriptPythonJava
7Adaptive cardsDemonstrates how the multi-turn dialog can use a card to get user input for name and age..NET CoreJavaScriptPythonJava
8Suggested actionsDemonstrates how to enable your bot to present buttons that the user can tap to provide input..NET CoreJavaScriptPythonJava
13Core botCore bot shows how to use cards, dialog, and Language Understanding (LUIS)..NET Core, .NET WebJavaScript, TypeScriptPythonJava
15Handling attachmentsDemonstrates how to listen for/handle user provided attachments..NET CoreJavaScriptPythonJava
40TIMEX resolutionDemonstrates various ways to parse and manipulate the TIMEX expressions you get from LUIS and the DateTimeRecognizer used by the DateTimePrompt..NET CoreJavaScriptPythonJava
43Complex dialogsDemonstrates different ways for composing dialogs..NET CoreJavaScriptPythonJava
45State managementDemonstrates how to use state management and storage objects to manage and persist state..NET CoreJavaScriptPythonJava

Advanced bots

Sample NameDescription.NETJavaScriptPythonJava
1Console echo botIntroduces the concept of adapter and demonstrates a simple echo bot on console adapter and how to send a reply and access the incoming message..NET CoreJavaScript, TypeScriptPython
1Browser echo botDemonstrates how to host a bot in the browser using Web Chat and a custom Web Chat Adapter.ECMAScript 6
16Proactive messagesDemonstrates how to send proactive messages to users..NET CoreJavaScript, TypeScriptPythonJava
17Multilingual botUsing translate middleware to support a multi-lingual bot. Demonstrates custom middleware..NET CoreJavaScriptPythonJava
19Custom dialogsDemonstrates complex conversation flow using the Dialogs library..NET CoreJavaScriptPythonJava
21Application InsightsDemonstrates how to add telemetry logging to your bot, storing telemetry within Application Insights..NET CoreJavaScriptJava
23Facebook eventsIntegrate and consume Facebook specific payloads, such as post-backs, quick replies and opt-in events..NET CoreJavaScriptPythonJava
42Scale outDemonstrates how you can build your own state solution from the ground up that supports scaled out deployment with ETag based optimistic locking..NET CorePythonJava
44Basic custom promptsDemonstrates how to implement your own basic prompts to ask the user for information..NET CoreJavaScriptPythonJava
47Inspection middlewareDemonstrates how to use middleware to allow the Bot Framework Emulator to debug traffic into and out of the bot in addition to looking at the current state of the bot.[.NET Core][cs#47]JavaScriptPythonJava
70Styling webchatThis sample shows how to create a web page with custom Web Chat component.ECMAScript 6

Authentication samples

Sample NameDescription.NETJavaScriptPythonJava
18OAuth authenticationBot that demonstrates how to integrate OAuth providers..NET CoreJavaScriptPythonJava
24MSGraph authenticationDemonstrates bot authentication capabilities of Azure Bot Service. Demonstrates utilizing the Microsoft Graph API to retrieve data about the user..NET CoreJavaScriptPythonJava
46Teams authenticationDemonstrates how to use authentication for a bot running in Microsoft Teams..NET CoreJavaScriptPythonJava
84Certificate authenticationDemonstrates how to use Certificates to authenticate the bot.NET CoreJavaScript
85Subject name/issuer authenticationDemonstrates how to use the subject name/issuer authentication in a bot.NET CoreJavaScript

Custom question answering samples

Sample NameDescription.NETJavaScriptPythonJava
12Custom question answering (simple)Demonstrates how to use Custom question answering to have simple single-turn conversations.NET CoreJavaScript
48Custom question answering (advanced)Demonstrates how to integrate Multiturn and Active learning in a Custom question answering bot.NET CoreJavaScript

Teams samples

Sample NameDescription.NETJavaScriptPythonJava
25Message ReactionsDemonstrates how to create a simple bot that responds to Message Reactions.NET CoreJavaScriptJava
46AuthenticationDemonstrates how to use authentication for a bot running in Microsoft Teams..NET CoreJavaScriptPythonJava
50Messaging extensions - searchA Messaging Extension that accepts search requests and returns results..NET CoreJavaScriptPythonJava
51Messaging extensions - actionA Messaging Extension that accepts parameters and returns a card. Also, how to receive a forwarded message as a parameter in a Messaging Extension..NET CoreJavaScriptPythonJava
52Messaging extensions - auth and configA Messaging Extension that has a configuration page, accepts search requests and returns results after the user has signed in..NET CoreJavaScript
53Messaging extensions - action previewDemonstrates how to create a Preview and Edit flow for a Messaging Extension..NET CoreJavaScriptPythonJava
54Task moduleDemonstrates how to retrieve a Task Module, and values from cards in the Task Module, for a Messaging Extension..NET CoreJavaScriptPythonJava
55Link unfurlingA Messaging Extension that performs link unfurling..NET Core)JavaScriptPythonJava
56File uploadDemonstrates how to obtain file consent, and upload files to Teams from a bot. Also, how to receive a file sent to a bot..NET CoreJavaScriptPythonJava
57Conversation botDemonstrates various features of bots on Teams: message all members in a Team or Channel, @mention a user from a bot, update previously sent messages, etc..NET CoreJavaScriptPythonJava
58Start new thread in a channelDemonstrates creating a new thread in a channel..NET CoreJavaScriptPythonJava

Skills samples

Sample NameDescription.NETJavaScriptPythonJava
80Skills - simple bot to botThis sample shows how to connect a skill to a skill consumer..NET CoreJavaScriptPythonJava
81Skills - skill dialogThis sample shows how to connect a skill to a skill dialog consumer..NET CoreJavaScriptPythonJava
82Skills - SSO with CloudAdapterThis sample shows how use SSO with skills and CloudAdapter..NET CoreJavaScriptNANA

Experimental / preview samples

A collection of experimental samples exist, intended to provide samples for features currently in preview or as a way to solicit feedback on a given design, approach, or technology being considered by the Bot Framework Team.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Reporting security issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

Copyright (c) Microsoft Corporation. All rights reserved.