aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 5d7ddc158cdc75911eb8bb089f70b9294609a4fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# hommabot2

Rewrite of hommabot (Python3) in TS.

1. Reads Google Sheets for recurring tasks
2. Determines which tasks fall in the current week
3. Broadcasts a Telegram message to all active chats
4. Updates the "last done" column for tasks that became due

## Persistence

- Embedded SQLite (STRICT tables) auto-initialized on first run
- Single connection (read + write)

## Setup

1. Install dependencies (includes better-sqlite3):

```sh
npm install
```

2. Create/update your `.env` (minimum required):

```sh
TELEGRAM_BOT_TOKEN=...
SHEETS_SPREADSHEET_ID=...
SHEETS_RANGE=...
G_SA_JSON_B64=...          # Base64-encoded Google Service Account JSON
# Optional:
# SQLITE_PATH=./data/hommabot.db
```

3. (Optional) Seed permitted Telegram user IDs (only these can /start to register chats):

```sh
sqlite3 data/hommabot.db "INSERT OR IGNORE INTO permitted_users (id) VALUES (123456789);"
```

Repeat with additional IDs as needed.

4. (Optional) Pre-register an active chat manually (normally added via /start):

```sh
sqlite3 data/hommabot.db "INSERT OR IGNORE INTO active_chats (id) VALUES (-1001234567890);"
```

## Running

Direct TypeScript execution:

```sh
npm start
```

## Building

```sh
npm run build
```

## Automating (cron example)

Run every Monday at 08:00:

```
0 8 * * 1 /usr/bin/node /path/to/hommabot2/build/index.js >> /path/to/hommabot2/hommabot.log 2>&1
```

## Inspecting the database

```sh
sqlite3 data/hommabot.db ".tables"
sqlite3 data/hommabot.db "SELECT * FROM active_chats;"
sqlite3 data/hommabot.db "SELECT * FROM permitted_users;"
```

## Notes

- To add new permitted users at any time, insert into `permitted_users`.
- To clear active chats:

```sh
sqlite3 data/hommabot.db "DELETE FROM active_chats;"
```