feat: add bot and api services with config, logger and database packages
- Add bot service with telegram integration and webhook/polling modes - Add api service with hono, swagger and zod-openapi - Create config package for environment variable management - Create logger package for colored console logging - Create database package with prisma integration - Remove next.js web and docs apps - Update turbo.json for new services - Add dockerfiles and gitea workflows for deployment
This commit is contained in:
12
apps/bot/src/config.ts
Normal file
12
apps/bot/src/config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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'),
|
||||
},
|
||||
});
|
||||
33
apps/bot/src/index.ts
Normal file
33
apps/bot/src/index.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { serve } from '@hono/node-server';
|
||||
import { config } from './config';
|
||||
import { Bot, webhookCallback } from 'grammy';
|
||||
import { Hono } from 'hono';
|
||||
import { logger } from '@repo/logger';
|
||||
|
||||
const bot = new Bot(config.BOT_TOKEN);
|
||||
|
||||
bot.command('start', (ctx) => ctx.reply('Привет, мир'));
|
||||
|
||||
if (config.MODE === 'webhook') {
|
||||
logger.info('Starting in webhook mode...');
|
||||
|
||||
const app = new Hono();
|
||||
app.post(`/${config.WEBHOOK_URI}`, webhookCallback(bot, 'hono'));
|
||||
|
||||
serve(
|
||||
{
|
||||
fetch: app.fetch,
|
||||
port: Number(config.PORT),
|
||||
},
|
||||
(info) => {
|
||||
logger.info(`Server is running on localhost:${info.port}`);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
logger.info('Starting in polling mode...');
|
||||
bot.start({
|
||||
onStart: () => {
|
||||
logger.info('Bot started polling...');
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user