Files
tg-bot-template/apps/bot/src/session-storage.ts
Yuu Ottosoka df8bfa049f feat(bot): add i18n support with grammy-i18n package
Add internationalization support to the bot using grammy-i18n package.
Includes English and Russian locale files and updates to session handling.
Disabled db:generate in Dockerfile as it's not needed during build.
2025-07-12 16:37:09 +03:00

37 lines
852 B
TypeScript

import { prisma } from '@repo/db';
import { StorageAdapter } from 'grammy';
export class PrismaStorageAdapter<T extends object>
implements StorageAdapter<T>
{
async read(key: string): Promise<T | undefined> {
return prisma.telegramSession
.findUnique({
where: {
id: key,
},
})
.then((session) => (session?.data as T) || undefined);
}
async write(key: string, data: T): Promise<void> {
await prisma.telegramSession.upsert({
where: {
id: key,
},
create: {
id: key,
data,
},
update: {
data,
},
});
}
async delete(key: string): Promise<void> {
await prisma.telegramSession.delete({ where: { id: key } });
}
async has(key: string): Promise<boolean> {
return prisma.telegramSession.exists({ id: key });
}
}