fix: WeCom sender_name shows enterprise user ID instead of actual username#2055
Merged
fix: WeCom sender_name shows enterprise user ID instead of actual username#2055
Conversation
- 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
Member
|
@rocksclawbot review this |
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:
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)
Verdict: LGTM with the recursion fix. The rest is minor. 🦞 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述 / Overview
When using the WeCom (企业微信) integration,
sender_namein pipeline variables contained the enterprise user's ID instead of their display name. Root cause:WecomEventConverter.target2yiriwas settingFriend.nicknametostr(event.agent_id)(the application agent ID), whichpreproc.pyreads assender_name.Changes:
libs/wecom_api/api.py: Addedget_user_info(userid)toWecomClient— calls WeCom/user/getendpoint via contacts secret token, with URL encoding, token auto-refresh, and graceful error handling.pkg/platform/sources/wecom.py:WecomEventConverter.target2yirinow accepts optionalbot: WecomClientparameter; when provided, fetches the user's realnamefrom the API, falling back to user ID on failure.register_listener'son_messagecallback passesself.bottotarget2yiri.Mirrors the pattern already used in
wecomcs.py(bot.get_customer_info()).更改前后对比截图 / Screenshots
检查清单 / Checklist
PR 作者完成 / For PR author
请在方括号间写
x以打勾 / Please tick the box withx项目维护者完成 / For project maintainer
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.