Fix creating bots in manager

This commit is contained in:
2022-02-04 12:00:02 +03:00
parent 22e7905791
commit cf133f7291

View File

@@ -1,3 +1,5 @@
import * as Sentry from '@sentry/node';
import express, { Response, Request, NextFunction } from 'express'; import express, { Response, Request, NextFunction } from 'express';
import { Server } from 'http'; import { Server } from 'http';
@@ -10,12 +12,18 @@ import { Telegraf } from 'telegraf';
import env from '@/config'; import env from '@/config';
import getBot, { BotStatuses } from './factory/index'; import getBot, { BotStatuses } from './factory/index';
Sentry.init({
dsn: env.SENTRY_DSN,
});
export enum Cache { export enum Cache {
ORIGINAL = "original", ORIGINAL = "original",
BUFFER = "buffer", BUFFER = "buffer",
NO_CACHE = "no_cache" NO_CACHE = "no_cache"
} }
export interface BotState { export interface BotState {
id: number; id: number;
token: string; token: string;
@@ -81,10 +89,17 @@ export default class BotsManager {
await oldBot.telegram.deleteWebhook(); await oldBot.telegram.deleteWebhook();
await oldBot.telegram.logOut(); await oldBot.telegram.logOut();
} catch (e) { } catch (e) {
console.log(e); Sentry.captureException(e);
} }
const bot = await getBot(state.token, state); let bot: Telegraf;
try {
bot = await getBot(state.token, state);
} catch (e) {
Sentry.captureException(e);
return;
}
const dockerIp = await dockerIpTools.getContainerIp(); const dockerIp = await dockerIpTools.getContainerIp();