Create a bot with the Bot Framework SDK

APPLIES TO: SDK v4

This article describes how to build your first bot with the Bot Framework SDK for C#, Java, JavaScript or Python, and how to test your bot with the Bot Framework Emulator.

Creating your first bot doesn't require an Azure subscription or an Azure AI Bot Service resource. This quickstart focuses on creating your first bot locally. If you'd like to learn how to create a bot in Azure, see Create an Azure Bot resource.

Note

The Bot Framework JavaScript, C#, and Python SDKs will continue to be supported, however, the Java SDK is being retired with final long-term support ending in November 2023.

Existing bots built with the Java SDK will continue to function.

For new bot building, consider using Microsoft Copilot Studio and read about choosing the right copilot solution.

For more information, see The future of bot building.

Prerequisites

JavaScript and TypeScript templates

To install Yeoman and the Yeoman generator for Bot Framework v4:

  1. Open a terminal or elevated command prompt.

  2. Switch to the directory for your JavaScript bots. Create it first if you don't already have one.

    mkdir myJsBots
    cd myJsBots
    
  3. Make sure you have the latest versions of npm and Yeoman.

    npm install -g npm
    npm install -g yo
    
  4. Install the Yeoman generator. Yeoman is a tool for creating applications. For more information, see yeoman.io.

    npm install -g generator-botbuilder
    

    Note

    The install of Windows build tools listed below is only required if you use Windows as your development operating system. For some installations, the install step for restify is giving an error related to node-gyp. If this is the case you can try running this command with elevated permissions. This call may also hang without exiting if Python is already installed on your system:

    Only run this command if you're on Windows.

    npm install -g windows-build-tools
    

Create a bot

  1. Use the generator to create an echo bot.

    yo botbuilder
    

    Yeoman prompts you for some information with which to create your bot. For this tutorial, use the default values.

    ? What's the name of your bot? my-chat-bot
    ? What will your bot do? Demonstrate the core capabilities of the Microsoft Bot Framework
    ? What programming language do you want to use? JavaScript
    ? Which template would you like to start with? Echo Bot - https://aka.ms/bot-template-echo
    ? Looking good.  Shall I go ahead and create your new bot? Yes
    

Thanks to the template, your project contains all the code that's necessary to create the bot in this quickstart. You don't need any other code to test your bot.

Start your bot

In a terminal or command prompt change directories to the one created for your bot, and start it with npm start.

cd my-chat-bot
npm start

At this point, your bot is running locally on port 3978.

Start the Emulator and connect your bot

  1. Start the Bot Framework Emulator.

  2. Select Open Bot on the Emulator's Welcome tab.

  3. Enter your bot's URL, which is your local host and port, with /api/messages added to the path. The address is usually: http://localhost:3978/api/messages.

    open a bot

  4. Then select Connect.

    Send a message to your bot, and the bot will respond back.

    echo message

Next steps

  • For information about how to debug using Visual Studio or Visual Studio Code and the Bot Framework Emulator, see Debug a bot.
  • For information about devtunnel, see Tunneling (devtunnel).