mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 16:14:02 +00:00
feat(ops): sync Telegram commands after deploy
This commit is contained in:
@@ -1,24 +1,13 @@
|
||||
import { Bot } from 'grammy'
|
||||
import type { Logger } from '@household/observability'
|
||||
|
||||
import { formatTelegramHelpText } from './telegram-commands'
|
||||
|
||||
export function createTelegramBot(token: string, logger?: Logger): Bot {
|
||||
const bot = new Bot(token)
|
||||
|
||||
bot.command('help', async (ctx) => {
|
||||
await ctx.reply(
|
||||
[
|
||||
'Household bot scaffold is live.',
|
||||
'Available commands:',
|
||||
'/help - Show command list',
|
||||
'/household_status - Show placeholder household status',
|
||||
'/setup [household name] - Register this group as a household',
|
||||
'/bind_purchase_topic - Bind the current topic as the purchase topic',
|
||||
'/bind_feedback_topic - Bind the current topic as the feedback topic',
|
||||
'/pending_members - List pending household join requests',
|
||||
'/approve_member <telegram_user_id> - Approve a pending member',
|
||||
'/anon <message> - Send anonymous household feedback in a private chat'
|
||||
].join('\n')
|
||||
)
|
||||
await ctx.reply(formatTelegramHelpText())
|
||||
})
|
||||
|
||||
bot.command('household_status', async (ctx) => {
|
||||
|
||||
89
apps/bot/src/telegram-commands.ts
Normal file
89
apps/bot/src/telegram-commands.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
export interface TelegramCommandDefinition {
|
||||
command: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface ScopedTelegramCommands {
|
||||
scope: 'default' | 'all_private_chats' | 'all_group_chats' | 'all_chat_administrators'
|
||||
commands: readonly TelegramCommandDefinition[]
|
||||
}
|
||||
|
||||
const DEFAULT_COMMANDS = [
|
||||
{
|
||||
command: 'help',
|
||||
description: 'Show command list'
|
||||
},
|
||||
{
|
||||
command: 'household_status',
|
||||
description: 'Show current household status'
|
||||
}
|
||||
] as const satisfies readonly TelegramCommandDefinition[]
|
||||
|
||||
const PRIVATE_CHAT_COMMANDS = [
|
||||
...DEFAULT_COMMANDS,
|
||||
{
|
||||
command: 'anon',
|
||||
description: 'Send anonymous household feedback'
|
||||
},
|
||||
{
|
||||
command: 'cancel',
|
||||
description: 'Cancel the current prompt'
|
||||
}
|
||||
] as const satisfies readonly TelegramCommandDefinition[]
|
||||
|
||||
const GROUP_CHAT_COMMANDS = DEFAULT_COMMANDS
|
||||
|
||||
const GROUP_ADMIN_COMMANDS = [
|
||||
...GROUP_CHAT_COMMANDS,
|
||||
{
|
||||
command: 'setup',
|
||||
description: 'Register this group as a household'
|
||||
},
|
||||
{
|
||||
command: 'bind_purchase_topic',
|
||||
description: 'Bind the current topic as purchases'
|
||||
},
|
||||
{
|
||||
command: 'bind_feedback_topic',
|
||||
description: 'Bind the current topic as feedback'
|
||||
},
|
||||
{
|
||||
command: 'pending_members',
|
||||
description: 'List pending household join requests'
|
||||
},
|
||||
{
|
||||
command: 'approve_member',
|
||||
description: 'Approve a pending household member'
|
||||
}
|
||||
] as const satisfies readonly TelegramCommandDefinition[]
|
||||
|
||||
export const TELEGRAM_COMMAND_SCOPES = [
|
||||
{
|
||||
scope: 'default',
|
||||
commands: DEFAULT_COMMANDS
|
||||
},
|
||||
{
|
||||
scope: 'all_private_chats',
|
||||
commands: PRIVATE_CHAT_COMMANDS
|
||||
},
|
||||
{
|
||||
scope: 'all_group_chats',
|
||||
commands: GROUP_CHAT_COMMANDS
|
||||
},
|
||||
{
|
||||
scope: 'all_chat_administrators',
|
||||
commands: GROUP_ADMIN_COMMANDS
|
||||
}
|
||||
] as const satisfies readonly ScopedTelegramCommands[]
|
||||
|
||||
export function formatTelegramHelpText(): string {
|
||||
return [
|
||||
'Household bot scaffold is live.',
|
||||
'Private chat:',
|
||||
...PRIVATE_CHAT_COMMANDS.map((command) => `/${command.command} - ${command.description}`),
|
||||
'Group admins:',
|
||||
...GROUP_ADMIN_COMMANDS.filter(
|
||||
(command) => !DEFAULT_COMMANDS.some((baseCommand) => baseCommand.command === command.command)
|
||||
).map((command) => `/${command.command} - ${command.description}`)
|
||||
].join('\n')
|
||||
}
|
||||
Reference in New Issue
Block a user