Skip to content
This repository has been archived by the owner on Dec 19, 2021. It is now read-only.

Latest commit

 

History

History
62 lines (46 loc) · 4 KB

CHATBOT.md

File metadata and controls

62 lines (46 loc) · 4 KB

Chatbot

The scaffolding assumes you want to use the Microsoft Bot Framework and LUIS. You can read a full guide on how to build a chatbot using this generator here.

Standard Files

The chatbot scaffolding includes all the same files/structure in the boilerplate docs.
It also includes the following additions/changes:

  • src/bot.ts - This is main class. The purpose of this class is to configure the bot. It sets defaults, registers dialogs to paths, and binds intents to paths. The class provided by the scaffolding assumes that you are planning on using LUIS for your intent engine.
  • src/config.ts - This file is used for configuration of the app.
  • src/console.ts - This script starts the bot for interaction over the console. This would only happen in dev scenarios.
  • src/server.ts - This script starts the bot for interaction using a web server. The scaffolding chooses restify (which is very similar to express).
  • src/dialogs/dialog-base.ts - All dialogs will inherit from this class, it provides the base property and method that we we use to bind dialogs to paths.
  • src/dialogs/sample.ts - This is an extremely simple dialog that tells the chatter what their favorite food is.
  • test/unit/bot-tests.ts - This includes unit tests for bot.ts.

Building

The chatbot leverages the same gulp tasks defined in the boilerplate docs.

Testing

The chatbot leverages the same testing configuration defined in the boilerplate docs.
The scaffolding provides these tests for the bot.ts. These tests provide a good example on how to use sinon stubs with mocha and chai.

Run

You can run the bot 2 ways:

  • Server Mode - After tranpsiling run node src/server.js, this will allow you to interact with the bot using the API.
  • Console Mode - After tranpsiling run node src/console.js, this will allow you to interact with the bot using your local console.

The scaffolding produces a runable bot, to run it:

  1. Transpile the code - npm run build
  2. Start the bot on the console - node src/console.js
  3. Using natural language tell the bot what your favorite food is (i.e. "My favorite food is ice cream" or "I love apples")
Additional notes about building on the scaffolding

A few general notes about building on the scaffolding.

  • In the real world you will probably have some additional classes to connect to services, I would recommend creating a folder under src named data-access to hold these classes
  • Manage your listen port in config.ts
  • I elected to put dialog strings in config.ts, as your bot grows you may want to move these out into a separate config file. You could also put the strings in line but that feels wrong to me.
  • This server listens on http, to register your bot on the framework you need an https endpoint with a trusted cert, an easy way to do this is put your bot behind a proxy using AWS API gateway