Skip to content

Add /user/presence/subscribe and forward last_seen in Presence webhook#340

Merged
asternic merged 4 commits into
asternic:mainfrom
Flow-Mind-Company:feat/presence-last-seen-webhook
Jul 1, 2026
Merged

Add /user/presence/subscribe and forward last_seen in Presence webhook#340
asternic merged 4 commits into
asternic:mainfrom
Flow-Mind-Company:feat/presence-last-seen-webhook

Conversation

@Flow-Mind-Company

Copy link
Copy Markdown
Contributor

What

  • Add POST /user/presence/subscribe which calls whatsmeow's SubscribePresence(jid). whatsmeow only emits *events.Presence for a contact after you subscribe, so without this there is no way to start receiving a contact's presence.
  • Forward from and (when offline) a last_seen unix timestamp in the Presence webhook payload. The event already carries evt.LastSeen, but only state (online/offline) was sent to the webhook — the timestamp was logged and dropped.
  • Document both in API.md.

Why

You can already set your own presence (/user/presence) and you receive a Presence webhook with state, but there is no way to (a) subscribe to a specific contact's presence, nor (b) get their last-seen time. These two small additions make "last seen / online status" usable by API consumers.

Notes

  • Backwards compatible: the Presence webhook only gains additional keys (from, last_seen); existing consumers are unaffected.
  • last_seen is present only when the contact is offline and shares their last seen (privacy dependent).
  • Reciprocity: you must be online to receive presence; wuzapi already sends an available presence on connect.
  • Builds clean (go build ./..., go vet ./...).

…webhook

The Presence event already carries the contact's LastSeen, but only the state
(online/offline) was forwarded to the webhook. This adds "from" and, when the
contact is offline and shares it, a "last_seen" unix timestamp to the Presence
webhook payload.

Also adds POST /user/presence/subscribe which calls whatsmeow's
SubscribePresence(jid), so clients can opt in to receive Presence events for a
specific contact (whatsmeow only emits them after subscribing).

Docs added to API.md.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new endpoint /user/presence/subscribe to subscribe to a contact's presence updates, updating the handlers, routes, event handler, and API documentation. Feedback on the changes includes using the request context r.Context() instead of context.Background() in the HTTP handler to ensure proper request cancellation, and correcting a typo in the success response message.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread handlers.go Outdated
Comment thread handlers.go Outdated
asternic and others added 3 commits July 1, 2026 13:29
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@asternic
asternic merged commit 7064214 into asternic:main Jul 1, 2026
1 check 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