Skip to content

fix(weixin): update parameter names for image and document senders - #8144

Closed
Astral-Yang wants to merge 1 commit into
NousResearch:mainfrom
Astral-Yang:dev_fix_weixin_sender
Closed

fix(weixin): update parameter names for image and document senders#8144
Astral-Yang wants to merge 1 commit into
NousResearch:mainfrom
Astral-Yang:dev_fix_weixin_sender

Conversation

@Astral-Yang

Copy link
Copy Markdown

Here is the English version for your PR description, tailored for a technical repository like hermes-agent.


What does this PR do?

This PR fixes a parameter mismatch in the weixin adapter. The caller (e.g., run.py) passes arguments using keywords image_path and file_path, but the function definitions in weixin.py were using a generic path parameter. This caused a TypeError: got an unexpected keyword argument during execution.

Aligning these parameter names ensures the adapter correctly handles asynchronous media uploads as intended by the orchestration layer.

Related Issue

Fixes # ## Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • adapter/weixin.py:
    • Renamed parameter path to image_path in send_image_file to match caller arguments.
    • Renamed parameter path to file_path in send_document for semantic clarity and caller alignment.
  • run.py:
    • Verified keyword arguments used in adapter.send_image_file and adapter.send_document calls match the updated definitions.

How to Test

  1. Launch the agent with the WeChat adapter enabled.
  2. Trigger a flow that generates an image (e.g., a chart or a generated asset).
  3. Trigger a flow that sends a document (e.g., a KML file or log).
  4. Expected Result: Files are uploaded and sent to the chat successfully without TypeError.

Checklist

Code

Documentation & Housekeeping

  • I've updated relevant documentation — N/A
  • I've considered cross-platform impact — N/A

Screenshots / Logs

Before Fix:

WARNING gateway.platforms.base: [Weixin] Error sending media: WeixinAdapter.send_image_file() got an unexpected keyword argument 'image_path'

After Fix:
The media message is successfully delivered to the WeChat client.

- Rename 'path' to 'image_path' in send_image_file
- Rename 'path' to 'file_path' in send_document
This aligns the function definitions with the keyword arguments used in callers(run.py).
@UlyssesWu

Copy link
Copy Markdown

I tried your fix locally. The image still failed to send🥺. Here is the error log:

WARNING gateway.platforms.base: [Weixin] Failed to send media (.jpg): 404, message='Not Found', 
url='https://novac2c.cdn.weixin.qq.com/c2c/upload?encrypted_query_param=...&filekey=...&taskid=...'

ERROR gateway.platforms.weixin: [Weixin] send_document failed to=o9cq....: 404, message='Not Found', 
url='https://novac2c.cdn.weixin.qq.com/c2c/upload?encrypted_query_param=...&filekey=...&taskid=...'

I don't know if it's a common issue or just me?

@Astral-Yang

Astral-Yang commented Apr 12, 2026

Copy link
Copy Markdown
Author

I tried your fix locally. The image still failed to send🥺. Here is the error log:

WARNING gateway.platforms.base: [Weixin] Failed to send media (.jpg): 404, message='Not Found', 
url='https://novac2c.cdn.weixin.qq.com/c2c/upload?encrypted_query_param=...&filekey=...&taskid=...'

ERROR gateway.platforms.weixin: [Weixin] send_document failed to=o9cq....: 404, message='Not Found', 
url='https://novac2c.cdn.weixin.qq.com/c2c/upload?encrypted_query_param=...&filekey=...&taskid=...'

I don't know if it's a common issue or just me?

This issue may be connected to PR #8360 and #7531. I have resolved the function call problems, but the WeChat adapter appears to have multiple remaining issues.#7531 seems also fix this parameter, so you can refer that pr.

teknium1 added a commit that referenced this pull request Apr 12, 2026
…essages

Four fixes for the Weixin/WeChat adapter, synthesized from the best
aspects of community PRs #8407, #8521, #8360, #7695, #8308, #8525,
#7531, #8144, #8251.

1. Streaming cursor (▉) stuck permanently — WeChat doesn't support
   message editing, so the cursor appended during streaming can never
   be removed.  Add SUPPORTS_MESSAGE_EDITING = False to WeixinAdapter
   and check it in gateway/run.py to use an empty cursor for non-edit
   platforms.  (Fixes #8307, #8326)

2. Media upload failures — two bugs in _send_file():
   a) upload_full_url path used PUT (404 on WeChat CDN); now uses POST.
   b) aes_key was base64(raw_bytes) but the iLink API expects
      base64(hex_string); images showed as grey boxes.  (Fixes #8352, #7529)
   Also: unified both upload paths into _upload_ciphertext(), preferring
   upload_full_url.  Added send_video/send_voice methods and voice_item
   media builder for audio/.silk files.  Added video_md5 field.

3. Markdown links stripped — WeChat can't render [text](url), so
   format_message() now converts them to 'text (url)' plaintext.
   Code blocks are preserved.  (Fixes #7617)

4. Blank message prevention — three guards:
   a) _split_text_for_weixin_delivery('') returns [] not ['']
   b) send() filters empty/whitespace chunks before _send_text_chunk
   c) _send_message() raises ValueError for empty text as safety net

Community credit: joei4cm (#8407), lyonDan (#8521), SKFDJKLDG (#8360),
tomqiaozc (#7695), joshleeeeee (#8308), luoxiao6645(#8525),
longsizhuo (#7531), Astral-Yang (#8144), QingWei-Li (#8251).
teknium1 added a commit that referenced this pull request Apr 12, 2026
…essages (#8665)

Four fixes for the Weixin/WeChat adapter, synthesized from the best
aspects of community PRs #8407, #8521, #8360, #7695, #8308, #8525,
#7531, #8144, #8251.

1. Streaming cursor (▉) stuck permanently — WeChat doesn't support
   message editing, so the cursor appended during streaming can never
   be removed.  Add SUPPORTS_MESSAGE_EDITING = False to WeixinAdapter
   and check it in gateway/run.py to use an empty cursor for non-edit
   platforms.  (Fixes #8307, #8326)

2. Media upload failures — two bugs in _send_file():
   a) upload_full_url path used PUT (404 on WeChat CDN); now uses POST.
   b) aes_key was base64(raw_bytes) but the iLink API expects
      base64(hex_string); images showed as grey boxes.  (Fixes #8352, #7529)
   Also: unified both upload paths into _upload_ciphertext(), preferring
   upload_full_url.  Added send_video/send_voice methods and voice_item
   media builder for audio/.silk files.  Added video_md5 field.

3. Markdown links stripped — WeChat can't render [text](url), so
   format_message() now converts them to 'text (url)' plaintext.
   Code blocks are preserved.  (Fixes #7617)

4. Blank message prevention — three guards:
   a) _split_text_for_weixin_delivery('') returns [] not ['']
   b) send() filters empty/whitespace chunks before _send_text_chunk
   c) _send_message() raises ValueError for empty text as safety net

Community credit: joei4cm (#8407), lyonDan (#8521), SKFDJKLDG (#8360),
tomqiaozc (#7695), joshleeeeee (#8308), luoxiao6645(#8525),
longsizhuo (#7531), Astral-Yang (#8144), QingWei-Li (#8251).
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #8665 which synthesizes the best fixes from ~25 community PRs into a single consolidated change. Your contribution (media sender parameter name updates) was reviewed and informed the final implementation. Thank you @Astral-Yang for your work on this!

@teknium1 teknium1 closed this Apr 12, 2026
@UlyssesWu

Copy link
Copy Markdown

@teknium1 Unfortunately, you didn't merge this fix correctly. The parameter path in send_image_file needs to be renamed to image_path. Sending images in Weixin still failed in v0.9.0 released today which is kind of upsetting.

I can confirm that the image-sending feature is working after manually applying this fix.

aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…essages (NousResearch#8665)

Four fixes for the Weixin/WeChat adapter, synthesized from the best
aspects of community PRs NousResearch#8407, NousResearch#8521, NousResearch#8360, NousResearch#7695, NousResearch#8308, NousResearch#8525,
NousResearch#7531, NousResearch#8144, NousResearch#8251.

1. Streaming cursor (▉) stuck permanently — WeChat doesn't support
   message editing, so the cursor appended during streaming can never
   be removed.  Add SUPPORTS_MESSAGE_EDITING = False to WeixinAdapter
   and check it in gateway/run.py to use an empty cursor for non-edit
   platforms.  (Fixes NousResearch#8307, NousResearch#8326)

2. Media upload failures — two bugs in _send_file():
   a) upload_full_url path used PUT (404 on WeChat CDN); now uses POST.
   b) aes_key was base64(raw_bytes) but the iLink API expects
      base64(hex_string); images showed as grey boxes.  (Fixes NousResearch#8352, NousResearch#7529)
   Also: unified both upload paths into _upload_ciphertext(), preferring
   upload_full_url.  Added send_video/send_voice methods and voice_item
   media builder for audio/.silk files.  Added video_md5 field.

3. Markdown links stripped — WeChat can't render [text](url), so
   format_message() now converts them to 'text (url)' plaintext.
   Code blocks are preserved.  (Fixes NousResearch#7617)

4. Blank message prevention — three guards:
   a) _split_text_for_weixin_delivery('') returns [] not ['']
   b) send() filters empty/whitespace chunks before _send_text_chunk
   c) _send_message() raises ValueError for empty text as safety net

Community credit: joei4cm (NousResearch#8407), lyonDan (NousResearch#8521), SKFDJKLDG (NousResearch#8360),
tomqiaozc (NousResearch#7695), joshleeeeee (NousResearch#8308), luoxiao6645(NousResearch#8525),
longsizhuo (NousResearch#7531), Astral-Yang (NousResearch#8144), QingWei-Li (NousResearch#8251).
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…essages (NousResearch#8665)

Four fixes for the Weixin/WeChat adapter, synthesized from the best
aspects of community PRs NousResearch#8407, NousResearch#8521, NousResearch#8360, NousResearch#7695, NousResearch#8308, NousResearch#8525,
NousResearch#7531, NousResearch#8144, NousResearch#8251.

1. Streaming cursor (▉) stuck permanently — WeChat doesn't support
   message editing, so the cursor appended during streaming can never
   be removed.  Add SUPPORTS_MESSAGE_EDITING = False to WeixinAdapter
   and check it in gateway/run.py to use an empty cursor for non-edit
   platforms.  (Fixes NousResearch#8307, NousResearch#8326)

2. Media upload failures — two bugs in _send_file():
   a) upload_full_url path used PUT (404 on WeChat CDN); now uses POST.
   b) aes_key was base64(raw_bytes) but the iLink API expects
      base64(hex_string); images showed as grey boxes.  (Fixes NousResearch#8352, NousResearch#7529)
   Also: unified both upload paths into _upload_ciphertext(), preferring
   upload_full_url.  Added send_video/send_voice methods and voice_item
   media builder for audio/.silk files.  Added video_md5 field.

3. Markdown links stripped — WeChat can't render [text](url), so
   format_message() now converts them to 'text (url)' plaintext.
   Code blocks are preserved.  (Fixes NousResearch#7617)

4. Blank message prevention — three guards:
   a) _split_text_for_weixin_delivery('') returns [] not ['']
   b) send() filters empty/whitespace chunks before _send_text_chunk
   c) _send_message() raises ValueError for empty text as safety net

Community credit: joei4cm (NousResearch#8407), lyonDan (NousResearch#8521), SKFDJKLDG (NousResearch#8360),
tomqiaozc (NousResearch#7695), joshleeeeee (NousResearch#8308), luoxiao6645(NousResearch#8525),
longsizhuo (NousResearch#7531), Astral-Yang (NousResearch#8144), QingWei-Li (NousResearch#8251).
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…essages (NousResearch#8665)

Four fixes for the Weixin/WeChat adapter, synthesized from the best
aspects of community PRs NousResearch#8407, NousResearch#8521, NousResearch#8360, NousResearch#7695, NousResearch#8308, NousResearch#8525,
NousResearch#7531, NousResearch#8144, NousResearch#8251.

1. Streaming cursor (▉) stuck permanently — WeChat doesn't support
   message editing, so the cursor appended during streaming can never
   be removed.  Add SUPPORTS_MESSAGE_EDITING = False to WeixinAdapter
   and check it in gateway/run.py to use an empty cursor for non-edit
   platforms.  (Fixes NousResearch#8307, NousResearch#8326)

2. Media upload failures — two bugs in _send_file():
   a) upload_full_url path used PUT (404 on WeChat CDN); now uses POST.
   b) aes_key was base64(raw_bytes) but the iLink API expects
      base64(hex_string); images showed as grey boxes.  (Fixes NousResearch#8352, NousResearch#7529)
   Also: unified both upload paths into _upload_ciphertext(), preferring
   upload_full_url.  Added send_video/send_voice methods and voice_item
   media builder for audio/.silk files.  Added video_md5 field.

3. Markdown links stripped — WeChat can't render [text](url), so
   format_message() now converts them to 'text (url)' plaintext.
   Code blocks are preserved.  (Fixes NousResearch#7617)

4. Blank message prevention — three guards:
   a) _split_text_for_weixin_delivery('') returns [] not ['']
   b) send() filters empty/whitespace chunks before _send_text_chunk
   c) _send_message() raises ValueError for empty text as safety net

Community credit: joei4cm (NousResearch#8407), lyonDan (NousResearch#8521), SKFDJKLDG (NousResearch#8360),
tomqiaozc (NousResearch#7695), joshleeeeee (NousResearch#8308), luoxiao6645(NousResearch#8525),
longsizhuo (NousResearch#7531), Astral-Yang (NousResearch#8144), QingWei-Li (NousResearch#8251).
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.

3 participants