feat(bot): add safe group unsetup flow

This commit is contained in:
2026-03-11 06:08:34 +04:00
parent 1b8c6e87f6
commit b6b6f9e1b8
25 changed files with 495 additions and 0 deletions

View File

@@ -41,6 +41,23 @@ export interface HouseholdSetupService {
reason: 'not_admin' | 'household_not_found' | 'not_topic_message'
}
>
unsetupGroupChat(input: {
actorIsAdmin: boolean
telegramChatId: string
telegramChatType: string
}): Promise<
| {
status: 'reset'
household: HouseholdTelegramChatRecord
}
| {
status: 'noop'
}
| {
status: 'rejected'
reason: 'not_admin' | 'invalid_chat_type'
}
>
}
function isSupportedGroupChat(chatType: string): boolean {
@@ -146,6 +163,36 @@ export function createHouseholdSetupService(
household,
binding
}
},
async unsetupGroupChat(input) {
if (!input.actorIsAdmin) {
return {
status: 'rejected',
reason: 'not_admin'
}
}
if (!isSupportedGroupChat(input.telegramChatType)) {
return {
status: 'rejected',
reason: 'invalid_chat_type'
}
}
const household = await repository.getTelegramHouseholdChat(input.telegramChatId)
if (!household) {
return {
status: 'noop'
}
}
await repository.clearHouseholdTopicBindings(household.householdId)
return {
status: 'reset',
household
}
}
}
}