feat(bot): add session management and user tracking

- Implement Prisma storage adapter for Telegram session management
- Add middleware to upsert Telegram user data
- Extend TelegramUser model with additional fields
- Add db:push command to turbo.json and package.json
- Extend Prisma client with exists helper method
This commit is contained in:
Yuu Ottosoka
2025-07-09 20:36:07 +03:00
parent 84760349c0
commit 49f0385d00
8 changed files with 115 additions and 15 deletions

View File

@@ -1,12 +1,22 @@
import { serve } from '@hono/node-server';
import { config } from './config';
import { Bot, webhookCallback } from 'grammy';
import { Bot, session, webhookCallback } from 'grammy';
import { Hono } from 'hono';
import { logger } from '@repo/logger';
import { PrismaStorageAdapter } from './session-storage';
import { BotContext } from './types';
import { upsertUser } from './middlewares/upsert-user';
const bot = new Bot(config.BOT_TOKEN);
const bot = new Bot<BotContext>(config.BOT_TOKEN);
const storage = new PrismaStorageAdapter();
bot.command('start', (ctx) => ctx.reply('Привет, мир'));
bot.use(session({ storage, initial: () => ({}) }));
bot.use(upsertUser);
bot.command('start', async (ctx) => {
const session = await ctx.session;
await ctx.reply('Привет, ' + JSON.stringify(session));
});
if (config.MODE === 'webhook') {
logger.info('Starting in webhook mode...');