Botbuilder Nodejs Sample View

Source: Internet
Author: User

For bot framework knowledge, refer to "Nodejs bot learning"

This article is based on the bot framework official example "Https://github.com/Microsoft/BotBuilder" written personal learning materials

Example One: Basics-waterfall(the most basic waterfall flow) (Https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/basics-waterfall)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/1-basics-waterfall

Multiple methods, the result of the previous method can be extracted in the next method, that is, the waterfall flow, run a method, and then run the next method

Save data to UserData, but the second time is not removed

Example Two: Basics-loops(the most basic loop) (Https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/basics-loops)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/2-basics-loops

Pre-defined array of problems, Bot starts directly into dialog, in dialog, extracts the problem in the array and sends it to the user to get a reply

The array does not loop through, then the next problem (replace dialog with Replacedialog) is completed, and the loop is returned to the method in which the bot starts (EndDialog () and Enddialogwithresult () can be returned)

example Three: Basics-menus(Basic menu selection) (Https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/basics-menus)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/3-basics-menus

Bot starts to enter the main menu, select different menus to enter different dialog, each dialog when completed, use the EndDialog () method to return to the main menu dialog, at this time use the Replacedialog () method to regain control

In the main menu, use EndDialog () to return, the initiative back to the bot, if you use the Endconverstation () method, will end the entire conversation

When an array parameter is added to the EndDialog () method, one of the elements is randomly selected as the default rule of the bot SDK to return

example four: Basics-naturallanguage(combined with Luis to develop an "alarm" app) (https://github.com/Microsoft/BotBuilder/tree/master/Node/ Examples/basics-naturallanguage)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/4-basics-naturalLanguage

In conjunction with Luis, in the native one object, add an "alarm" object, and set a timer, if it is the corresponding time, directly return a message to the user

Get the address of the user before adding "alarm" (this address is recorded by the user's address)

The user's address is set before the message is returned, so it can be returned to the user who added the alarm, and the other user will not be prompted to delete the alarm after sending the prompt.

Entity recognition can know the time returned and become a combination of date and time

Find the parameter from the Luis entity, and if not, let the user select the alarm that needs to be deleted

Example five: Basics-multiturn(multi-turn waterfall Flow) (Https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/basics-multiTurn)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/5-basics-multiTurn

Running an example is a failure, from the logic of the code, it should be by querying different problems, different problems are returned to the same dialog response (but the parameters of the incoming dialog is different, reply dialog will vary according to the parameters and thus have different responses)

Example Six: Basics-firstrun(middleware) (Https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/basics-firstRun)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/6-basics-firstRun

The role of middleware is to set whether or not to run the dialog repeatedly

Each message will go into the Onfindaction method, Onfindaction is the middleware

Middleware, for the first time, Userdata.version is empty, then callback, score is 1.1, it will run FirstRun Dialog,userdata.version modified to 1

Later, Userdata.version is 1, then callback, score is 0, skipping FirstRun dialog

Run effect: The first time (open the simulator first, after the recalculation) will go to FirstRun dialog, regardless of whether you enter a name, will be saved to UserData, and then each time will run the second and third line of the bot code

In the future input, if you enter help, you will always be stuck in the help

Example VII: basics-logging(log middleware) (https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/basics-logging)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/7-basics-logging

The method name of the log middleware is Botbuilder

In the middleware, if the next () method is not run, the bot itself message will not be sent out

example Eight: basics-localization(Multi-language support) (https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/ Basics-localization)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/8-basics-localization

User can choose language, expected to add JSON file in the project, and can let the user choose the language, after the user selects the language, can read the JSON file corresponding node's text

Session.preferredlocale can choose a different language

Example nine: basics-customprompt(Customize dialog box) (https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/ BASICS-CUSTOMPROMPT)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/9-basics-customPrompt

The main program waits for a reply, and when the sub-dialog runs Enddialogwithresult (), it is reactivated

The first entry to Onbegin () is bound to go through the matches () method,

If it matches, it will end, no match will run Ondefault (),

Also see if the text equals 42, equals 42 ends, does not equal 42 will emit hint text, but will not exit

Example Ten: Basics-libraries(Dialog Package into Lib) (https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/ Basics-libraries)

Https://github.com/ChenWes/bot-nodejs-sample/tree/master/10-basics-libraries

Define a library, and then export

Lib's dialog defines the event, invoked directly using Begindialog ()//to participate in using the Lib Plus dialog name

Botbuilder Nodejs Sample View

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.