-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
59 lines (46 loc) · 1.41 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
const express = require('express');
const app = express();
const http = require('http').Server(app);
const port = process.env.PORT || 8000;
const io = require('socket.io')(http);
const Botmaster = require('botmaster');
const SocketBot = require('botmaster-socket.io');
const SessionWare = require('botmaster-session-ware');
const WatsonConversationWare = require('./botmaster-watson-conversation-ware');
app.use(express.static(__dirname + '/public'));
const server = http.listen(port, '0.0.0.0', () => {
console.log('listening on %d', port);
});
const socketBotSettings = {
id: 'CHARTDOCTOR',
server
}
const watsonConversationWareOptions = {
settings: {
username: "",
password: "",
version: 'v1',
version_date: '2017-02-03',
},
workspaceId: ""
}
const botmaster = new Botmaster();
const mySocketBot = new SocketBot(socketBotSettings);
botmaster.addBot(mySocketBot);
const watsonConversationWare = WatsonConversationWare(watsonConversationWareOptions);
botmaster.use(watsonConversationWare);
botmaster.on('error', (bot, err) => {
console.log(err.stack);
});
botmaster.use({
type: 'incoming',
name: 'my-watson-controller',
controller: (bot, update) => {
return bot.sendTextCascadeTo(update.watsonUpdate.output.text, update.sender.id);
}
});
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
})
const sessionWare = SessionWare();
botmaster.useWrapped(sessionWare.incoming, sessionWare.outgoing);