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:
@@ -1,4 +1,5 @@
|
||||
BOT_TOKEN="your-bot-token"
|
||||
WEBHOOK_URL="your-webhook-url"
|
||||
PORT=3000
|
||||
MODE=polling or webhook
|
||||
MODE=polling or webhook
|
||||
DATABASE_URL=copy from packages/database/.env
|
||||
@@ -2,10 +2,13 @@
|
||||
"name": "bot",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "NODE_PATH=./src tsnd --respawn --transpile-only --exit-child src/index.ts",
|
||||
"start": "NODE_PATH=./dist node ./dist/index.js",
|
||||
"build": "tsc"
|
||||
"dev": "tsx watch src/index.ts",
|
||||
"start": "node dist/index.js",
|
||||
"build": "tsup",
|
||||
"check-types": "tsc --noEmit",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hono/node-server": "^1.15.0",
|
||||
@@ -19,7 +22,9 @@
|
||||
"zod": "^3.25.76"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"@types/node": "^22.10.2",
|
||||
"tsup": "^8.3.5",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
{
|
||||
"extends": "@repo/typescript-config/base.json",
|
||||
"extends": "@repo/typescript-config/node.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
"rootDir": ".",
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"include": ["src/**/*"],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
"**/*.test.*",
|
||||
"**/*.spec.*"
|
||||
]
|
||||
}
|
||||
20
apps/bot/tsup.config.ts
Normal file
20
apps/bot/tsup.config.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { defineConfig } from "tsup";
|
||||
|
||||
export default defineConfig({
|
||||
entry: ["src/index.ts"],
|
||||
format: ["esm"],
|
||||
dts: false,
|
||||
splitting: false,
|
||||
sourcemap: true,
|
||||
clean: true,
|
||||
external: [
|
||||
"@repo/config",
|
||||
"@repo/db",
|
||||
"@repo/logger",
|
||||
"@repo/typescript-config",
|
||||
],
|
||||
treeshake: true,
|
||||
minify: false,
|
||||
target: "node18",
|
||||
platform: "node",
|
||||
});
|
||||
Reference in New Issue
Block a user