This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathindex.js
83 lines (73 loc) · 2.15 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const express = require('express');
const bodyParser = require('body-parser');
const config = require('./config');
const MAX_ITEMS_IN_CACHE = 500;
const EXPIRED_IN_FIVE_MINUTE = 5 * 60;
// Initialize Variable
global.CLOUD_POOL_SIZE = 0;
// Platforms
const {
LineBot,
// MessengerBot,
TelegramBot,
ConsoleBot,
MemorySessionStore
} = require('bottender');
const {
registerRoutes
} = require('bottender/express');
const handler = require("./handle/handler");
const server = express();
server.use(bodyParser.json({
verify: (req, res, buf) => {
req.rawBody = buf.toString();
},
}));
// Session: how we store session. We stores sessions in memory.
const mSession = new MemorySessionStore(MAX_ITEMS_IN_CACHE, EXPIRED_IN_FIVE_MINUTE);
// Session data: used for conversation
const sessData = {
isGotImgWaitAnwser: false,
isGotReqWaitImg: false,
previousContext: {}
}
// 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,
// sessionStore: mSession,
// }).setInitialState(sessData).onEvent(handler),
line: new LineBot({
channelSecret: config.channelSecret,
accessToken: config.channelAccessToken,
sessionStore: mSession,
}).setInitialState(sessData).
onEvent(handler),
telegram: new TelegramBot({
accessToken: config.telegramAccessToken,
sessionStore: mSession,
}).setInitialState(sessData).
onEvent(handler),
};
// registerRoutes(server, bots.messenger, {
// path: '/messenger',
// verifyToken: config.messengerVerifyToken
// });
registerRoutes(server, bots.line, {
path: '/line'
});
registerRoutes(server, bots.telegram, {
path: '/telegram'
});
server.listen(process.env.PORT || 5000, () => {
console.log('server is running on 5000 port...');
});
}