forked from weather-bot/WxKitty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (50 loc) · 1.29 KB
/
index.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
const express = require('express');
const bodyParser = require('body-parser');
const config = require('./config');
// Platforms
const {
LineBot,
MessengerBot,
ConsoleBot
} = require('bottender');
const {
registerRoutes
} = require('bottender/express');
const handler = require("./handler");
const server = express();
server.use(
bodyParser.json({
verify: (req, res, buf) => {
req.rawBody = buf.toString();
},
})
);
// Choose platform
let bots;
if (process.argv[2] == "console") {
bots = new ConsoleBot({
fallbackMethods: true,
}).onEvent(handler);
bots.createRuntime();
} else {
bots = {
messenger: new MessengerBot({
accessToken: config.messengerAccessToken,
appSecret: config.messengerAppSecret,
}).onEvent(handler),
line: new LineBot({
channelSecret: config.channelSecret,
accessToken: config.channelAccessToken
}).onEvent(handler),
};
registerRoutes(server, bots.messenger, {
path: '/messenger',
verifyToken: config.messengerVerifyToken
});
registerRoutes(server, bots.line, {
path: '/line'
});
server.listen(process.env.PORT || 5000, () => {
console.log('server is running on 5000 port...');
});
}