-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
98 lines (83 loc) · 3.4 KB
/
app.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
const restify = require('restify');
const builder = require('botbuilder');
require('dotenv-extended').load();
const commands = require('./app/recognizers/commands');
//require dialogs
const dialog = {
greet: require('./app/dialogs/greet'),
contactHuman: require('./app/dialogs/contactHuman'),
locationAvailability: require('./app/dialogs/locationAvailability'),
trackOrder: require('./app/dialogs/trackOrder'),
sizeAndPriceGuide: require('./app/dialogs/sizeAndPriceGuide'),
sendPost: require('./app/dialogs/sendPost'),
convertCurrency: require('./app/dialogs/convertCurrency'),
thankBack: require('./app/dialogs/thankBack'),
bye: require('./app/dialogs/bye'),
showServices: require('./app/dialogs/showServices'),
rateTimeQuote: require('./app/dialogs/rateTimeQuote'),
platformFix: require('./app/dialogs/platformFix')
};
// Create chat connector for communicating with the Bot Framework Service
const connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
const bot = new builder.UniversalBot(connector, {
persistConversationData: true
});
// var model = 'https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/67f56d58-9a3e-49bc-83c6-7132fc485096?subscription-key=7928eebc0f3d43e58de298827a21b73f&timezoneOffset=0&verbose=true';
var intents = new builder.IntentDialog({
recognizers: [
commands,
new builder.LuisRecognizer(process.env.LUIS_MODEL_URL)
],
intentThreshold: 0.2,
recognizeOrder: builder.RecognizeOrder.series
});
intents.matches('greet', '/greet')
intents.matches('contactHuman', '/contactHuman')
intents.matches('trackOrder', '/trackOrder')
intents.matches('locationAvailability', '/locationAvailability')
intents.matches('sizeAndPriceGuide', '/sizeAndPriceGuide')
intents.matches('sendPost', '/sendPost')
intents.matches('convertCurrency', '/convertCurrency')
intents.matches('thankBack', '/thankBack')
intents.matches('bye', '/bye')
intents.matches('showServices', '/showServices')
intents.matches('rateTimeQuote', '/rateTimeQuote')
intents.matches('platformFix', '/platformFix')
intents.onDefault('/confused')
bot.dialog('/', intents);
dialog.greet(bot);
dialog.contactHuman(bot);
dialog.trackOrder(bot);
dialog.locationAvailability(bot, builder);
dialog.sizeAndPriceGuide(bot);
dialog.sendPost(bot);
dialog.convertCurrency(bot);
dialog.thankBack(bot);
dialog.bye(bot);
dialog.showServices(bot);
dialog.rateTimeQuote(bot);
dialog.platformFix(bot);
bot.dialog('/confused', [
function (session, args, next) {
if (session.message.text.trim()) {
session.endDialog('Sorry, I didn\'t understand you or maybe just lost track of our conversation');
} else {
session.endDialog();
}
}
]);
// Setup Restify Server
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
//get request for webchat
server.get(/.*/, restify.plugins.serveStatic({
'directory': '.',
'default': 'index.html'
}));