Skip to content

fix: align iLink API with Python SDK (#14)#15

Merged
crrow merged 6 commits intomainfrom
issue-14-align-ilink-api
Mar 25, 2026
Merged

fix: align iLink API with Python SDK (#14)#15
crrow merged 6 commits intomainfrom
issue-14-align-ilink-api

Conversation

@crrow
Copy link
Copy Markdown
Contributor

@crrow crrow commented Mar 25, 2026

Summary

  • api.rs: Fix HTTP methods (GET for QR endpoints), timeouts (35s/15s/10s), headers (base64 UIN, base_info), merge send_text/media into send_message, full get_upload_url payload, add get_config
  • media.rs: Fix download URL pattern (encrypted_query_param), per-type field extraction (image/voice/file/video), full upload flow with MD5/filekey/retry, parse_aes_key supports base64
  • runtime.rs: Fix message type constants (1-based: TEXT=1, IMAGE=2, VOICE=3, FILE=4, VIDEO=5), find_media_item with priority, per-type outgoing format, typing cancel, error reply to user
  • bot.rs: QR code retry (up to 3 refreshes, 480s deadline), normalize_account_id
  • storage.rs: Env var state dir, sync.json format, global openclaw.json config, chmod 600

Test plan

  • 60 unit tests pass
  • clippy clean (-D warnings)
  • Examples build (echo_bot, openai_bot)
  • CI green

Closes #14

🤖 Generated with Claude Code

@crrow crrow added the bug Something isn't working label Mar 25, 2026
crrow and others added 6 commits March 25, 2026 20:19
Required for aligning media upload flow (MD5 hash) and CDN URL
construction (encrypted_query_param encoding) with Python SDK.

Closes #14
- State dir resolution: check $OPENCLAW_STATE_DIR → $CLAWDBOT_STATE_DIR → ~/.openclaw
- Add normalize_account_id() and derive_raw_account_id() public functions
- Change sync buf format from plain text to JSON in accounts/{id}.sync.json
- Change get_account_config to read from global {state_dir}/openclaw.json
- Add chmod 600 on Unix for save_account_data
- Add tests for normalization, sync buf format, and global config parsing

Closes #14

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add constants: DEFAULT_LONG_POLL_TIMEOUT, DEFAULT_API_TIMEOUT,
  DEFAULT_CONFIG_TIMEOUT, DEFAULT_ILINK_BOT_TYPE, SDK_VERSION
- Fix headers(): base64-encoded random u32 for X-WECHAT-UIN,
  content-type header, skip auth when token empty
- Add base_info with SDK version to all POST payloads
- Extract check_response() to check both errcode and ret fields
- Add GET helper (get_with_timeout) for QR code endpoints
- Change fetch_qr_code to GET with bot_type query param
- Change get_qr_code_status to GET with iLink-App-ClientVersion header
- Fix get_updates timeout to 35s (long poll)
- Merge send_text_message + send_media_message into send_message
- Fix send_typing to include typing_status, use 10s timeout
- Fix get_upload_url to accept full media metadata
- Add get_config endpoint
- Update callers in runtime.rs, bot.rs, media.rs for new signatures

Closes #14

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add constants UPLOAD_MEDIA_IMAGE/VIDEO/FILE/VOICE and MAX_UPLOAD_RETRIES
- Rewrite parse_aes_key to support base64-encoded keys (raw 16-byte or hex)
- Add aes_ecb_padded_size helper
- Change download_media to use encrypted_query_param URL pattern with subdir
- Add download_media_from_item for per-type field extraction (image/voice/file/video)
- Rewrite upload_media with full Python SDK flow: random filekey, CDN POST,
  x-encrypted-param header extraction, retry logic, UploadResult struct
- Update runtime.rs call sites minimally to compile (Task 5 will fix properly)
- Add tests for base64 key parsing and padded size calculation

Closes #14

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Switch to 1-based message type constants
- Rewrite body_from_item_list for ref_msg
- Add find_media_item with priority order
- Add build_media_send_item per-type format
- Replace to_user_id with from_user_id
- Split text and media into separate sends
- Forward error text to user on failure
- Add typing cancel after response
- Sleep 1 hour on session expiry
- Extract send_outgoing_media helper
- Update all tests for new type values

Closes #14

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add QR code retry loop: outer loop refreshes QR (up to 3 times),
  inner loop polls status, with 480s global deadline
- Handle response fields at root or nested under "data"
- Accept both "scanned" and "scaned" status variants
- Use storage::normalize_account_id() for account ID normalization

Closes #14
@crrow crrow force-pushed the issue-14-align-ilink-api branch from c6d8e7b to ce54599 Compare March 25, 2026 11:21
@crrow crrow merged commit febdabe into main Mar 25, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: align iLink API with Python SDK (frostming/weixin-agent-sdk)

1 participant