Repository navigation
Conversation
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.
问题描述
当用户在钉钉客户端发送带有附件(如图片+文字说明)的消息时,钉钉回调下发的消息类型为
msgtype: "richText"。根据钉钉回调协议及真实消息样本:text字段仅在msgtype == "text"时存在,richText消息的正文与附件均位于content.richText数组中。content.richText数组中的图片/文件等附件节点带有"type": "picture"/"type": "file",但普通文本节点仅包含{"text": "..."},不携带{"type": "text"}字段:{ "msgtype": "richText", "content": { "richText": [ { "pictureDownloadCode": "EJiwxxxxx", "downloadCode": "mIoxxxxx", "type": "picture" }, { "text": "\n" }, { "text": "请解释下" } ] } }此前
convert_rich_text仅在item.get("type", "") == "text"时提取文本,导致真实richText消息中的文本段落被全部忽略,最终归一化后的IncomingMessage.text为空字符串""。修改内容
src/dingtalk_channel_sdk/normalize/converters/richtext.py:item_type in ("", "text")(item_type = item.get("type") or ""),同时兼容钉钉真实回调中缺省type字段的文本段与显式指定"type": "text"的场景。content.get("richText")增加isinstance(..., list)防御性校验。tests/test_normalize_converters.py:新增test_convert_rich_text_without_type_field,覆盖无type文本段与图片/文件混排解析。tests/test_message.py:新增test_normalize_richtext_with_attachment_without_text_type,覆盖群聊@剥离及单聊真实样本的IncomingMessage归一化验证。测试验证
pytest全量单测(140 passed)全部通过。Details
单纯图片
没有文字说明
{ "senderPlatform": "Win", "conversationId": "cidXxxxxx=", "chatbotCorpId": "dingxxxxxx", "chatbotUserId": "$:LWCP_v1:$xXxxxx", "openThreadId": "cidXxxxxx=", "msgId": "msgXxxx", "senderNick": "Xxxxx", "isAdmin": true, "senderStaffId": "0000000000-1234334534", "sessionWebhookExpiredTime": 1792293932778, "createAt": 1792288532437, "content": { "pictureDownloadCode": "EJixxxxx", "downloadCode": "mIoxxxxxxx" }, "senderCorpId": "dingxxxxxx", "conversationType": "1", "senderId": "$:LWCP_v1:$Xxxxxx", "sessionWebhook": "https://oapi.dingtalk.com/robot/sendBySession?session=xxxxfsdfsdfsdfsdfessxxxxxx", "robotCode": "dingjgxxxxxxxxxxxxxxx", "msgtype": "picture" }纯文本消息
{ "senderPlatform": "Win", "conversationId": "cidXxxxxx=", "chatbotCorpId": "dingxxxxxx", "chatbotUserId": "$:LWCP_v1:$xXxxxx", "openThreadId": "cidXxxxxx=", "msgId": "msgXxxx", "senderNick": "Xxxxx", "isAdmin": true, "senderStaffId": "0000000000-1234334534", "sessionWebhookExpiredTime": 1792293989877, "createAt": 1792288589651, "senderCorpId": "dingxxxxxx", "conversationType": "1", "senderId": "$:LWCP_v1:$Xxxxxx", "sessionWebhook": "https://oapi.dingtalk.com/robot/sendBySession?session=xxxxfsdfsdfsdfsdfessxxxxxx", "text": { "content": "你好" }, "robotCode": "dingjgxxxxxxxxxxxxxxx", "msgtype": "text" }图片加文字说明
{ "senderPlatform": "Win", "conversationId": "cidXxxxxx=", "chatbotCorpId": "dingxxxxxx", "chatbotUserId": "$:LWCP_v1:$xXxxxx", "openThreadId": "cidXxxxxx=", "msgId": "msgsXxxxxxx", "senderNick": "Xxxxx", "isAdmin": true, "senderStaffId": "0000000000-1234334534", "sessionWebhookExpiredTime": 1792294060566, "createAt": 1792288660182, "content": { "richText": [ { "pictureDownloadCode": "EJiwxxxxx", "downloadCode": "mIoxxxxx", "type": "picture" }, { "text": "\n" }, { "text": "请解释下" } ] }, "senderCorpId": "dingxxxxxx", "conversationType": "1", "senderId": "$:LWCP_v1:$Xxxxxx", "sessionWebhook": "https://oapi.dingtalk.com/robot/sendBySession?session=xxxxfsdfsdfsdfsdfessxxxxxx", "robotCode": "dingjgxxxxxxxxxxxxxxx", "msgtype": "richText" }单纯文件
{ "senderPlatform": "Win", "conversationId": "cidXxxxxx=", "chatbotCorpId": "dingxxxxxx", "chatbotUserId": "$:LWCP_v1:$xXxxxx", "openThreadId": "cidXxxxxx=", "msgId": "msgsxxxxx", "senderNick": "Xxxxx", "isAdmin": true, "senderStaffId": "0000000000-1234334534", "sessionWebhookExpiredTime": 1792294174165, "createAt": 1792288773932, "content": { "spaceId": "1111111111111", "fileName": "xxxxx.mp3", "downloadCode": "j7mg+lxxxxxxx", "fileId": "222222222222" }, "senderCorpId": "dingxxxxxx", "conversationType": "1", "senderId": "$:LWCP_v1:$Xxxxxx", "sessionWebhook": "https://oapi.dingtalk.com/robot/sendBySession?session=xxxxfsdfsdfsdfsdfessxxxxxx", "robotCode": "dingjgxxxxxxxxxxxxxxx", "msgtype": "file" }