-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
76 lines (65 loc) · 2.86 KB
/
app.js
File metadata and controls
76 lines (65 loc) · 2.86 KB
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
var restify = require('restify');
var builder = require('botbuilder');
var luis = require('./Controller/LuisDialog');
var fs = require('fs');
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: '37cbbce4-63f1-4703-b9f4-79998acfd52f',
appPassword:'iyhRPZX024?*lsfiTRZ92^+'
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
// Receive messages from the user
var bot = new builder.UniversalBot(connector, [function (session) {
//read image from file
var image64 = new Buffer(fs.readFileSync('contosobotcolor.png').toString("base64"));
//Create welcome hero card
session.send(new builder.Message(session)
.addAttachment(
new builder.HeroCard(session)
.title("Hi, welcome to Contoso")
.subtitle("I am Conrad, your ContosoBot")
.text(`I can help you do these awesome things:
\n • View your balance
\n • Open a new bank account
\n • Remove your bank account
\n • Make transfers across accounts
\n • View what types of bank accounts you have
\n • Get exchange rates
\n • Get stock quotes
\n
\n Type 'help' to see all options again. If you want to ask me about these options, type 'explain more for me' or click on the link below.`)
.images([builder.CardImage.create(session,"data:image/jpeg;base64,"+image64)])
.buttons([
builder.CardAction.openUrl(session, 'https://contosowebsite.azurewebsites.net/faq.html', 'Help'),
builder.CardAction.openUrl(session, 'about:blank', 'Log in')
])
));
builder.Prompts.text(session, "Enter your name to begin"); //prompt user for their name
},
function(session, results) {
session.conversationData.name = results.response;
if (!session.conversationData.name) {
session.conversationData.name = "Human";
session.send("Sorry I didn't quite get your name. I will call you Human for now"); //if name is not detected
} else {
session.send("Hi " + session.conversationData.name); //say their name
}
}
]);
// Send welcome when conversation with bot is started, by initiating the root dialog
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.beginDialog(message.address, '/');
}
});
}
});
luis.startDialog(bot);