-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamy.js
63 lines (48 loc) · 1.45 KB
/
amy.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
'use strict';
// so what do you require?
const {
Botkit
} = require('botkit');
const {
config
} = require('./config.js');
const {
luis
} = require('./luis');
const controller = new Botkit({
webhook_uri: '/api/messages',
});
const luisOptions = {
serviceUri: config.luis.serviceUri
}
// ok, let's see what you need
const threshold = config.nlp.threshold;
// controller.middleware.ingest.use(() => {
// console.log('yes, i got your message')
// });
// controller.middleware.send.use(() => {
// console.log('yes, message is sent.')
// });
controller.middleware.receive.use(luis.middleware.receive(luisOptions));
controller.on('message', async (bot, message) => {
let reply = 'sorry, did not understand your request.';
if (message.topIntent) {
console.log(message.topIntent);
const intent = message.topIntent.intent;
const score = message.topIntent.score;
if (intent == 'greeting' && score >= threshold)
reply = 'hello'
if (intent == 'whois' && score >= threshold) {
var person = message.entities[0].entity;
// console.log(message.entities);
reply = person + ' is our manager.';
}
if (intent == 'weather' && score >= threshold) {
reply = 'it is cloudy today.';
}
if (intent == 'hru' && score >= threshold) {
reply = 'I am great, how about you?';
}
}
await bot.say(reply);
});