Skip to content

feat: download and decrypt inbound WeChat CDN images#17

Open
yuxianzhao0921-del wants to merge 1 commit into
Johnixr:mainfrom
yuxianzhao0921-del:main
Open

feat: download and decrypt inbound WeChat CDN images#17
yuxianzhao0921-del wants to merge 1 commit into
Johnixr:mainfrom
yuxianzhao0921-del:main

Conversation

@yuxianzhao0921-del
Copy link
Copy Markdown

Summary

Upstream had AES-128-ECB helpers and a downloadAndDecryptMedia function but never wired them into the polling loop for inbound images. This PR closes that gap.

What's included

  • Robust parseAesKey: WeChat's inbound media.aes_key is base64-encoded hex string (32 UTF-8 chars → 16 key bytes), not raw base64 of 16 bytes. The new parser handles both formats gracefully.
  • downloadAndSaveImage: download → decrypt → detect format via magic bytes (JPEG/PNG/GIF/WebP) → save to ~/.claude/channels/wechat/images/
  • Expanded ImageItem interface: added aeskey (hex), media.full_url, and CDNMedia type to match actual inbound message structure
  • Wired into polling loop: image messages now deliver a file path ([图片: /path/to/file.jpg]) instead of just [图片]

How it works

WeChat CDN image → fetch encrypted blob → AES-128-ECB decrypt → magic bytes detect format → save to disk → pass path to Claude

Relation to PR #10

This overlaps partially with #10. Key differences:

Both approaches work. Happy to collaborate on merging the best parts if needed.

Test plan

  • Tested with real WeChat CDN images (AES-128-ECB encrypted JPEG)
  • Verified Claude can read the saved image via the Read tool
  • Confirmed backward compatibility — text messages unaffected

🤖 Generated with Claude Code

Upstream had AES-128-ECB helpers and a downloadAndDecryptMedia function
but never wired them into the polling loop for inbound images. This
commit closes that gap:

- Fix parseAesKey: WeChat's media.aes_key is base64 of a hex string
  (32 UTF-8 chars → 16 key bytes), not raw base64 of 16 bytes
- Expand ImageItem with aeskey (hex) and media.full_url fields to
  match actual inbound message structure
- Add downloadAndSaveImage: download → decrypt → detect format via
  magic bytes → save to ~/.claude/channels/wechat/images/
- Wire into polling loop: image messages now deliver a file path
  instead of just "[图片]"

Tested with real WeChat CDN images (AES-128-ECB encrypted JPEG).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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