Skip to content

feat(bot): session cleanup and SessionStep union type#34

Merged
masmuss merged 2 commits into
mainfrom
feat/bot-session-ttl
Jun 14, 2026
Merged

feat(bot): session cleanup and SessionStep union type#34
masmuss merged 2 commits into
mainfrom
feat/bot-session-ttl

Conversation

@masmuss

@masmuss masmuss commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Changes

  • Session cleanup (daily cron): New cleanUpStaleSessions() in bot.service.ts deletes bot_sessions rows where updatedAt < 24h. Scheduled at 3 AM Asia/Jakarta via node-cron.
  • Schema guard: Added .$onUpdate(() => new Date()) to botSessions.updatedAt so the timestamp auto-updates even on writes outside the session adapter.
  • SessionStep union type: Replaced step?: string with SessionStep union ('awaiting_invite' | 'title' | 'body' | 'category' | 'attachment' | 'idle') for type-safe step assignments and comparisons.
  • Bug fix: Added missing return after idle handler reply to prevent fallthrough to the generic fallback message.
  • Idle handler: Graceful message when user messages an expired session.

Files

File Change
packages/services/src/bot.service.ts New — cleanUpStaleSessions()
packages/services/src/index.ts Export cleanUpStaleSessions
packages/database/src/schema.ts .$onUpdate on updatedAt
apps/bot/src/bot.ts Cron schedule + idle step handler
apps/bot/src/types.ts SessionStep union type
apps/bot/package.json Add node-cron dep

masmuss added 2 commits June 14, 2026 19:28
- Add bot.service.ts with cleanUpStaleSessions() deleting sessions
  older than 24 hours using botSessions.updatedAt
- Add (() => new Date()) to botSessions.updatedAt in schema
- Schedule node-cron at 3 AM Asia/Jakarta for daily cleanup
- Add idle step handler with return to prevent double-reply bug
- Add node-cron dependency to bot package
- Replace step?: string with SessionStep union
- All step assignments and comparisons now type-checked
@masmuss masmuss merged commit 58ed928 into main Jun 14, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant