@@ -215,11 +215,13 @@ async def convert_msg(
215215 dingtalk_stream .RichTextContent , message .rich_text_content
216216 )
217217 contents : list [dict ] = cast (list [dict ], rtc .rich_text_list )
218+ plain_parts : list [str ] = []
218219 for content in contents :
219- plains = ""
220220 if "text" in content :
221- plains += content ["text" ]
222- abm .message .append (Plain (plains ))
221+ plain_text = cast (str , content .get ("text" ) or "" )
222+ if plain_text :
223+ plain_parts .append (plain_text )
224+ abm .message .append (Plain (plain_text ))
223225 elif "type" in content and content ["type" ] == "picture" :
224226 download_code = cast (str , content .get ("downloadCode" ) or "" )
225227 if not download_code :
@@ -239,6 +241,7 @@ async def convert_msg(
239241 )
240242 if f_path :
241243 abm .message .append (Image .fromFileSystem (f_path ))
244+ abm .message_str = "" .join (plain_parts ).strip ()
242245 case "audio" | "voice" :
243246 download_code = cast (str , raw_content .get ("downloadCode" ) or "" )
244247 if not download_code :
@@ -629,6 +632,28 @@ async def send_message(msg_key: str, msg_param: dict) -> None:
629632 self ._safe_remove_file (cover_path )
630633 if converted_video :
631634 self ._safe_remove_file (video_path )
635+ elif isinstance (segment , File ):
636+ try :
637+ file_path = await segment .get_file ()
638+ if not file_path :
639+ logger .warning ("钉钉文件发送失败: 无法解析文件路径" )
640+ continue
641+ media_id = await self .upload_media (file_path , "file" )
642+ if not media_id :
643+ continue
644+ file_name = segment .name or Path (file_path ).name
645+ file_type = Path (file_name ).suffix .lstrip ("." )
646+ await send_message (
647+ msg_key = "sampleFile" ,
648+ msg_param = {
649+ "mediaId" : media_id ,
650+ "fileName" : file_name ,
651+ "fileType" : file_type ,
652+ },
653+ )
654+ except Exception as e :
655+ logger .warning (f"钉钉文件发送失败: { e } " )
656+ continue
632657
633658 async def send_message_chain_to_group (
634659 self ,
0 commit comments