- Replace Redis/in-memory storage with SQLite for persistence - Add database.ts service with tables for users, groups, purchases, participants - Update state.ts and groupState.ts to use SQLite backend - Fix buyer_name to use display name instead of Telegram ID - Remove legacy reminder array handlers (now using 3-slot system) - Add better-sqlite3 dependency, remove ioredis - Update env.example with BOT_DATABASE_PATH option - Add data/ directory to .gitignore for database files
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
|
|
|
function required(name: string): string {
|
|
const value = process.env[name];
|
|
if (!value) {
|
|
throw new Error(`Missing required environment variable: ${name}`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function optional(name: string, defaultValue: string): string {
|
|
return process.env[name] || defaultValue;
|
|
}
|
|
|
|
function optionalInt(name: string, defaultValue: number): number {
|
|
const value = process.env[name];
|
|
if (!value) return defaultValue;
|
|
const parsed = parseInt(value, 10);
|
|
return isNaN(parsed) ? defaultValue : parsed;
|
|
}
|
|
|
|
export const config = {
|
|
telegram: {
|
|
botToken: required('TELEGRAM_BOT_TOKEN'),
|
|
},
|
|
api: {
|
|
baseUrl: optional('API_BASE_URL', 'http://localhost:3000'),
|
|
},
|
|
frontend: {
|
|
baseUrl: optional('FRONTEND_BASE_URL', 'http://localhost:3001'),
|
|
},
|
|
database: {
|
|
path: process.env.BOT_DATABASE_PATH || null, // Defaults to ./data/bot.db in database.ts
|
|
},
|
|
bot: {
|
|
maxTicketsPerPurchase: optionalInt('MAX_TICKETS_PER_PURCHASE', 100),
|
|
paymentPollIntervalMs: optionalInt('PAYMENT_POLL_INTERVAL_MS', 5000),
|
|
paymentPollTimeoutMs: optionalInt('PAYMENT_POLL_TIMEOUT_MS', 900000), // 15 minutes
|
|
invoiceExpiryMinutes: optionalInt('INVOICE_EXPIRY_MINUTES', 15),
|
|
},
|
|
logging: {
|
|
level: optional('LOG_LEVEL', 'info'),
|
|
},
|
|
nodeEnv: optional('NODE_ENV', 'development'),
|
|
};
|
|
|
|
export default config;
|
|
|
|
|