Features: - Multi-channel notifications (Email + Telegram) - User-configurable notification settings per channel - Telegram bot integration with rich messages, location pins, and inline buttons - QR code generation for easy bot access (@myidbot support) - Admin UI for notification settings management - Test functionality for Telegram connection - Comprehensive documentation Implementation: - lib/telegram-service.ts: Telegram API integration - lib/notification-settings-db.ts: Database layer for user notification preferences - lib/geofence-notifications.ts: Extended for parallel multi-channel delivery - API routes for settings management and testing - Admin UI with QR code display and step-by-step instructions - Database table: UserNotificationSettings Documentation: - docs/telegram.md: Technical implementation guide - docs/telegram-anleitung.md: User guide with @myidbot instructions - docs/telegram-setup.md: Admin setup guide - README.md: Updated NPM scripts section Docker: - Updated Dockerfile to copy public directory - Added TELEGRAM_BOT_TOKEN environment variable - Integrated notification settings initialization in db:init 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
1007 B
JavaScript
Executable File
39 lines
1007 B
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* Initialize UserNotificationSettings table
|
|
*/
|
|
|
|
const Database = require('better-sqlite3');
|
|
const path = require('path');
|
|
|
|
const dbPath = path.join(process.cwd(), 'data', 'database.sqlite');
|
|
|
|
try {
|
|
const db = new Database(dbPath);
|
|
|
|
db.exec(`
|
|
CREATE TABLE IF NOT EXISTS UserNotificationSettings (
|
|
user_id TEXT PRIMARY KEY,
|
|
email_enabled INTEGER DEFAULT 1,
|
|
telegram_enabled INTEGER DEFAULT 0,
|
|
telegram_chat_id TEXT,
|
|
created_at TEXT DEFAULT (datetime('now')),
|
|
updated_at TEXT DEFAULT (datetime('now')),
|
|
|
|
FOREIGN KEY (user_id) REFERENCES User(id) ON DELETE CASCADE,
|
|
CHECK (email_enabled IN (0, 1)),
|
|
CHECK (telegram_enabled IN (0, 1))
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_user_notification_settings_user
|
|
ON UserNotificationSettings(user_id);
|
|
`);
|
|
|
|
db.close();
|
|
|
|
console.log('✅ Notification settings table initialized!');
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message);
|
|
process.exit(1);
|
|
}
|