Skip to content

Commit a36e65e

Browse files
Env renaming, vk bot initing.
1 parent 6297c02 commit a36e65e

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

.eslintrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
"rules": {
4949
"indent": [
5050
"error",
51-
"tab"
51+
"tab",
52+
{
53+
"SwitchCase": 1
54+
}
5255
],
5356
"linebreak-style": [
5457
"error",

src/adapters/bot/telegram/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Logger } from "winston";
66

77
import initListeners from "./listeners";
88

9-
const BOT_TOKEN = process.env.BOT_TOKEN;
9+
const TELEGRAM_BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
1010

1111
interface InitTelegramBot {
1212
logger?: Logger,
@@ -17,7 +17,7 @@ interface InitTelegramBot {
1717
}
1818

1919
const initTelegramBot = ({ logger, cache, messagesCache, repository = null, externals }: InitTelegramBot) => {
20-
const bot = new TelegramBotApi(BOT_TOKEN, { polling: true });
20+
const bot = new TelegramBotApi(TELEGRAM_BOT_TOKEN, { polling: true });
2121

2222
bot.setMyCommands([
2323
{ command: "/start", description: "Начать" },

src/adapters/bot/telegram/listeners/callback-query/payment.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Logger } from "winston";
77

88
import { payments } from "./payments-config";
99

10-
const YOOMONEY_TOKEN = process.env.YOOMONEY_TOKEN;
10+
const YOOMONEY_TELEGRAM_BOT_TOKEN = process.env.YOOMONEY_TELEGRAM_BOT_TOKEN;
1111

1212
interface PaymentQueryParams {
1313
bot: TelegramBot,
@@ -68,7 +68,7 @@ export const paymentQueryHandler = async ({ bot, query, cache, messagesCache, lo
6868
selectedPayment.title,
6969
selectedPayment.description,
7070
JSON.stringify(selectedPayment.payload),
71-
YOOMONEY_TOKEN,
71+
YOOMONEY_TELEGRAM_BOT_TOKEN,
7272
"RUB",
7373
// @ts-ignore
7474
selectedPayment.prices,

src/app.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import express from "express";
55
import http from "http";
66

77
import { initTelegramBot } from "./adapters/bot/telegram";
8+
import { initVkontakteBot } from "./adapters/bot/vkontakte";
89
import { initExternalServices } from "./adapters/externals";
910
import { FirestoreRepository } from "./adapters/repository";
1011
import initLogger from "./logger";
1112
import initRoutes from "./ports/http";
1213
import { Cache, MessagesCache } from "./types";
1314

1415
const PORT = process.env.PORT || 8080;
16+
const BOT_TO_RUN = process.env.BOT_TO_RUN;
1517
const ASTRIA_IS_FAST_BRANCH = process.env.ASTRIA_IS_FAST_BRANCH;
1618

1719
const app = express();
@@ -28,18 +30,28 @@ async function main() {
2830
const server = http.createServer(app);
2931

3032
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-
3633
const repository = new FirestoreRepository({ logger });
3734

3835
const externals = initExternalServices();
3936

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 });
4145

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+
});
4355
});
4456
}
4557

src/common/i18n/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from "path";
66
i18next
77
.use(FsBackend)
88
.init({
9-
debug: process.env.DEBUG_I18NEXT === "true",
9+
debug: !!process.env.DEBUG_I18NEXT,
1010

1111
initImmediate: false,
1212

src/logger/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const initLogger = () => {
1717
],
1818
});
1919

20-
if (process.env.LOGGER_MODE === "test") {
20+
if (!!process.env.LOGGER_TO_CONSOLE) {
2121
logger.add(new transports.Console({
2222
format: format.simple(),
2323
}));

0 commit comments

Comments
 (0)