feat: add file storage service and update configurations

refactor: migrate to tsup for builds and update tsconfigs
fix: update error handling and validation in payment service
chore: update package scripts and dependencies
docs: update README and env examples
This commit is contained in:
Yuu Ottosoka
2025-07-12 16:01:57 +03:00
parent c0c04bbdba
commit f9ecac94f2
67 changed files with 3308 additions and 695 deletions

View File

@@ -1,12 +1,12 @@
import { createConfig } from '@repo/config';
import z from 'zod';
import 'dotenv/config';
import { createConfig } from "@repo/config";
import z from "zod";
import "dotenv/config";
export const config = createConfig({
schema: {
BOT_TOKEN: z.string(),
WEBHOOK_URI: z.string(),
PORT: z.string().default('3000'),
MODE: z.enum(['polling', 'webhook']).default('polling'),
PORT: z.string().default("3000"),
MODE: z.enum(["polling", "webhook"]).default("polling"),
},
});

View File

@@ -37,9 +37,15 @@ if (config.MODE === 'webhook') {
);
} else {
logger.info('Starting in polling mode...');
bot.start({
onStart: () => {
logger.info('Bot started polling...');
},
});
const startBot = async () => {
bot.start({
drop_pending_updates: true,
onStart: () => {
logger.info('Bot started polling...');
},
});
};
startBot();
}

View File

@@ -7,7 +7,8 @@ const errorReply =
const replyErrorLog = 'Не удалось отправить сообщение об ошибке пользователю';
export const onError: MiddlewareFn<BotContext> = async (ctx, next) => {
return await next().catch(async () => {
return await next().catch(async (e) => {
logger.error('Ошибка в onError', e);
await ctx.reply(errorReply).catch((err) => {
logger.error(replyErrorLog, err);
});

View File

@@ -1,6 +1,6 @@
import { MiddlewareFn } from 'grammy';
import { BotContext } from '../types';
import { Prisma, prisma } from '@repo/db';
import { MiddlewareFn } from "grammy";
import { BotContext } from "../types";
import { Prisma, prisma } from "@repo/db";
export const upsertUser: MiddlewareFn<BotContext> = async (ctx, next) => {
const telegramId = ctx.from?.id.toString();

View File

@@ -1,5 +1,5 @@
import { prisma } from '@repo/db';
import { StorageAdapter } from 'grammy';
import { prisma } from "@repo/db";
import { StorageAdapter } from "grammy";
export class PrismaStorageAdapter<T extends object>
implements StorageAdapter<T>
@@ -14,7 +14,7 @@ export class PrismaStorageAdapter<T extends object>
.then((session) => (session?.data as T) || undefined);
}
async write(key: string, data: T): Promise<void> {
console.log('write', data);
console.log("write", data);
await prisma.telegramSession.upsert({
where: {
id: key,

View File

@@ -1,5 +1,5 @@
import { Context, LazySessionFlavor } from 'grammy';
import { Context, LazySessionFlavor } from "grammy";
// config your session data
export type SessionData = { };
export type SessionData = {};
export type BotContext = Context & LazySessionFlavor<SessionData>;