mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 07:25:36 +01:00
Add sentry
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "esbuild ./src/main.ts --bundle --platform=node --outfile=./build/main.cjs",
|
||||
"build-minify": "npm run build -- --minify --sourcemap",
|
||||
"build-watch": "npm run build -- --watch",
|
||||
"run": "node ./build/main.cjs",
|
||||
"run-watch": "nodemon build/main.cjs"
|
||||
@@ -13,6 +14,7 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@sentry/node": "^6.16.1",
|
||||
"docker-ip-get": "^1.1.5",
|
||||
"envalid": "^7.2.2",
|
||||
"express": "^4.17.1",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as Sentry from '@sentry/node';
|
||||
|
||||
import { Context, Telegraf, Markup, TelegramError } from 'telegraf';
|
||||
|
||||
import { BotState, Cache } from '@/bots/manager';
|
||||
@@ -18,6 +20,11 @@ import { getPaginatedMessage, registerLanguageSettingsCallback, registerPaginati
|
||||
import { getRandomKeyboard, getUpdateLogKeyboard, getUserAllowedLangsKeyboard } from './keyboard';
|
||||
|
||||
|
||||
Sentry.init({
|
||||
dsn: env.SENTRY_DSN,
|
||||
});
|
||||
|
||||
|
||||
export async function createApprovedBot(token: string, state: BotState): Promise<Telegraf> {
|
||||
const bot = new Telegraf(token, {
|
||||
telegram: {
|
||||
@@ -202,7 +209,7 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
||||
const userSettings = await getUserSettings(ctx.message.from.id);
|
||||
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
||||
|
||||
const pMessage = await getPaginatedMessage(CallbackData.AUTHOR_BOOKS_PREFIX, authorId, 1, allowedLangs, BookLibrary.getAuthorBooks, formatBook);
|
||||
const pMessage = await getPaginatedMessage(CallbackData.AUTHOR_BOOKS_PREFIX, parseInt(authorId), 1, allowedLangs, BookLibrary.getAuthorBooks, formatBook);
|
||||
|
||||
await ctx.reply(pMessage.message, {
|
||||
reply_markup: pMessage.keyboard.reply_markup
|
||||
@@ -219,7 +226,7 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
||||
const userSettings = await getUserSettings(ctx.message.from.id);
|
||||
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
||||
|
||||
const pMessage = await getPaginatedMessage(CallbackData.TRANSLATOR_BOOKS_PREFIX, translatorId, 1, allowedLangs, BookLibrary.getTranslatorBooks, formatBook);
|
||||
const pMessage = await getPaginatedMessage(CallbackData.TRANSLATOR_BOOKS_PREFIX, parseInt(translatorId), 1, allowedLangs, BookLibrary.getTranslatorBooks, formatBook);
|
||||
|
||||
await ctx.reply(pMessage.message, {
|
||||
reply_markup: pMessage.keyboard.reply_markup
|
||||
@@ -236,7 +243,7 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
||||
const userSettings = await getUserSettings(ctx.message.from.id);
|
||||
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
||||
|
||||
const pMessage = await getPaginatedMessage(CallbackData.SEQUENCE_BOOKS_PREFIX, sequenceId, 1, allowedLangs, BookLibrary.getSequenceBooks, formatBook);
|
||||
const pMessage = await getPaginatedMessage(CallbackData.SEQUENCE_BOOKS_PREFIX, parseInt(sequenceId), 1, allowedLangs, BookLibrary.getSequenceBooks, formatBook);
|
||||
|
||||
await ctx.reply(pMessage.message, {
|
||||
reply_markup: pMessage.keyboard.reply_markup
|
||||
@@ -271,5 +278,9 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
||||
});
|
||||
});
|
||||
|
||||
bot.catch((err) => {
|
||||
Sentry.captureException(err);
|
||||
});
|
||||
|
||||
return bot;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { cleanEnv, str, num } from 'envalid';
|
||||
|
||||
|
||||
export default cleanEnv(process.env, {
|
||||
SENTRY_DSN: str(),
|
||||
WEBHOOK_BASE_URL: str(),
|
||||
WEBHOOK_PORT: num(),
|
||||
TELEGRAM_BOT_API_ROOT: str({ default: "https://api.telegram.org" }),
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import BotsManager from './bots/manager';
|
||||
|
||||
setTimeout(() => BotsManager.start(), 5_000);
|
||||
BotsManager.start();
|
||||
|
||||
Reference in New Issue
Block a user