Telegram Bot + Mini App for city walking quests. - React 19 + TypeScript + Vite 6 frontend - Express 5 + PostgreSQL backend - grammY Telegram bot with DeepSeek AI - GitLab CI/CD: lint, build, deploy to production Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
993 B
TypeScript
43 lines
993 B
TypeScript
import 'dotenv/config'
|
|
import { createBot } from './bot.js'
|
|
import { startEventProcessor } from './services/event-processor.js'
|
|
|
|
const token = process.env.TELEGRAM_BOT_TOKEN
|
|
|
|
if (!token) {
|
|
console.error('TELEGRAM_BOT_TOKEN is not set!')
|
|
process.exit(1)
|
|
}
|
|
|
|
const bot = createBot(token)
|
|
|
|
// Start event processing loop (polls quest_events table)
|
|
startEventProcessor(bot)
|
|
|
|
// Start bot
|
|
if (process.env.NODE_ENV === 'production' && process.env.BOT_WEBHOOK_URL) {
|
|
// Webhook mode for production
|
|
bot.api.setWebhook(process.env.BOT_WEBHOOK_URL, {
|
|
secret_token: process.env.BOT_WEBHOOK_SECRET,
|
|
})
|
|
console.log('Guidly bot started in webhook mode')
|
|
} else {
|
|
// Polling mode for development
|
|
bot.start({
|
|
onStart: () => {
|
|
console.log('Guidly bot started in polling mode')
|
|
},
|
|
})
|
|
}
|
|
|
|
// Graceful shutdown
|
|
process.on('SIGTERM', () => {
|
|
console.log('Shutting down bot...')
|
|
bot.stop()
|
|
})
|
|
|
|
process.on('SIGINT', () => {
|
|
console.log('Shutting down bot...')
|
|
bot.stop()
|
|
})
|