-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitial_bot.js
109 lines (96 loc) · 4.21 KB
/
initial_bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// let restify = require('restify');
const builder = require('botbuilder');
const BuyItemArr = require('./dialogs/BuyItem.js');
const ContactInfoArr = require('./dialogs/ContactInfo.js');
const FindProductsArr = require('./dialogs/FindProducts.js');
// let server = restify.createServer();
// server.listen(process.env.port || process.env.PORT || 3978, function () {
// console.log(`\n${server.name} listening to ${server.url}.\n`);
// });
//
// let connector = new builder.ChatConnector({
// appId: process.env.MICROSOFT_APP_ID,
// appPassword: process.env.MICROSOFT_APP_PASSWORD
// });
let connector = new builder.ConsoleConnector().listen();
let model = 'https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/cf50007f-d18f-483b-9c5c-98fde2dd4160?subscription-key=0620fb642aa145b6a9bf5a5023b0d3f5';
let recognizer = new builder.LuisRecognizer(model);
let dialog = new builder.IntentDialog({ recognizers: [recognizer] });
// __IntentDialog__ Information:
// https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.intentdialog.html
let bot = new builder.UniversalBot(connector);
let BuyItem = BuyItemArr(builder, bot);
let ContactInfo = ContactInfoArr(builder, bot);
let FindProducts = FindProductsArr(builder, bot);
bot.dialog('/', dialog);
dialog.matches('ContactInfo', function (session, results) {
//Through having the LuisRecognizer and IntentDialog match to this; we're able to create a dialog which can be called in methods such as session.replaceDialog, and session.beingDialog
session.beginDialog('/ContactInfo', results);
});
bot.dialog('/ContactInfo', ContactInfo);
dialog.matches('BuyItem',
function(session, results){
session.beginDialog('/BuyItem', results);
}
);
bot.dialog('/BuyItem', BuyItem);
dialog.matches('FindProducts',
function(session, results){
session.beginDialog('/FindProducts');
}
);
bot.dialog('/FindProducts', FindProducts);
// dialog.matches('GetShippingAddress', [
// function (session, args, next) {
//
// },
// //end GetShippingAddress function 1
// ]);
// bot.dialog('/FindProducts', [
// function (session, args, next) {
// // let intent = args.intent;
// let product = builder.EntityRecognizer.findEntity(args.entities, 'inventory.product.name');
// let quantity = builder.EntityRecognizer.findEntity(args.entities, 'inventory.product.quantity');
// let iQuery = session.dialogData.iQuery = {
// product: product ? product.entity : null,
// quantity: quantity ? quantity.entity : null
// };
// if(!iQuery.product) {
// builder.Prompts.text(session, "I'm sorry but I don't understand, would you please restate the item you are looking for?");
// } else {
// next();
// }
// },
// //end FindProducts function 1
// function (session, results, next) {
// let iQuery = session.dialogData.iQuery;
// if(results.response) {
// iQuery.product = results.response;
// }
// console.log("line 155, iQuery object", session.dialogData.iQuery);
// if(iQuery.quantity){
// builder.Prompts.text(session, `So you are inquiring about ${iQuery.product}, is this correct? yes/no`);
// } else {
// // session.dialogStack();
// builder.Prompts.text(session, "How many are you looking for?");
// }
// },
// //end FindProducts function 2
// function (session, results, next) {
// let iQuery = session.dialogData.iQuery;
// if(iQuery.quantity) {
// if(results.response == "yes") {
// let randNum = Math.floor(Math.random() * (100 - 1) + 1);
// session.dialogData.iQuery = {inventory: randNum};
// session.endDialog(`We have ${randNum} ${iQuery.product}`);
// }
// if(results.response == "no") {
// session.replaceDialog('/FindProducts');
// }
// } else {
// iQuery.quantity = results.response;
// console.log(`Line 175, iQuery Object`, iQuery);
// }
// }
// ]);
dialog.onDefault(builder.DialogAction.send("I'm sorry I didn't understand. I only assist in shopping."));