forked from ChimeneB/Chat-Bot-Build-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
74 lines (63 loc) · 2.43 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
var restify = require('restify');
var builder = require('botbuilder');
var cognitiveservices = require('botbuilder-cognitiveservices');
require('dotenv').load();
//=========================================================
// Bot Setup
//=========================================================
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3578, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
server.get('/', restify.plugins.serveStatic({
directory: __dirname,
default: '/default.html'
}));
server.post('/api/messages', connector.listen());
//=========================================================
// Recognizers
//=========================================================
var qnarecognizer = new cognitiveservices.QnAMakerRecognizer({
knowledgeBaseId: process.env.QnA_KBID,
subscriptionKey: process.env.QnA_Key,
top: 1
});
var model = process.env.LUIS_MODEL_URL;
var recognizer = new builder.LuisRecognizer(model);
//=========================================================
// Bot Dialogs
//=========================================================
var intents = new builder.IntentDialog({ recognizers: [recognizer, qnarecognizer] });
bot.dialog('/', intents);
intents.matches('Greetings', [
function (session, args, next) {
var msg = new builder.Message(session).addAttachment(createHeroCard(session));
session.send(msg);
}]);
intents.matches('qna' || 'none', [
function (session, args, next) {
var answerEntity = builder.EntityRecognizer.findEntity(args.entities, 'answer');
session.send(answerEntity.entity);
}
]);
intents.onDefault([
function (session) {
session.send('Sorry!! No match!!');
}
]);
function createHeroCard(session) {
return new builder.HeroCard(session)
.title('Demo Chat Bot')
.subtitle('Your friendly neighbourhood bot')
.text('Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.')
.images([
builder.CardImage.create(session, 'https://z.co.nz/assets/Uploads/Who-Is-Z.png')
]);
}