-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
executable file
·35 lines (28 loc) · 1.28 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
const Botmaster = require('botmaster');
const MessengerBot = require('botmaster-messenger');
const { fulfillOutgoingWare } = require('botmaster-fulfill');
const actions = require('botmaster-fulfill-actions');
const config = require('./config');
const incomingMiddleware = require('./middleware/incoming');
const watsonConversationStorageMiddleware = require('./middleware/watson_conversation_storage');
// Initialize messenger bot
messengerBot = new MessengerBot(config.messengerCredentials);
// Define botmaster and add different bot-types (in this case only messenger)
const botmaster = new Botmaster(config.botmasterSettings);
botmaster.addBot(messengerBot);
// Incoming middleware for botmaster to perform middleware tasks before update handler is entered.
botmaster.use({
type: 'incoming',
name: 'retrieveSession',
controller: watsonConversationStorageMiddleware.retrieveSession
});
botmaster.use(incomingMiddleware.userInfo.addUserInfoToUpdate);
botmaster.use(incomingMiddleware.reply.replyToUser);
// Botmaster outgoing middleware handlers
botmaster.use({
type: 'outgoing',
name: 'fulfill-middleware',
controller: fulfillOutgoingWare({actions})
});
botmaster.on('listening', (message) => { console.log(message); });
botmaster.on('error', (bot, err) => { console.log(err.stack); });