@@ -5,13 +5,15 @@ import express from "express";
5
5
import http from "http" ;
6
6
7
7
import { initTelegramBot } from "./adapters/bot/telegram" ;
8
+ import { initVkontakteBot } from "./adapters/bot/vkontakte" ;
8
9
import { initExternalServices } from "./adapters/externals" ;
9
10
import { FirestoreRepository } from "./adapters/repository" ;
10
11
import initLogger from "./logger" ;
11
12
import initRoutes from "./ports/http" ;
12
13
import { Cache , MessagesCache } from "./types" ;
13
14
14
15
const PORT = process . env . PORT || 8080 ;
16
+ const BOT_TO_RUN = process . env . BOT_TO_RUN ;
15
17
const ASTRIA_IS_FAST_BRANCH = process . env . ASTRIA_IS_FAST_BRANCH ;
16
18
17
19
const app = express ( ) ;
@@ -28,18 +30,28 @@ async function main() {
28
30
const server = http . createServer ( app ) ;
29
31
30
32
server . listen ( PORT , ( ) => {
31
- logger . log ( {
32
- level : "info" ,
33
- message : `We are live on ${ PORT } , ASTRIA_IS_FAST_BRANCH = ${ ! ! ASTRIA_IS_FAST_BRANCH } ` ,
34
- } ) ;
35
-
36
33
const repository = new FirestoreRepository ( { logger } ) ;
37
34
38
35
const externals = initExternalServices ( ) ;
39
36
40
- const bot = initTelegramBot ( { logger, cache, messagesCache, repository, externals } ) ;
37
+ switch ( BOT_TO_RUN ) {
38
+ case "telegram" :
39
+ const telegramBot = initTelegramBot ( { logger, cache, messagesCache, repository, externals } ) ;
40
+
41
+ initRoutes ( { app, bot : telegramBot , logger } ) ;
42
+ break ;
43
+ case "vkontakte" :
44
+ const vkontakteBot = initVkontakteBot ( { logger, cache, messagesCache, repository, externals } ) ;
41
45
42
- initRoutes ( { app, bot, logger } ) ;
46
+ break ;
47
+ default :
48
+ throw new Error ( "NO VALID BOT_TO_RUN ENV PROVIDED!" ) ;
49
+ }
50
+
51
+ logger . log ( {
52
+ level : "info" ,
53
+ message : `We are live on ${ PORT } , BOT_TO_RUN = ${ BOT_TO_RUN } , ASTRIA_IS_FAST_BRANCH = ${ ! ! ASTRIA_IS_FAST_BRANCH } ` ,
54
+ } ) ;
43
55
} ) ;
44
56
}
45
57
0 commit comments