Skip to content

fix: WeCom sender_name shows enterprise user ID instead of actual username#2055

Merged
wangcham merged 3 commits intomasterfrom
copilot/fix-sender-name-parameter
Mar 23, 2026
Merged

fix: WeCom sender_name shows enterprise user ID instead of actual username#2055
wangcham merged 3 commits intomasterfrom
copilot/fix-sender-name-parameter

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

概述 / Overview

When using the WeCom (企业微信) integration, sender_name in pipeline variables contained the enterprise user's ID instead of their display name. Root cause: WecomEventConverter.target2yiri was setting Friend.nickname to str(event.agent_id) (the application agent ID), which preproc.py reads as sender_name.

Changes:

  • libs/wecom_api/api.py: Added get_user_info(userid) to WecomClient — calls WeCom /user/get endpoint via contacts secret token, with URL encoding, token auto-refresh, and graceful error handling.
  • pkg/platform/sources/wecom.py:
    • WecomEventConverter.target2yiri now accepts optional bot: WecomClient parameter; when provided, fetches the user's real name from the API, falling back to user ID on failure.
    • register_listener's on_message callback passes self.bot to target2yiri.

Mirrors the pattern already used in wecomcs.py (bot.get_customer_info()).

更改前后对比截图 / Screenshots

修改前 / Before:
sender_name = "wangwu123" (user ID)

修改后 / After:
sender_name = "王五" (actual display name from WeCom contacts API)

检查清单 / Checklist

PR 作者完成 / For PR author

请在方括号间写x以打勾 / Please tick the box with x

  • 阅读仓库贡献指引了吗? / Have you read the contribution guide?
  • 与项目所有者沟通过了吗? / Have you communicated with the project maintainer?
  • 我确定已自行测试所作的更改,确保功能符合预期。 / I have tested the changes and ensured they work as expected.

项目维护者完成 / For project maintainer

  • 相关 issues 链接了吗? / Have you linked the related issues?
  • 配置项写好了吗?迁移写好了吗?生效了吗? / Have you written the configuration items? Have you written the migration? Has it taken effect?
  • 依赖加到 pyproject.toml 和 core/bootutils/deps.py 了吗 / Have you added the dependencies to pyproject.toml and core/bootutils/deps.py?
  • 文档编写了吗? / Have you written the documentation?
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: 集成企微的时候,参数sender_name的值为企业用户的Id</issue_title>
<issue_description>### 运行环境

v4.6.5

异常情况

集成企微的时候,参数sender_name的值为企业用户的Id

复现步骤

No response

启用的插件

No response</issue_description>

<agent_instructions>现在已经在刚刚的pr加了企微用户名称传到流水线的实现,请你看一下这里可以传到query.variables里的sender_name里了吗</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Add get_user_info() to WecomClient to fetch user name via /user/get API
- Update WecomEventConverter.target2yiri to accept bot param and fetch real user name
- Update register_listener call to pass self.bot for user name lookup
- URL-encode userid parameter for safety

Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix sender_name parameter to use user name instead of ID fix: WeCom sender_name shows enterprise user ID instead of actual username Mar 11, 2026
@RockChinQ RockChinQ marked this pull request as ready for review March 11, 2026 18:07
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. eh: Improve enhance: 现有功能的改进 / improve current features IM: wecom 企业微信 适配器相关 / WeCom and WeComCS adapter related m: Platform 机器人管理相关 / Bots management labels Mar 11, 2026
@RockChinQ RockChinQ requested a review from wangcham March 12, 2026 13:51
@RockChinQ
Copy link
Member

@rocksclawbot review this

@rocksclawbot
Copy link
Contributor

Review findings:

Overall: Approach is correct — fetching user info from WeCom contacts API to get the actual username instead of agent_id. Code follows existing patterns.

Issues found:

  1. Potential infinite recursion in get_user_info() (api.py): If get_access_token() succeeds but the refreshed token still returns errcode 40014/42001, this recurses forever. Suggest adding a _retried=False parameter:
async def get_user_info(self, userid: str, _retried: bool = False) -> dict:
    ...
    if not _retried and data.get("errcode") in (40014, 42001):
        self.access_token_for_contacts = await self.get_access_token(self.secret_for_contacts)
        return await self.get_user_info(userid, _retried=True)
  1. Pre-existing bug (not from this PR): get_users() at L71/L92 calls async def check_access_token_for_contacts() without await — the check always passes since a coroutine object is truthy. Your new code at L80 correctly uses await 👍

  2. Silent exception swallowing (wecom.py L175): except Exception: pass hides errors. Consider at least a debug-level log.

  3. Minor: quote(userid) import is good defensive coding.

Verdict: LGTM with the recursion fix. The rest is minor. 🦞

@wangcham wangcham merged commit 88a04fd into master Mar 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eh: Improve enhance: 现有功能的改进 / improve current features IM: wecom 企业微信 适配器相关 / WeCom and WeComCS adapter related m: Platform 机器人管理相关 / Bots management size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 集成企微的时候,参数sender_name的值为企业用户的Id

4 participants