From 5ecf3bf0e0726b8b33682bb5c3aad9679b7b5be4 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 23 Jun 2026 14:37:56 +0530 Subject: [PATCH] fix(slack): report ext-matched audio mimetype for rerouted voice clips Follow-up to the salvaged voice-clip fix: the rerouted video/mp4 branch used {".m4a": "audio/mp4"}.get(ext, "audio/mp4"), whose sole key's value equals the default, so it always returned "audio/mp4" regardless of the cached extension (dead lookup + a throwaway dict per inbound voice clip). Replace it with a module-level _SLACK_EXT_TO_AUDIO_MIME map so the reported media_type matches the bytes we cached (e.g. a clip cached as .wav now reports audio/wav instead of audio/mp4). STT routing already keys on the audio/ prefix + cached filename extension, so behavior is unchanged; this just removes the dead construct and keeps the reported mimetype coherent. --- plugins/platforms/slack/adapter.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py index 6656e3554b4..5ef300b086f 100644 --- a/plugins/platforms/slack/adapter.py +++ b/plugins/platforms/slack/adapter.py @@ -333,6 +333,25 @@ _SLACK_STT_SUPPORTED_EXTS = frozenset( {".mp3", ".mp4", ".mpeg", ".mpga", ".m4a", ".wav", ".webm", ".ogg", ".aac", ".flac"} ) +# Cached-extension → reported ``audio/*`` mimetype. Used when re-routing a +# ``video/mp4``-mislabeled voice clip onto the audio path so the reported +# media_type stays coherent with the bytes we actually cached (the gateway's +# STT gate keys on the ``audio/`` prefix + the cached filename extension, but a +# matching mimetype avoids surprising any consumer that inspects it). Anything +# unmapped falls back to ``audio/mp4`` — Slack voice clips are MP4/AAC. +_SLACK_EXT_TO_AUDIO_MIME = { + ".mp4": "audio/mp4", + ".m4a": "audio/mp4", + ".mp3": "audio/mpeg", + ".mpeg": "audio/mpeg", + ".mpga": "audio/mpeg", + ".wav": "audio/wav", + ".webm": "audio/webm", + ".ogg": "audio/ogg", + ".aac": "audio/aac", + ".flac": "audio/flac", +} + def _resolve_slack_audio_ext(file_obj: Dict[str, Any], mimetype: str) -> str: """Pick the cache extension that matches an inbound Slack audio file's bytes. @@ -2746,7 +2765,7 @@ class SlackAdapter(BasePlatformAdapter): # Report a coherent audio mimetype matching the cached # extension so downstream STT routing recognizes it. media_types.append( - {".m4a": "audio/mp4"}.get(ext, "audio/mp4") + _SLACK_EXT_TO_AUDIO_MIME.get(ext, "audio/mp4") ) logger.debug( "[Slack] Cached voice clip (mislabeled %s) as audio: %s",