Add SQLite database for Telegram bot user/group settings
- 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
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import TelegramBot from 'node-telegram-bot-api';
|
||||
import { stateManager } from '../services/state';
|
||||
import { logger, logUserAction } from '../services/logger';
|
||||
import { getMainMenuKeyboard, getCancelKeyboard } from '../utils/keyboards';
|
||||
import { getMainMenuKeyboard, getLightningAddressKeyboard } from '../utils/keyboards';
|
||||
import { messages } from '../messages';
|
||||
|
||||
/**
|
||||
@@ -10,6 +10,7 @@ import { messages } from '../messages';
|
||||
export async function handleStart(bot: TelegramBot, msg: TelegramBot.Message): Promise<void> {
|
||||
const chatId = msg.chat.id;
|
||||
const userId = msg.from?.id;
|
||||
const username = msg.from?.username;
|
||||
|
||||
if (!userId) {
|
||||
await bot.sendMessage(chatId, messages.errors.userNotIdentified);
|
||||
@@ -17,7 +18,7 @@ export async function handleStart(bot: TelegramBot, msg: TelegramBot.Message): P
|
||||
}
|
||||
|
||||
logUserAction(userId, 'Started bot', {
|
||||
username: msg.from?.username,
|
||||
username: username,
|
||||
firstName: msg.from?.first_name,
|
||||
});
|
||||
|
||||
@@ -29,7 +30,7 @@ export async function handleStart(bot: TelegramBot, msg: TelegramBot.Message): P
|
||||
// Create new user
|
||||
user = await stateManager.createUser(
|
||||
userId,
|
||||
msg.from?.username,
|
||||
username,
|
||||
msg.from?.first_name,
|
||||
msg.from?.last_name
|
||||
);
|
||||
@@ -40,9 +41,9 @@ export async function handleStart(bot: TelegramBot, msg: TelegramBot.Message): P
|
||||
|
||||
// Check if lightning address is set
|
||||
if (!user.lightningAddress) {
|
||||
await bot.sendMessage(chatId, messages.start.needAddress, {
|
||||
await bot.sendMessage(chatId, messages.start.needAddressWithOptions(username), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_markup: getCancelKeyboard(),
|
||||
reply_markup: getLightningAddressKeyboard(username),
|
||||
});
|
||||
|
||||
await stateManager.updateUserState(userId, 'awaiting_lightning_address');
|
||||
|
||||
Reference in New Issue
Block a user