fix(media): default audio files to attachment instead of voice message#517
Conversation
#516) `detectMediaTypeFromExtension` mapped audio extensions (.mp3/.wav/.ogg/.amr) to "voice" unconditionally, causing audio files sent without `asVoice=true` to be delivered as voice messages. Now `resolveOutboundMediaType` downgrades detected "voice" to "file" when `asVoice` is not set, so audio files are sent as file attachments by default. Closes #516
Greptile Summary此 PR 修复了音频文件(mp3/wav/ogg/amr)在未显式设置 Confidence Score: 5/5此 PR 可安全合并,修复逻辑正确,测试覆盖充分 修改集中在 无需特别关注的文件 Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["resolveOutboundMediaType(params)"] --> B{asVoice === true?}
B -->|Yes| C{显式 mediaType 是否合法?}
C -->|No, 不兼容| D[抛出错误]
C -->|Yes 或未设置| E{文件是否为音频?}
E -->|No| F[抛出错误]
E -->|Yes| G["返回 'voice'"]
B -->|No| H{explicitType 有值?}
H -->|Yes| I["返回 explicitType"]
H -->|No| J{detectedType === 'voice'?}
J -->|Yes| K["返回 'file' ← 新逻辑(降级为附件)"]
J -->|No| L["返回 detectedType(image/video/file)"]
Reviews (1): Last reviewed commit: "fix(media): default audio files to attac..." | Re-trigger Greptile |
| it('resolveOutboundMediaType respects explicit mediaType="voice" without asVoice', () => { | ||
| expect(resolveOutboundMediaType({ mediaPath: '/tmp/a.mp3', mediaType: 'voice', asVoice: false })).toBe('voice'); | ||
| }); |
There was a problem hiding this comment.
测试名称写作"without asVoice",但实参仍然传入了 asVoice: false,初读时容易误解为"未传 asVoice"(即参数缺省)。建议改为更能描述真实意图的描述,例如"显式 mediaType='voice' 即使 asVoice=false 也优先使用"。
| it('resolveOutboundMediaType respects explicit mediaType="voice" without asVoice', () => { | |
| expect(resolveOutboundMediaType({ mediaPath: '/tmp/a.mp3', mediaType: 'voice', asVoice: false })).toBe('voice'); | |
| }); | |
| it('resolveOutboundMediaType respects explicit mediaType="voice" even when asVoice is false', () => { | |
| expect(resolveOutboundMediaType({ mediaPath: '/tmp/a.mp3', mediaType: 'voice', asVoice: false })).toBe('voice'); | |
| }); |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Rename "without asVoice" to "even when asVoice is false" to avoid ambiguity with parameter omission vs explicit false.
|
真机测试让机器人分别以文件方式和语音方式发送mp3格式文件均生效 |
Summary
resolveOutboundMediaTypenow downgrades detected"voice"to"file"whenasVoiceis not set, so audio files (.mp3/.wav/.ogg/.amr) are sent as file attachments by defaultasVoice=trueor explicitmediaType="voice"is provided will audio files be sent as voice messagesCloses #516
Test plan
npx vitest run tests/unit/media-utils.test.ts— 27 tests passednpx vitest run— all 961 tests passedaudioAsVoice),确认收到的是文件附件而非语音消息audioAsVoice=true),确认仍然作为语音消息发送