fix: use mediaId for file reply and improve excel file payload detection
This commit is contained in:
parent
f7ffdb4233
commit
b96e333df8
@ -1488,11 +1488,14 @@ class OpenClawDingTalkBot(ChatbotHandler):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _extract_incoming_file_payload(self, callback_data: dict, msg: ChatbotMessage) -> dict:
|
def _extract_incoming_file_payload(self, callback_data: dict, msg: ChatbotMessage) -> dict:
|
||||||
if str(getattr(msg, "message_type", "")).lower() != "file":
|
|
||||||
return {}
|
|
||||||
payload = self._find_download_code_payload(callback_data)
|
payload = self._find_download_code_payload(callback_data)
|
||||||
if not payload:
|
if not payload:
|
||||||
payload = self._find_download_code_payload(getattr(msg, "extensions", {}))
|
payload = self._find_download_code_payload(getattr(msg, "extensions", {}))
|
||||||
|
if not payload:
|
||||||
|
try:
|
||||||
|
payload = self._find_download_code_payload(msg.to_dict())
|
||||||
|
except Exception:
|
||||||
|
payload = None
|
||||||
if not payload:
|
if not payload:
|
||||||
return {}
|
return {}
|
||||||
file_name = payload.get("file_name") or ""
|
file_name = payload.get("file_name") or ""
|
||||||
@ -1504,6 +1507,8 @@ class OpenClawDingTalkBot(ChatbotHandler):
|
|||||||
if file_name:
|
if file_name:
|
||||||
break
|
break
|
||||||
payload["file_name"] = self._normalize_file_name(file_name or "upload.xlsx")
|
payload["file_name"] = self._normalize_file_name(file_name or "upload.xlsx")
|
||||||
|
if not self._is_supported_excel_file(payload["file_name"]):
|
||||||
|
return {}
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
def _guess_image_ext(self, content_type: str, source_url: str) -> str:
|
def _guess_image_ext(self, content_type: str, source_url: str) -> str:
|
||||||
@ -2194,7 +2199,7 @@ class OpenClawDingTalkBot(ChatbotHandler):
|
|||||||
values = {
|
values = {
|
||||||
"msgtype": "file",
|
"msgtype": "file",
|
||||||
"file": {
|
"file": {
|
||||||
"media_id": media_id,
|
"mediaId": media_id,
|
||||||
},
|
},
|
||||||
"at": {
|
"at": {
|
||||||
"atUserIds": [msg.sender_staff_id] if msg.sender_staff_id else [],
|
"atUserIds": [msg.sender_staff_id] if msg.sender_staff_id else [],
|
||||||
@ -2479,6 +2484,13 @@ class OpenClawDingTalkBot(ChatbotHandler):
|
|||||||
incoming_file_payload = self._extract_incoming_file_payload(callback.data, msg)
|
incoming_file_payload = self._extract_incoming_file_payload(callback.data, msg)
|
||||||
has_excel_file = bool(incoming_file_payload)
|
has_excel_file = bool(incoming_file_payload)
|
||||||
conversation_key = re.sub(r"[^A-Za-z0-9_-]+", "-", str(getattr(msg, "conversation_id", "") or "default"))
|
conversation_key = re.sub(r"[^A-Za-z0-9_-]+", "-", str(getattr(msg, "conversation_id", "") or "default"))
|
||||||
|
self.logger.info(
|
||||||
|
"incoming message: type=%s has_excel_file=%s has_image=%s text_len=%s",
|
||||||
|
str(getattr(msg, "message_type", "")),
|
||||||
|
has_excel_file,
|
||||||
|
bool(incoming_image_codes),
|
||||||
|
len(text or ""),
|
||||||
|
)
|
||||||
|
|
||||||
if not text and not incoming_image_codes and not has_excel_file:
|
if not text and not incoming_image_codes and not has_excel_file:
|
||||||
return AckMessage.STATUS_OK, "ignored"
|
return AckMessage.STATUS_OK, "ignored"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user