Create a bot with the Bot Framework SDK for JavaScript
Note
This topic is for the latest release of the SDK (v4). You can find content for the older version of the SDK (v3) here.
This quickstart walks you through building a single bot by using the Yeoman Bot Builder generator and the Bot Framework SDK for JavaScript, and then testing 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
- Visual Studio Code
- Node.js
- Yeoman, which uses a generator to create a bot for you
- git
- Bot Framework Emulator
- Knowledge of restify and asynchronous programming in JavaScript
Note
The install of Windows build tools listed below is only required if you use Windows as your developemnt 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:
npm install -g windows-build-tools
Create a bot
To create your bot and initialize its packages
Open a terminal or elevated command prompt.
If you don't already have a directory for your JavaScript bots, create one and change directories to it. (We're creating a directory for your JavaScript bots in general, even though we're only creating one bot in this tutorial.)
mkdir myJsBots cd myJsBots
Ensure your version of npm is up to date.
npm install -g npm
Next, install Yeoman and the generator for JavaScript.
npm install -g yo generator-botbuilder
Then, 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.
- Enter a name for your bot. (myChatBot)
- Enter a description. (Demonstrate the core capabilities of the Microsoft Bot Framework)
- Choose the language for your bot. (JavaScript)
- Choose the template to use. (Echo)
Thanks to the template, your project contains all of the code that's necessary to create the bot in this quickstart. You won't actually need to write any additional code.
Note
If you choose to create a Basic
bot, you'll need a LUIS language model. You can create one on luis.ai. After creating the model, update the .bot file. Your bot file should look similar to this one.
Start your bot
In a terminal or command prompt change directories to the one created for your bot, and start it with npm start
. At this point, your bot is running locally.
Start the Emulator and connect your bot
- Start the Bot Framework Emulator.
- Click the Open Bot link in the emulator "Welcome" tab.
- Select the .bot file located in the directory where you created the project.
Send a message to your bot, and the bot will respond back with a message.
Additional resources
See tunneling (ngrok) for how to connect to a bot hosted remotely.
Next steps
Feedback
Would you like to provide feedback?
Our feedback system is built on GitHub Issues. Read more on our blog.
Loading feedback...