Skip to content

Persist iLink context tokens for proactive sends#68

Open
loccen wants to merge 1 commit intofastclaw-ai:mainfrom
loccen:fix/persist-context-token
Open

Persist iLink context tokens for proactive sends#68
loccen wants to merge 1 commit intofastclaw-ai:mainfrom
loccen:fix/persist-context-token

Conversation

@loccen
Copy link
Copy Markdown

@loccen loccen commented Apr 25, 2026

Summary

Fix proactive sends from the CLI and HTTP API by reusing the latest iLink context_token for each WeChat user.

Root Cause

The iLink sendmessage API requires every outgoing reply to include the context_token from the incoming message. WeClaw already passes that token for normal in-message replies, but proactive sends (weclaw send and POST /api/send) call the same sender helpers with an empty token.

After the server-side conversation context expires, those proactive send requests can fail with send message failed: ret=-2 errmsg=.

Changes

  • Persist the latest context_token per bot/user under the account storage directory.
  • Save the token whenever an incoming user message is handled.
  • Load the cached token automatically when proactive text or media sends do not provide one.
  • Clear cached context tokens when the iLink session expires.
  • Add unit tests for saving, loading, and clearing context tokens.

Notes

This keeps existing reply behavior unchanged while making proactive sends durable across restarts and idle periods, as long as the user has sent at least one message since the current login/session.

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.

1 participant