Add /user/presence/subscribe and forward last_seen in Presence webhook#340
Merged
asternic merged 4 commits intoJul 1, 2026
Merged
Conversation
…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.
Contributor
There was a problem hiding this comment.
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.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
POST /user/presence/subscribewhich calls whatsmeow'sSubscribePresence(jid). whatsmeow only emits*events.Presencefor a contact after you subscribe, so without this there is no way to start receiving a contact's presence.fromand (when offline) alast_seenunix timestamp in thePresencewebhook payload. The event already carriesevt.LastSeen, but onlystate(online/offline) was sent to the webhook — the timestamp was logged and dropped.API.md.Why
You can already set your own presence (
/user/presence) and you receive aPresencewebhook withstate, 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
Presencewebhook only gains additional keys (from,last_seen); existing consumers are unaffected.last_seenis present only when the contact is offline and shares their last seen (privacy dependent).go build ./...,go vet ./...).