Skip to content

Conversation

@fdc310
Copy link
Member

@fdc310 fdc310 commented Nov 6, 2025

…I did not account for multiple texts and images, as well as the presence of default line breaks. Also resolved the error in Dify caused by sending only images, which resulted in an empty query.

概述 / Overview

请在此部分填写你实现/解决/优化的内容:
Summary of what you implemented/solved/optimized:

修复了因为dingtalk的api中富文本处理没有考虑多文多图的情况,以及会有默认换行符。修复了dify只发图片导致的query为空报错的问题

检查清单 / 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?

…I did not account for multiple texts and images, as well as the presence of default line breaks. Also resolved the error in Dify caused by sending only images, which resulted in an empty query.
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

❌ Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/platform/sources/dingtalk.py 0.00% 15 Missing ⚠️
pkg/provider/runners/difysvapi.py 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@RockChinQ RockChinQ requested a review from Copilot November 7, 2025 01:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds file upload support to the DingTalk integration and extends the Dify Service API runner to handle file types beyond images. The changes enable processing of rich text content with multiple elements from DingTalk and uploading various file types to Dify.

Key changes:

  • Extended Dify Service API runner to support generic file uploads alongside image uploads
  • Added rich text content parsing for DingTalk messages to maintain proper order of text and images
  • Updated file upload client to handle multiple input types (Path objects, file paths, file objects, bytes)

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

File Description
pkg/provider/runners/difysvapi.py Renamed image_ids to file_ids, added file type handling, added fallback query text for file-only messages
pkg/platform/sources/dingtalk.py Added rich content parsing with element-based processing, fallback to legacy fields, debug print statement
libs/dingtalk_api/dingtalkevent.py Added rich_content property to access Rich_Content field
libs/dify_service_api/v1/client.py Added file input preprocessing to handle Path, string paths, and file objects before upload

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 98 to 101
image_b64, image_format = await image.extract_b64_and_format(ce.image_base64)
file_bytes = base64.b64decode(image_b64)
file_upload_resp = await self.dify_client.upload_file(
file_bytes,
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file type handler is incorrectly accessing ce.image_base64 attribute. Based on the pattern from cozeapi.py line 88, file types should access ce.file attribute instead. This will cause an AttributeError when processing file content elements.

Suggested change
image_b64, image_format = await image.extract_b64_and_format(ce.image_base64)
file_bytes = base64.b64decode(image_b64)
file_upload_resp = await self.dify_client.upload_file(
file_bytes,
# Assume ce.file is a tuple: (filename, file_bytes, mimetype)
file = ce.file
file_upload_resp = await self.dify_client.upload_file(
file,

Copilot uses AI. Check for mistakes.
async for chunk in self.dify_client.chat_messages(
inputs=inputs,
query=plain_text,
query=plain_text if plain_text else "如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容",
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma in Chinese text. Should be '如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容' (comma after '文件' before '请读取').

Suggested change
query=plain_text if plain_text else "如果是可读取文件请读取此文件内容,如果是图片就描述此图片中内容",
query=plain_text if plain_text else "如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容",

Copilot uses AI. Check for mistakes.
async for chunk in self.dify_client.chat_messages(
inputs=inputs,
query=plain_text,
query=plain_text if plain_text else "如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容",
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma in Chinese text. Should be '如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容' (comma after '文件' before '请读取').

Copilot uses AI. Check for mistakes.
async for chunk in self.dify_client.chat_messages(
inputs=inputs,
query=plain_text,
query=plain_text if plain_text else "如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容",
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma in Chinese text. Should be '如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容' (comma after '文件' before '请读取').

Suggested change
query=plain_text if plain_text else "如果是可读取文件请读取此文件内容,如果是图片就描述此图片中内容",
query=plain_text if plain_text else "如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容",

Copilot uses AI. Check for mistakes.
async for chunk in self.dify_client.chat_messages(
inputs=inputs,
query=plain_text,
query=plain_text if plain_text else "如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容",
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma in Chinese text. Should be '如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容' (comma after '文件' before '请读取').

Suggested change
query=plain_text if plain_text else "如果是可读取文件请读取此文件内容,如果是图片就描述此图片中内容",
query=plain_text if plain_text else "如果是可读取文件,请读取此文件内容,如果是图片就描述此图片中内容",

Copilot uses AI. Check for mistakes.
if event.rich_content:
elements = event.rich_content.get("Elements")
for element in elements:
print(element)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement left in production code. This should be removed or replaced with proper logging.

Suggested change
print(element)
EventLogger.debug(element)

Copilot uses AI. Check for mistakes.
if event.picture:
yiri_msg_list.append(platform_message.Image(base64=event.picture))

# 处理其他类型消息(文件、音频等)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment '处理其他类型消息(文件、音频等)' is incorrectly positioned. It's inside the else block but the file/audio handling code applies to both branches (rich_content and fallback). The comment should be dedented to align with the if statement at line 58.

Suggested change
# 处理其他类型消息(文件、音频等)
# 处理其他类型消息(文件、音频等)

Copilot uses AI. Check for mistakes.
Comment on lines +115 to 132
# 处理 Path 对象
if isinstance(file, Path):
if not file.exists():
raise ValueError(f"File not found: {file}")
with open(file, "rb") as f:
file = f.read()

# 处理文件路径字符串
elif isinstance(file, str):
if not os.path.isfile(file):
raise ValueError(f"File not found: {file}")
with open(file, "rb") as f:
file = f.read()

# 处理文件对象
elif hasattr(file, 'read'):
file = file.read()
"""上传文件"""
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring '上传文件' is misplaced after the preprocessing logic. It should be placed immediately after the function signature at line 114, before any implementation code.

Copilot uses AI. Check for mistakes.
Comment on lines +202 to +203
image_placeholders = []

Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable image_placeholders is not used.

Suggested change
image_placeholders = []

Copilot uses AI. Check for mistakes.
… plan_text is empty when there is file content, and there is no file (the message could not be parsed) and the content is empty.
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants