-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
143 lines (121 loc) · 4.14 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var restify = require('restify');
var builder = require('botbuilder');
var config = require('./bot-config.json');
var http = require('http');
//=================================================
// Bot Setup
//=================================================
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('listening to %s', server.url);
});
var connector = new builder.ChatConnector({
appId: config.AppCredentials.app_id,
appPassword: config.AppCredentials.app_password
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
var model = 'https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/25ca0874-22b3-4b42-b9f9-e6091ce8f0e2?subscription-key=0b8f0e68b07a45f9a45206492fb9f17d&verbose=true&timezoneOffset=0&spellCheck=false';
var recognizer = new builder.LuisRecognizer(model);
var intents = new builder.IntentDialog({ recognizers: [recognizer] });
//=================================================
// Bot Dialogs
//=================================================
var hourInDay = new Date().getHours();
var greetingTimeMessage;
var goodbyeTime;
if (hourInDay >= 0 && hourInDay < 12) {
greetingTimeMessage = 'Good morning';
goodbyeTime = 'morning';
} else if (hourInDay >= 12 && hourInDay < 17) {
greetingTimeMessage = 'Good afternoon';
goodbyeTime = 'afternoon';
} else if (hourInDay >= 17 && hourInDay < 24) {
greetingTimeMessage = 'Good evening';
goodbyeTime = 'evening';
}
bot.dialog('/', intents);
intents.matches('How is Assistant', [
function (session) {
session.send('My name is Norma and I am Mr Tsilivis personal assistant.');
if (!session.userData.name) {
session.beginDialog('/profile');
}
else {
session.send('How can I help you %s', session.userData.name);
session.endDialog();
}
}
]);
intents.matches('Nicks Age', [
function (session) {
session.send('Mr Tsilivis is 29 years old. Anythin else ?');
}
]);
intents.matches('Take a note', [
function (session) {
session.send('Thank you I will notify Nick');
}
]);
intents.matches('Where is nick', [
function (session) {
session.send('I am sorry but Nick is not here. Thats all I can say :) ');
}
]);
intents.matches('Send Boss CV', [
function (session) {
session.send('I can send you Mr Tsilivis info in your email.');
// session.beginDialog('/email');
if (!session.userData.email) {
session.beginDialog('/email');
}
else {
session.send('Done!! Sent it at: %s. Anything else ?', session.userData.email);
}
}
]);
intents.matches('Leaving', [
function (session) {
session.send('Thank you very much. Have a nice %s :D', goodbyeTime);
}
]);
intents.onDefault([
function (session, args, next) {
if(!session.userData.name) {
session.beginDialog('/profile');
} else {
session.send('Hi %s. How can I help you ?', session.userData.name);
}
}
]);
bot.dialog('/profile', [
function (session) {
// session.send('Hello, My name is Norma. Please give me your name.');
builder.Prompts.text(session, 'Hello, My name is Norma. Please give me your name.');
},
function (session, results) {
session.userData.name = results.response;
session.send('Hi %s. How can I help you ?', session.userData.name);
session.endDialog();
}
]);
bot.dialog('/email', [
function (session, args, next) {
builder.Prompts.text(session, 'Can I have your email address please ?');
},
function (session, result) {
session.send('Thak you %s, you will receive an email from me very soon.', session.userData.name);
session.userData.email = result.response;
// session.endDialog;
}
]);
bot.dialog('reset', function (session, args, next) {
session.userData.name = '';
session.userData.email = '';
session.send('Done!');
session.endDialog();
})
.triggerAction({
matches: /^reset$/i,
confirmPrompt: "Are you sure?"
});