fix(signal): use media_urls/media_types instead of non-existent image_paths/audio_path/document_paths
The Signal adapter was passing image_paths, audio_path, and document_paths to MessageEvent.__init__(), but those fields don't exist on the dataclass. MessageEvent uses media_urls (List[str]) and media_types (List[str]). Changes: - Replace separate image_paths/audio_path/document_paths with unified media_urls and media_types lists (matching Discord, Slack, etc.) - Add _ext_to_mime() helper to map file extensions to MIME types - Use Signal's contentType from attachment metadata when available, falling back to extension-based mapping - Update message type detection to check media_types prefixes Fixes TypeError: MessageEvent.__init__() got an unexpected keyword argument 'image_paths'
This commit is contained in:
parent
8eefbef91c
commit
d04b9f4dc5
1 changed files with 28 additions and 17 deletions
|
|
@ -104,6 +104,20 @@ def _is_audio_ext(ext: str) -> bool:
|
||||||
return ext.lower() in (".mp3", ".wav", ".ogg", ".m4a", ".aac")
|
return ext.lower() in (".mp3", ".wav", ".ogg", ".m4a", ".aac")
|
||||||
|
|
||||||
|
|
||||||
|
_EXT_TO_MIME = {
|
||||||
|
".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png",
|
||||||
|
".gif": "image/gif", ".webp": "image/webp",
|
||||||
|
".ogg": "audio/ogg", ".mp3": "audio/mpeg", ".wav": "audio/wav",
|
||||||
|
".m4a": "audio/mp4", ".aac": "audio/aac",
|
||||||
|
".mp4": "video/mp4", ".pdf": "application/pdf", ".zip": "application/zip",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _ext_to_mime(ext: str) -> str:
|
||||||
|
"""Map file extension to MIME type."""
|
||||||
|
return _EXT_TO_MIME.get(ext.lower(), "application/octet-stream")
|
||||||
|
|
||||||
|
|
||||||
def _render_mentions(text: str, mentions: list) -> str:
|
def _render_mentions(text: str, mentions: list) -> str:
|
||||||
"""Replace Signal mention placeholders (\\uFFFC) with readable @identifiers.
|
"""Replace Signal mention placeholders (\\uFFFC) with readable @identifiers.
|
||||||
|
|
||||||
|
|
@ -404,9 +418,8 @@ class SignalAdapter(BasePlatformAdapter):
|
||||||
|
|
||||||
# Process attachments
|
# Process attachments
|
||||||
attachments_data = data_message.get("attachments", [])
|
attachments_data = data_message.get("attachments", [])
|
||||||
image_paths = []
|
media_urls = []
|
||||||
audio_path = None
|
media_types = []
|
||||||
document_paths = []
|
|
||||||
|
|
||||||
if attachments_data and not getattr(self, "ignore_attachments", False):
|
if attachments_data and not getattr(self, "ignore_attachments", False):
|
||||||
for att in attachments_data:
|
for att in attachments_data:
|
||||||
|
|
@ -420,12 +433,10 @@ class SignalAdapter(BasePlatformAdapter):
|
||||||
try:
|
try:
|
||||||
cached_path, ext = await self._fetch_attachment(att_id)
|
cached_path, ext = await self._fetch_attachment(att_id)
|
||||||
if cached_path:
|
if cached_path:
|
||||||
if _is_image_ext(ext):
|
# Use contentType from Signal if available, else map from extension
|
||||||
image_paths.append(cached_path)
|
content_type = att.get("contentType") or _ext_to_mime(ext)
|
||||||
elif _is_audio_ext(ext):
|
media_urls.append(cached_path)
|
||||||
audio_path = cached_path
|
media_types.append(content_type)
|
||||||
else:
|
|
||||||
document_paths.append(cached_path)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Signal: failed to fetch attachment %s", att_id)
|
logger.exception("Signal: failed to fetch attachment %s", att_id)
|
||||||
|
|
||||||
|
|
@ -440,11 +451,12 @@ class SignalAdapter(BasePlatformAdapter):
|
||||||
chat_id_alt=group_id if is_group else None,
|
chat_id_alt=group_id if is_group else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Determine message type
|
# Determine message type from media
|
||||||
msg_type = MessageType.TEXT
|
msg_type = MessageType.TEXT
|
||||||
if audio_path:
|
if media_types:
|
||||||
|
if any(mt.startswith("audio/") for mt in media_types):
|
||||||
msg_type = MessageType.VOICE
|
msg_type = MessageType.VOICE
|
||||||
elif image_paths:
|
elif any(mt.startswith("image/") for mt in media_types):
|
||||||
msg_type = MessageType.IMAGE
|
msg_type = MessageType.IMAGE
|
||||||
|
|
||||||
# Parse timestamp from envelope data (milliseconds since epoch)
|
# Parse timestamp from envelope data (milliseconds since epoch)
|
||||||
|
|
@ -462,9 +474,8 @@ class SignalAdapter(BasePlatformAdapter):
|
||||||
source=source,
|
source=source,
|
||||||
text=text or "",
|
text=text or "",
|
||||||
message_type=msg_type,
|
message_type=msg_type,
|
||||||
image_paths=image_paths,
|
media_urls=media_urls,
|
||||||
audio_path=audio_path,
|
media_types=media_types,
|
||||||
document_paths=document_paths,
|
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue