Repository navigation
Report the logged-in user and emit login and logout - #10
Merged
Merged
Conversation
The login event still fires as soon as the phone confirms, with the account's username. A background profile lookup then gives contactPayload(currentUserId) the nickname as name and the WeChat ID as weixin, falling back to the WeChat ID or username if it fails. The example prints "Logged in as <name>". Each session now emits logout exactly once: - stop(): "puppet stop()" - logout(reason): submits WeChat's logout request once, then emits the reason - WeChat rejects heartbeat or sync with -13 and rejects one automatic renewal: "WeChat ended the session", with no error event - any other failure after login: an error event, then "Neo session failed" Before, a session WeChat had ended only emitted error and left isLoggedIn true. A closed notification socket now reconnects once and lets a heartbeat decide. Stopping closes the native session so its credentials are released right away. The example's error handler read the deprecated data field, which wechaty-puppet always replaces with gerror. It now prints the gerror message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thisnick
force-pushed
the
feat/login-identity-logout
branch
from
November 10, 2026 22:26
789f4db to
b9e35fb
Compare
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.
Implements the three features Huan asked for before the first npm release: current-user information, the
loginevent and thelogoutevent. Builds on #9 (Node.js 26).Current user
loginstill fires as soon as the phone confirms, with the account's username. A background profile lookup (one contact request for our own username) then givescontactPayload(currentUserId):nameweixin, when setLogin never waits for the lookup and can't fail because of it. If the lookup fails,
namefalls back to the WeChat ID, then to the username. The example printsLogged in as <name>.Logout
Each session emits
logoutexactly once:stop()puppet stop()logout(reason): submits WeChat's logout request once (prepare_logout().submit()), then emits-13and also rejects one automatic renewal, e.g. after a sign-out from the phoneWeChat ended the session, with noerrorerrorevent, thenNeo session failedBefore this, a session WeChat had ended only emitted
errorand leftisLoggedIntrue.Other changes:
stop()now closes the native session, so its credentials are released right away.Spotting
-13matches error text, the same rule the agent-wechat daemon uses.PendingLogout::submitis async-only, so the addon builds a single-thread tokio runtime just for that call. thisnick/agent-wechat#455 tracks typed errors and a blocking logout in wechat-protocol, so both can be swapped out later.Example fix
The example's error handler read
data, but wechaty-puppet always rewrites error events to{ gerror }, so it printedundefined. It now prints thegerrormessage.Validation
Offline:
-13detection and session close.npm testandnpm run test:packageon Node 26: 7 tests, 4 of them new. They cover login before the profile, the nickname and fallback names, and one logout each for stop,logout(), a session WeChat ended, and an unexpected failure.Live, on Linux x64 with an isolated test account:
loginimmediately.contactPayload()returned the account's nickname and avatar about 1.2 s later.dingwas answered withdong.logoutwith reasonWeChat ended the sessionand noerror.The bot-side
logout()path, which submits WeChat's logout request, is covered by the scripted tests but hasn't been run against WeChat yet.The spec's acceptance steps, the release-gate table and the README now describe this lifecycle.
🤖 Generated with Claude Code