No description
Find a file
2026-07-22 22:55:22 +03:00
cmd feat: relatives_repository, исправление sql инъекций, изменение типа datetime.Datetime на time.Time 2026-07-22 22:07:09 +03:00
docs feat: migrations 2026-07-13 22:37:13 +03:00
internal fix: some linter errors 2026-07-22 22:55:22 +03:00
migrations fix: ai suggessions, tests, docs 2026-07-22 22:51:08 +03:00
.golangci.yml fix: ai suggessions, tests, docs 2026-07-22 22:51:08 +03:00
config.example.yaml fix: ai suggessions, tests, docs 2026-07-22 22:51:08 +03:00
go.mod feat: migrations 2026-07-13 22:37:13 +03:00
go.sum feat: migrations 2026-07-13 22:37:13 +03:00
README.md fix: ai suggessions, tests, docs 2026-07-22 22:51:08 +03:00

Still Alive Bot

A Telegram bot that periodically polls users at a configurable interval. If a user does not respond, the bot sends alert messages to the user's pre-registered trusted contacts (relatives).

Project Structure

cmd/
  api/       — API server entrypoint
  migrator/  — Database migration tool
internal/
  app/       — Application bootstrap
  config/    — Configuration parsing and validation
  domain/    — Domain entities, repository interfaces, and errors
  repository — Repository implementations (SQLite)
migrations/  — SQL migration files (up/down)
docs/        — Documentation and diagrams

Configuration

Configuration is loaded from a YAML file (default: config.yaml). See config.example.yaml for all available options.

The bot token can be provided either in the config file (bot.token) or via the bot_token environment variable.

Migrations

Run up migrations:

go run ./cmd/migrator -config config.yaml

Run down migrations:

go run ./cmd/migrator -config config.yaml -down

Running

go run ./cmd/api -config config.yaml

Database Schema

See docs/db_schema.png for the ER diagram.

Storage Conventions

  • active — stored as INTEGER with CHECK(active IN (0, 1)); 0 = inactive, 1 = active.
  • poll_interval — stored as TEXT representing a Go time.Duration string (e.g. "5m", "1h30m").
  • last_seen, next_poll — stored as TEXT in RFC 3339 / ISO 8601 format (Go time.Time default).

Testing

go test ./internal/repository/ -v

Repository tests use an in-memory SQLite database (:memory:) created once per top-level test function via setupTestDB. Each sub-test runs inside a transaction that is rolled back in t.Cleanup, ensuring full isolation between test cases without the overhead of recreating the database schema for every test.

Repository implementations depend on the DBTX interface (satisfied by both *sql.DB and *sql.Tx), which enables this transaction-based isolation pattern.