Skip to content

Commit ba7e647

Browse files
authored
Update README.md
1 parent b58cd84 commit ba7e647

1 file changed

Lines changed: 36 additions & 19 deletions

File tree

README.md

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,34 @@
22

33
# posthog-telegram
44

5-
**Streams PostHog events to Telegram in real-time.**
5+
**Forwards PostHog webhook events to Telegram in real-time.**
66

77
[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](./LICENSE)
88
[![Python](https://img.shields.io/badge/Python-3.10+-3776ab?style=flat-square&logo=python)](https://www.python.org)
9-
[![PostHog](https://img.shields.io/badge/PostHog-Events-f54e00?style=flat-square)](https://posthog.com)
9+
[![PostHog](https://img.shields.io/badge/PostHog-Webhooks-f54e00?style=flat-square)](https://posthog.com)
1010

1111
</div>
1212

1313
---
1414

15-
Polls the PostHog Events API every 30 seconds, deduplicates results, and fires one Telegram message per event. Designed to run as a systemd service on a VPS.
15+
A lightweight FastAPI webhook receiver. PostHog pushes events to `/posthog`, the service filters noise, extracts key properties, and fires a formatted message to Telegram. Designed to run as a systemd service on a VPS.
1616

1717
## Features
1818

19-
- **Real-time alerts**New events land in Telegram within 30 seconds
20-
- **Deduplication**Seen event IDs are cached so nothing fires twice
21-
- **Rich formatting**Emojis, timestamps, user IDs, and key properties per event
22-
- **vehiclefinder-aware**Ships with `query`, `make`, `model`, and `year` prop support out of the box
23-
- **Configurable**Poll interval, ignored events, and emoji map all controlled via `.env` or `bot.py`
19+
- **Webhook-driven**Zero polling; PostHog pushes events instantly
20+
- **Noise filtering**Configurable `SKIP_EVENTS` set drops web vitals, autocapture, and other noise
21+
- **Rich formatting**Site label, event name, timestamp, location, URL, and device info per message
22+
- **vehiclefinder-aware**Extracts `make`, `model`, and `year` for vehicle search events
23+
- **Fuzzy property matching**Handles inconsistent PostHog key casing and formatting automatically
2424

2525
## Stack
2626

2727
| Layer | Tech |
2828
|---|---|
2929
| Language | Python 3.10+ |
30-
| APIs | PostHog Events API, Telegram Bot API |
30+
| Web framework | FastAPI |
31+
| HTTP client | requests |
32+
| APIs | PostHog Webhooks, Telegram Bot API |
3133
| Process management | systemd |
3234
| Config | `.env` via `python-dotenv` |
3335

@@ -46,17 +48,22 @@ Fill in `.env`:
4648
```env
4749
TELEGRAM_BOT_TOKEN=...
4850
TELEGRAM_CHAT_ID=...
49-
POSTHOG_API_KEY=...
50-
POSTHOG_PROJECT_ID=...
51-
POLL_INTERVAL=30
5251
```
5352

5453
**Getting your Telegram chat ID:** message your bot, then visit `https://api.telegram.org/bot<TOKEN>/getUpdates`.
5554

5655
Run locally:
5756

5857
```bash
59-
venv/bin/python bot.py
58+
venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000
59+
```
60+
61+
### PostHog setup
62+
63+
In PostHog → **Project Settings****Webhooks**, add your endpoint:
64+
65+
```
66+
https://your-domain.com/posthog
6067
```
6168

6269
## Deployment
@@ -78,15 +85,25 @@ sudo systemctl enable --now posthog-telegram
7885
sudo journalctl -u posthog-telegram -f
7986
```
8087

88+
The service must be reachable from the internet — proxy it through nginx or Caddy on your VPS.
89+
8190
## Message Format
8291

8392
```
84-
📄 $pageview 14:32:01 UTC
85-
👤 abc12345…
86-
Current Url: https://vehiclefinder.co.nz/
87-
Browser: Chrome
88-
Os: Mac OS X
89-
Referring Domain: google.com
93+
VF · Pageview 14:32:01 UTC
94+
abc12345… · Auckland, New Zealand
95+
/stats/toyota?make=toyota
96+
Chrome · Mac OS X
97+
```
98+
99+
For vehicle search events, a vehicle line is prepended:
100+
101+
```
102+
VF · Pageview 14:32:01 UTC
103+
2018 Toyota Corolla
104+
abc12345… · Wellington, New Zealand
105+
/search
106+
Chrome · Windows
90107
```
91108

92109
---

0 commit comments

Comments
 (0)