mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 15:44:02 +00:00
33 lines
861 B
TypeScript
33 lines
861 B
TypeScript
import { Bot } from 'grammy'
|
|
import type { Logger } from '@household/observability'
|
|
|
|
import { botLocaleFromContext, getBotTranslations } from './i18n'
|
|
import { formatTelegramHelpText } from './telegram-commands'
|
|
|
|
export function createTelegramBot(token: string, logger?: Logger): Bot {
|
|
const bot = new Bot(token)
|
|
|
|
bot.command('help', async (ctx) => {
|
|
const locale = botLocaleFromContext(ctx)
|
|
await ctx.reply(formatTelegramHelpText(locale))
|
|
})
|
|
|
|
bot.command('household_status', async (ctx) => {
|
|
const locale = botLocaleFromContext(ctx)
|
|
await ctx.reply(getBotTranslations(locale).bot.householdStatusPending)
|
|
})
|
|
|
|
bot.catch((error) => {
|
|
logger?.error(
|
|
{
|
|
event: 'telegram.bot_error',
|
|
updateId: error.ctx?.update.update_id,
|
|
error: error.error
|
|
},
|
|
'Telegram bot error'
|
|
)
|
|
})
|
|
|
|
return bot
|
|
}
|