We are going to export new object of this form. Export function will take builder object as parameter and call constructor of applesOrder with builder parameter.
Now, we will modify
starter.js to call
applesOrderForm.
- var restify = require('restify');
- var builder = require('botbuilder');
-
- var server = restify.createServer();
- server.listen(process.env.port || process.env.PORT || 3979, function()
- {
- console.log('Bot Application is avalable at (%s)', server.url);
- });
-
- var connector = new builder.ChatConnector({
- appId: process.env.MICROSOFT_APP_ID,
- appPassword: process.env.MICROSOFT_APP_PASSWORD
- });
-
- server.post('/api/order_your_grocery', connector.listen());
-
- var applesOrder = require('./applesOrderForm.js')(builder);
-
- var bot = new builder.UniversalBot(connector, applesOrder.form);
We will call a requirement for applesOrderForm.js as builder object as parameter. Then, the bot object is created calling UniversalBot constructor with applesOrder.form as second parameter. When user starts conversation with bot these functions will be called in sequence, mentioned while defining that array.
Let's debug the app. Open node.js command prompt and run
node starter.js command. It will host the application on port 3979 and start listening. Now launch bot emulator app. Put URL as
http://localhost:3979/api/order_your_grocery to connect emulator with bot application. Keep App ID and App Password blank, click on connect. Start a conversation with bot.
welcomePrompt
It will greet the user with a welcome message and prompt for the name of the user. Wait for user input; after that, call next function.
numberOfApplesPrompt
Get the user name from results parameter and save it to dialogData of the session. Prompt for the number of apples. Wait for user input which should be of type
number, after that call next function.
userAddressPrompt
Get the number of apples from results parameter and save it to dialogData of the session. Prompt for the address for delivery. Wait for user input, after that call next function.
deliveryTimePrompt
Get the address from results parameter and save it to dialogData of the session. Prompt for the time for delivery. Wait for user input which should be of type
DateTime, after that call next function.
goodByePrompt
Get the time for delivery from results parameter and save it to dialogData of the session. Say goodbye to the user.
This is how we can manage conversation using default (root) dialog. In the next article, we will discuss managing conversations with multiple dialogs. Till then, keep developing bots!