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

C# templates

The current bot samples use .NET Core 3.1 templates.

.NET Core Templates will help you to quickly build new conversational AI bots using Bot Framework v4. As of May 2020, these templates and the code they generate require .NET Core 3.1 or later.

To install the Bot Framework templates:

  1. Open a console window.

  2. Download and install .NET Core SDK download version 3.1 or later.

  3. You can use this command to determine which versions of the .NET Core command-line interface are installed.

    dotnet --version
    
  4. Install the three Bot Framework C# templates: the echo, core, and empty bot templates.

    dotnet new -i Microsoft.Bot.Framework.CSharp.EchoBot
    dotnet new -i Microsoft.Bot.Framework.CSharp.CoreBot
    dotnet new -i Microsoft.Bot.Framework.CSharp.EmptyBot
    
  5. Verify the templates have been installed correctly.

    dotnet new --list
    

Note

The steps above install all three Bot Framework templates. You don't need to install all the templates and can install just the ones you'll use. This article makes use of the echo bot template.

Create a bot

  1. Open a new terminal window.

  2. Go to the directory in which you want to create your bot project.

  3. Create a new echo bot project using the following command. Replace <your-bot-name> with the name to use for your bot project.

    dotnet new echobot -n <your-bot-name>
    

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

Start your bot

From a command prompt or terminal:

  1. Change directories to the project folder for your bot.

  2. Use dotnet run to start the bot.

    dotnet run
    
  3. This command builds the application and deploys it to localhost.

The application's default web page won't display, but 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).