Skip to content

fix(messages): show what a service message did (calls, pins, group changes) - #159

Merged
neoromantic merged 1 commit into
neoromantic:mainfrom
ertembiyik:ertembiyik/NO-TASK/service-message-actions
Nov 17, 2026
Merged

neoromantic merged 1 commit into
neoromantic:mainfrom
ertembiyik:ertembiyik/NO-TASK/service-message-actions

Conversation

@ertembiyik

Copy link
Copy Markdown
Contributor

What and why

A call, a pin or a group change is a service message. The cache stores it with message_type = 'service', no text, and the whole TL message in raw_json, but tg messages list, get and search printed nothing about what it was. An agent reading a chat could not tell that a call had happened, so it skipped those rows.

Every message item now has action, read from raw_json when the item is printed (the way attachment is), and null for any other message.

Before (tg messages get on a made-up answered call, from the e2e fixtures):

{
  "messageId": 1,
  "text": null,
  "messageType": "service",
  "hasMedia": false,
  "attachment": null
}

After, the same message:

{
  "messageId": 1,
  "text": null,
  "messageType": "service",
  "hasMedia": false,
  "attachment": null,
  "action": {
    "type": "phone_call",
    "video": false,
    "duration": 1834,
    "reason": "hangup"
  }
}

(Both are the real output with the unchanged fields left out.)

The shape:

type Other fields
phone_call video; duration in seconds, null when nobody answered; reason: missed, busy (declined), hangup, disconnect, or null
group_call duration: null when the video chat started, seconds when it ended
pin_message messageId, the pinned message
chat_create title, userIds
channel_create, chat_edit_title, topic_create title
chat_add_user, chat_delete_user, chat_joined_by_link userIds, userId, inviterId
anything else only type: the TL name in snake case without messageAction (chat_edit_photo, screenshot_taken…), so nothing is dropped

Decisions you may want to change:

  • action: null on ordinary messages, not a missing key: it matches attachment: null and gives every item one shape.
  • One naming rule for type (the TL name in snake case), for mapped and unmapped actions alike, so mapping another action later only adds fields.
  • Search does not index actions. tg messages search still finds a service message only by its text, which is empty. That can be a follow-up if you want calls to be searchable.
  • Scope: fields are mapped for calls, pins and group changes only. I'm happy to trim or extend the set.

No migration and no schema change: old caches get the field because it is read from raw_json. raw_json is now read for service rows as well as media rows.

How I checked it

  • Unit tests in src/__tests__/service-action.test.ts on made-up raw messages taken through toRawJson: an answered voice call, a video call, missed and busy calls, a call with no reason, pins with and without a reply header, group create, rename, add, remove and join by link, unmapped actions, and input that isn't a message.

  • E2E in src/__e2e__/messages.e2e.test.ts: messages list on a chat with three calls, messages get --context around a pin with a rename and an unmapped action next to it, and messages search.

  • Ran the extractor over the 124 service messages of a real cache, read-only and outside the repo: every one got a type, and all 89 calls came out with a sensible reason and duration. No real data is in the PR.

  • bun run check: clean.

  • bun run test:e2e: 369 pass, 0 fail.

  • bun run test: 2242 pass, 1 fail. The failure is cache database lock > lets several processes switch a new or folded cache to WAL at once (SQLITE_SCHEMA in configureSearchMerges); it fails the same way on an untouched main on my machine (macOS, Bun 1.4.4), and this change doesn't touch that code.

  • Tests pass locally and use made-up data only (apart from the one failure above, which main has too)

  • README, docs and affected demos follow the product content standard (docs/cli-commands.md, docs/database-schema.md, the message_type schema annotation, README and CHANGELOG)

  • Title follows the repo's commit style: Conventional Commits (feat: …, fix: …) unless AGENTS.md says otherwise

🤖 Generated with Claude Code

…anges)

A call, a pin or a group change is cached as message_type 'service' with
no text and the whole TL message in raw_json, but tg messages list, get
and search printed nothing about it. Every item now has action, read from
raw_json when the item is printed, the way attachment is, and null for any
other message. A call gives video, duration and why it ended; a pin the
pinned message; a group change the new title or the users added or
removed; any other action its type name.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@neoromantic
neoromantic merged commit a703f32 into neoromantic:main Nov 17, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants