Create a bot with the Bot Framework SDK for JavaScript

APPLIES TO: SDK v4

This article shows you how to build a bot by using the Yeoman Bot Builder generator and the Bot Framework SDK for JavaScript, and then how to test it with the Bot Framework Emulator.

Creating a bot with Azure Bot Service and creating a bot locally are independent, parallel ways to create a bot.

Prerequisites

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 are on Windows. Read the above note.
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 additional code to test your bot.

Note

If you create a Core bot, you'll need a LUIS language model. (You can create a language model at luis.ai). After creating the model, update the configuration file.

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. Click Open Bot on the Emulator's Welcome tab.

  3. Enter your bot's URL, which is the URL of the local port, with /api/messages added to the path, typically http://localhost:3978/api/messages.

    open a bot screen cs

  4. Then click Connect.

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

    Emulator running cs

Additional resources

See tunneling (ngrok) for how to connect to a bot hosted remotely.

Next steps