-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
executable file
·63 lines (53 loc) · 2.32 KB
/
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
'use strict';
require('dotenv').config();
const server = require('restify').createServer();
server.listen(process.env.port || process.env.PORT || 3978, '::', () =>
console.log('%s listening to %s', server.name, server.url)
);
const builder = require('botbuilder');
const connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
const bot = new builder.UniversalBot(connector);
bot.dialog('/',
new builder
.IntentDialog({ recognizers: [new builder.LuisRecognizer(process.env.LUIS_APP_MODEL)] })
.matches('builtin.intent.communication.send_text', [
(session, args, next) => {
let message = builder.EntityRecognizer.findEntity(args.entities, 'builtin.communication.message');
let contact_name = builder.EntityRecognizer.findEntity(args.entities, 'builtin.communication.contact_name');
session.dialogData.info = { message: message && message.entity, contact_name: contact_name && contact_name.entity };
if (!session.dialogData.info.contact_name)
builder.Prompts.text(session, "Who do you want to message");
else
next();
},
(session, args, next) => {
if (!session.dialogData.info.contact_name)
session.dialogData.info.contact_name = args.response;
if (!session.dialogData.info.message)
builder.Prompts.text(session, `What do you want to tell ${session.dialogData.info.contact_name}`);
else
next();
},
(session, args, next) => {
if (!session.dialogData.info.message)
session.dialogData.info.message = args.response;
builder.Prompts.choice(session, `Do you want to send the message "${session.dialogData.info.message}" to "${session.dialogData.info.contact_name}"?`, ["Yes", "No"]);
},
(session, args, next) => {
if (args.response.entity === "Yes") {
session.send("Message sent.");
} else {
session.send("Message not sent.");
}
}
])
.onDefault(
(session) => {
session.send("I am a very simple bot. Try asking me to send a message.");
}
)
);