mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-17 11:07:11 +08:00
fix(wecom_bot): revert callback image cap to 512KB (2MB inline body rejected by WeCom)
The 2MB cap (matching the long-connection upload path) does not work for the callback path: there the whole image is base64-embedded in an AES-encrypted body returned on every poll. A ~1.5MB image (base64 ~2.1MB, encrypted ~2.8MB) makes WeCom reject the finish packet and poll forever, which also surfaces as a truncated text bubble and WeCom's own timeout error. Cap well below that at 512KB so the finish packet is accepted. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -892,9 +892,12 @@ class WecomBotChannel(ChatChannel):
|
||||
if not local_path:
|
||||
return None
|
||||
|
||||
# Keep consistent with the long-connection upload path (2MB limit):
|
||||
# only compress when the image exceeds the cap, otherwise send as-is.
|
||||
callback_max_size = 2 * 1024 * 1024
|
||||
# Unlike the long-connection path (which uploads and sends only a tiny
|
||||
# media_id), the callback reply embeds the whole image as base64 inside
|
||||
# an AES-encrypted body that is returned on EVERY poll. Empirically a
|
||||
# ~1.5MB image (base64 ~2.1MB, encrypted ~2.8MB) makes WeCom reject the
|
||||
# finish packet and poll forever, so cap well below that.
|
||||
callback_max_size = 512 * 1024
|
||||
if os.path.getsize(local_path) > callback_max_size:
|
||||
compressed = self._compress_image(local_path, callback_max_size)
|
||||
if compressed:
|
||||
|
||||
Reference in New Issue
Block a user