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.
37 lines
852 B
TypeScript
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 });
|
|
}
|
|
}
|