Aftergram docs

Documentation · Aftergram 1.1

Aftergram docs

Everything Aftergram does, how to set it up, and how to run it without a window. Aftergram is a Mac app that signs in to your own Telegram as one more device and keeps a private log of incoming messages, so deleted and edited ones stay readable.

Install

  1. Download Aftergram and drag Aftergram.app to Applications. It needs macOS 13 Ventura or later on Apple silicon.
  2. Open it. The first launch starts a 7-day Pro trial; after that, Free keeps working.
  3. Follow the three sign-in steps below. Aftergram then lives in the menu bar; closing the window doesn’t stop it.

Move the app to Applications before turning on the background service: the service remembers where the app was when you installed it.

Telegram API keys

Telegram asks every app to use its own keys. You create yours once; they stay on your Mac.

  1. Go to my.telegram.org and sign in with your phone number.
  2. Open API development tools and create an application. Any name and short description will do.
  3. Copy api_id (a number) and api_hash (32 characters) into Aftergram’s first step.

Sign in

  1. Phone: in international format, e.g. +44 7700 900123.
  2. Code: Telegram sends it as a message to your other devices.
  3. Cloud password, if two-step verification is on. A wrong password can simply be retried; Start over goes back to the phone step.

Aftergram appears in Telegram → Settings → Devices as Aftergram · Mac. On first sign-in it saves the recent history of your 50 latest chats, so a message deleted from then on is caught even if it was sent before you installed Aftergram.

You can also sign in from Terminal with aftergram login. With the background service running, both the window and the command line hand the new session to the service.

Reading the log

The main window with chats, the feed and the selected message.

Chat settings

Pick a chat, then Chat settings:

Hidden chats

A hidden chat is still logged but kept out of the chat list, the feed, stats, search, export, the command line and notifications. Open them from Settings → Hidden chats, optionally behind a password (at least 4 characters, stored as a PBKDF2 hash). Closing the window locks them again.

Accounts

The account switcher.

The switcher at the top of the sidebar shows the account on view or All accounts. Its list shows each account’s connection (green: listening) and how many messages it has kept, with a search field from six accounts on, and Add account. Free listens to one account, Pro to up to ten.

Sign out (Settings → Accounts) ends the session in Telegram and removes the account; its messages stay in the log.

Media and view-once

With Pro, photos, voice and video messages, videos, audio and files up to 20 MB are downloaded as they arrive, so they stay playable after a deletion. Stickers, contacts, locations and polls are described, not downloaded. Pro

View-once media

View-once photos, videos, voice and video messages are labelled as such (View-once voice message · 0:05). Settings → Save view-once media (off by default) downloads them on arrival:

Telegram’s API terms ask apps to respect self-destructing media. Whether to keep it is your decision; that’s why the switch is off by default.

Export

Export saves what the feed shows — one chat, one account or everything, with the current filter — as .txt or .json. Pro

=== Dan K. · private chat ===
[2026-09-27 14:26:30] Dan K.: forget what I said yesterday about Alex
    ↩ reply to You: so what's the story with Alex?
    ✕ deleted 2026-09-27 14:27:13

JSON has one object per chat with its messages: id, date, sender, text, media, mediaFile, deletedAt, replyTo and versions (every version, when edited).

Settings

Private chats / GroupsDefault recording for each kind: media, deletions, edits, notifications.
Open at loginStarts in the menu bar without a window.
Background serviceRun in background, Start, Stop, Remove. See below.
Keep the Mac awakeOff, While charging, Always. A sleeping Mac can’t receive messages.
Keep regular messages for7 days (Free) up to a year (Pro). Deleted and edited messages are kept forever.
Save view-once mediaOff by default. Pro.
DataSize on disk; Show in Finder.
Postgres copyURL, Test, Turn on/off, status, Copy all local data. Pro.
Hidden chatsOpen, lock, set or remove the password.
AccountsAdd account, Sign out.

Background service

The service listens to Telegram without the window: it starts at login, restarts itself if it stops, and keeps going when you close Aftergram. Turn it on in Settings → Background service → Run in background, or:

aftergram service install   # launchd agent app.aftergram.service
aftergram status            # running? each account listening?

While it runs, the window is a viewer: it shows what the service collects and changes to settings reach the service within seconds. Signing in, adding and signing out accounts work from the window too — the window does the sign-in and restarts the service with the new session. Only one process listens at a time; the other waits.

The aftergram command is linked to ~/.local/bin/aftergram when the service is installed. If your shell doesn’t find it:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc

Command line

The app binary is also the command line: Aftergram.app/Contents/MacOS/aftergram <command>. Without a command it opens the window.

CommandWhat it does
service installRun Aftergram in the background (starts at login, restarts itself).
service start · stopStart the installed service now; stop it until the next login.
service uninstallRemove the background service. Data stays.
statusService, plan, each account’s state, the Postgres copy.
loginAdd an account, or sign back in to one whose session ended (API keys, phone, code, cloud password).
accountsList accounts.
chatsTable of logged chats: messages, deleted, edited, last message. Hidden chats are left out.
logsThe last 40 lines of the service log.
db set <url>Test and turn on the Postgres copy.
db statusIs the copy up to date; queue; last sync; URL without password.
db migrateCopy every local message to Postgres again (safe to repeat).
db offStop copying. What is in Postgres stays.
runListen in the foreground (what the service runs).

Postgres copy

Settings with the Postgres copy section.

Aftergram can mirror its log into a Postgres database you run — for SQL, scripts, Grafana or Metabase. The Mac stays the source of truth. Pro

Turn it on

Settings → Postgres copy: paste a URL, Test, Turn on. Or aftergram db set <url>. Aftergram creates its tables itself. A local database in Docker:

docker run -d --name aftergram-pg --restart unless-stopped \
  -e POSTGRES_USER=aftergram -e POSTGRES_PASSWORD=aftergram -e POSTGRES_DB=aftergram \
  -p 5432:5432 -v aftergram-pg:/var/lib/postgresql/data postgres:17

aftergram db set postgres://aftergram:aftergram@localhost:5432/aftergram

Hosted Postgres works too; TLS is used when the server offers it, and ?sslmode=require insists on it.

How it syncs

Tables

messages
account, scope, msg_idPrimary key. account is your Telegram user id; scope is 0 for private chats and basic groups, the channel id for supergroups.
chat_id, chat_title, chat_kindChat (user or group).
sender_id, sender_nameWho sent it.
date, textUnix seconds; current text.
media_kind, media_label, media_pathMedia type, label, file on the Mac.
deleted_atWhen it disappeared from the chat, or null.
edit_count, last_edit_atEdits.
reply_to, reply_sender, reply_textThe message it answered, as it was then.
synced_atWhen Postgres last got this row.

edits(account, scope, msg_id, at, text) holds every version of edited messages, the original first. aftergram_meta holds the schema version.

Example queries

-- what was deleted this week
SELECT chat_title, sender_name, text, to_timestamp(deleted_at) AS deleted
FROM messages WHERE deleted_at > extract(epoch FROM now() - interval '7 days')
ORDER BY deleted_at DESC;

-- every version of edited messages
SELECT m.chat_title, e.text, to_timestamp(e.at) AS at
FROM edits e JOIN messages m USING (account, scope, msg_id)
ORDER BY m.date, e.at;

-- who deletes the most
SELECT sender_name, count(*) FROM messages
WHERE deleted_at IS NOT NULL GROUP BY 1 ORDER BY 2 DESC LIMIT 10;

Where data lives

Everything is in ~/Library/Application Support/app.aftergram.mac/, readable only by your macOS account:

aftergram.dbThe log (SQLite).
media/Downloaded media.
accounts/<slot>/session.dbEach account’s Telegram session.
config.jsonAPI keys, settings, per-chat rules, Pro key, Postgres URL.
service/Service status, service.log, Postgres copy status.

There is no Aftergram server. Nothing is sent anywhere except Telegram itself and, if you set one up, your own Postgres.

Plans and licence

Every install starts with 7 days of Pro. Free then keeps catching deletions and edits for one account with 7 days of history. Pro is a one-time $19 key for all your Macs: up to 10 accounts, up to a year of history, media and view-once media, per-chat settings, export and the Postgres copy. Enter the key in Settings → Upgrade; it is checked on your Mac, offline.

Troubleshooting

“needs sign-in” in aftergram status

Telegram ended the session (for example, it was terminated in Devices). Sign in again from the window or with aftergram login; the log is kept.

Nothing arrives after the Mac slept

Aftergram reconnects by itself after sleep and fetches what arrived meanwhile. A message sent and deleted during sleep can’t be caught; set Keep the Mac awake → While charging.

aftergram: command not found

Add ~/.local/bin to your PATH (see Background service), or use the full path to the app binary.

Postgres says “stopped”

The URL, password or permissions are wrong. aftergram db status shows the server’s message; fix it with aftergram db set <url>.

More detail

aftergram logs shows the service log; aftergram status shows each account and the Postgres copy.

Uninstall

aftergram service uninstall                       # if you used the service
rm -rf ~/Library/Application\ Support/app.aftergram.mac   # deletes the whole log

Then move Aftergram.app to the Bin and remove Aftergram · Mac from Telegram → Settings → Devices.