-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwit.js
52 lines (35 loc) · 1.16 KB
/
wit.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
'use strict';
const debug = require('debug')('cbp:wit');
const fs = require('fs');
const path = require('path');
const Q = require('q');
const Wit = require('node-wit').Wit;
const GraphAPI = require('./graphAPI');
const sessionStore = require('./sessionStore');
const config = require('./config');
// bot actions
const actions = {
send(request, response) {
debug('saying', response);
let recipientId;
return sessionStore.get(request.sessionId)
.then(session => {
recipientId = session.fbid;
return GraphAPI.sendTemplateMessage(recipientId, response);
})
.catch((err) => {
console.log('Oops! An error occurred while forwarding the response to', recipientId, ':', err );
});
}
};
(function initCustomActions() {
var actionsPath = path.join(__dirname, 'actions');
var actionsFile = fs.readdirSync(actionsPath);
actionsFile.forEach(function (js) {
const actionName = path.basename(js,'.js');
debug(`Initializing wit action [${actionName}]`);
actions[actionName] = require(path.join(actionsPath, js));
});
})();
// Setting up our bot
module.exports = new Wit({accessToken: config.witToken, actions: actions});