1 | # Bot Builder for Node.js
|
2 | [Bot Builder for Node.js](http://docs.botframework.com/builder/node/overview/) is a powerful framework for constructing bots that can handle both freeform interactions and more guided ones where the possibilities are explicitly shown to the user. It is easy to use and models frameworks like Express & Restify to provide developers with a familiar way to write Bots.
|
3 |
|
4 | - [Installing](#installing)
|
5 | - [Basic Use](#build-a-bot)
|
6 | - [Learn More](#learn-more)
|
7 | - [Sample Apps](https://github.com/Microsoft/BotBuilder-Samples)
|
8 | - [Documentation](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0)
|
9 | - [Class Reference](https://docs.microsoft.com/en-us/javascript/api/botbuilder/)
|
10 | - [GitHub Repo](https://github.com/Microsoft/botbuilder-js)
|
11 | - [Report Issues](https://github.com/Microsoft/botbuilder-js/issues)
|
12 |
|
13 | ## Installing
|
14 | To add the latest version of this package to your bot:
|
15 |
|
16 | ```bash
|
17 | npm install --save botbuilder
|
18 | ```
|
19 |
|
20 | #### Use the Daily Build
|
21 |
|
22 | To get access to the daily builds of this library, configure npm to use the MyGet feed before installing.
|
23 |
|
24 | ```bash
|
25 | npm config set registry https://botbuilder.myget.org/F/botbuilder-v4-js-daily/npm/
|
26 | ```
|
27 |
|
28 | To reset the registry in order to get the latest published version, run:
|
29 | ```bash
|
30 | npm config set registry https://registry.npmjs.org/
|
31 | ```
|
32 |
|
33 | ## What's included?
|
34 |
|
35 | Bot Builder has everything you need to run a bot on almost any bot platform like the [Microsoft Bot Framework](http://botframework.com), [Skype](http://skype.com), and [Slack](http://slack.com). The core library will get your bot online and chatting.
|
36 | Then, extend and connect your Bot Builder app with these plugins:
|
37 |
|
38 | | Plugin | Description
|
39 | |--- |---
|
40 | | [botbuilder-dialogs](https://github.com/microsoft/botbuilder-js/tree/main/libraries/botbuilder-dialogs/README.md) | Powerful dialog system with dialogs that are isolated and composable, and built-in prompts for simple things like Yes/No, strings, numbers, enumerations.
|
41 | | [botbuilder-ai](https://github.com/microsoft/botbuilder-js/tree/main/libraries/botbuilder-dialogs/README.md) | Utilize powerful AI frameworks like [LUIS](https://www.luis.ai) and [QnA Maker](https://www.qnamaker.ai).
|
42 | | [botbuilder-azure](https://github.com/microsoft/botbuilder-js/tree/main/libraries/botbuilder-azure/README.md) | Incorporate Azure services like Cosmos DB and Blob Storage into your bot.
|
43 |
|
44 | ## Build a bot
|
45 | [Read the quickstart guide](https://docs.microsoft.com/en-us/azure/bot-service/javascript/bot-builder-javascript-quickstart?view=azure-bot-service-4.0)
|
46 | that will walk you through setting up your Bot Builder app so that you've got a well structured project and
|
47 | all of the tools necessary to develop and extend your bot.
|
48 |
|
49 | ### Start from scratch
|
50 | Create a folder for your bot, cd into it, and run npm init.
|
51 |
|
52 | ```
|
53 | npm init
|
54 | ```
|
55 |
|
56 | Get the BotBuilder and Restify modules using npm.
|
57 |
|
58 | ```
|
59 | npm install --save botbuilder
|
60 | npm install --save restify
|
61 | ```
|
62 |
|
63 | Create a file named bot.js and get your bot online with a few lines of code.
|
64 |
|
65 | ```javascript
|
66 | const restify = require('restify');
|
67 | const botbuilder = require('botbuilder');
|
68 |
|
69 | // Create bot adapter, which defines how the bot sends and receives messages.
|
70 | var adapter = new botbuilder.BotFrameworkAdapter({
|
71 | appId: process.env.MicrosoftAppId,
|
72 | appPassword: process.env.MicrosoftAppPassword
|
73 | });
|
74 |
|
75 | // Create HTTP server.
|
76 | let server = restify.createServer();
|
77 | server.listen(process.env.port || process.env.PORT || 3978, function () {
|
78 | console.log(`\n${server.name} listening to ${server.url}`);
|
79 | console.log(`\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator`);
|
80 | });
|
81 |
|
82 | // Listen for incoming requests at /api/messages.
|
83 | server.post('/api/messages', (req, res) => {
|
84 | // Use the adapter to process the incoming web request into a TurnContext object.
|
85 | adapter.processActivity(req, res, async (turnContext) => {
|
86 | // Do something with this incoming activity!
|
87 | if (turnContext.activity.type === 'message') {
|
88 | // Get the user's text
|
89 | const utterance = turnContext.activity.text;
|
90 |
|
91 | // send a reply
|
92 | await turnContext.sendActivity(`I heard you say ${ utterance }`);
|
93 | }
|
94 | });
|
95 | });
|
96 | ```
|
97 |
|
98 | ## Test your bot
|
99 | Use the [Bot Framework Emulator](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-debug-emulator?view=azure-bot-service-4.0) to test your bot on localhost.
|
100 |
|
101 | Install the emulator from [here](https://aka.ms/botframework-emulator) and then start your bot in a console window.
|
102 |
|
103 | Start the emulator and say "hello" to your bot.
|
104 |
|
105 | ## Publish your bot
|
106 | Deploy your bot to the cloud and then [register it](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-quickstart?view=azure-bot-service-4.0) with the Azure Bot Service.
|
107 |
|
108 | ## Learn More
|
109 | Learn how to build great bots.
|
110 |
|
111 | * [Core Concepts Guide](http://docs.botframework.com/builder/node/guides/core-concepts/)
|
112 | * [Bot Builder for Node.js Reference](https://docs.microsoft.com/en-us/javascript/api/botbuilder/)
|