Skip to content

fix(media): default audio files to attachment instead of voice message#517

Merged
zhumin-zizhu merged 2 commits into
mainfrom
fix/516-mp3-sent-as-voice
Apr 11, 2026
Merged

fix(media): default audio files to attachment instead of voice message#517
zhumin-zizhu merged 2 commits into
mainfrom
fix/516-mp3-sent-as-voice

Conversation

@zhumin-zizhu

@zhumin-zizhu zhumin-zizhu commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • resolveOutboundMediaType now downgrades detected "voice" to "file" when asVoice is not set, so audio files (.mp3/.wav/.ogg/.amr) are sent as file attachments by default
  • Only when asVoice=true or explicit mediaType="voice" is provided will audio files be sent as voice messages
  • Added 4 unit tests covering the fix, regression protection, and edge cases

Closes #516

Test plan

  • npx vitest run tests/unit/media-utils.test.ts — 27 tests passed
  • npx vitest run — all 961 tests passed
  • 真机验证:发送 .mp3 文件(不带 audioAsVoice),确认收到的是文件附件而非语音消息
  • 真机验证:发送 .mp3 文件(带 audioAsVoice=true),确认仍然作为语音消息发送

#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-apps

greptile-apps Bot commented Apr 10, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 修复了音频文件(mp3/wav/ogg/amr)在未显式设置 asVoice 时被意外作为语音消息发送的问题,改为默认以文件附件方式发送。修复逻辑正确地插入在 explicitType 判断之后,确保显式传入 mediaType="voice" 的场景不受影响。

Confidence Score: 5/5

此 PR 可安全合并,修复逻辑正确,测试覆盖充分

修改集中在 resolveOutboundMediaType 的一个新分支,顺序位于 explicitType 判断之后保证了向后兼容性;现有的 asVoice=true 路径未受影响;三个调用点(channel.ts×2,inbound-handler.ts×1)均已通过 asVoice 参数正确传递意图;新增 4 个单元测试覆盖主要场景且全部通过。唯一的 P2 建议仅涉及测试名称措辞,不影响正确性

无需特别关注的文件

Important Files Changed

Filename Overview
src/media-utils.ts resolveOutboundMediaType 中新增一个降级分支:当 detectedType === "voice"asVoice 为 false 且未设置显式类型时,返回 "file",逻辑顺序正确
tests/unit/media-utils.test.ts 新增 4 个测试用例,覆盖了音频降级为文件、asVoice=true 保持语音、非音频显式类型、显式 mediaType="voice" 覆盖等场景

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)"]
Loading

Reviews (1): Last reviewed commit: "fix(media): default audio files to attac..." | Re-trigger Greptile

Comment thread tests/unit/media-utils.test.ts Outdated
Comment on lines +128 to +130
it('resolveOutboundMediaType respects explicit mediaType="voice" without asVoice', () => {
expect(resolveOutboundMediaType({ mediaPath: '/tmp/a.mp3', mediaType: 'voice', asVoice: false })).toBe('voice');
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 测试名称与意图略有歧义

测试名称写作"without asVoice",但实参仍然传入了 asVoice: false,初读时容易误解为"未传 asVoice"(即参数缺省)。建议改为更能描述真实意图的描述,例如"显式 mediaType='voice' 即使 asVoice=false 也优先使用"。

Suggested change
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.
@zhumin-zizhu

zhumin-zizhu commented Apr 11, 2026

Copy link
Copy Markdown
Collaborator Author

真机测试让机器人分别以文件方式和语音方式发送mp3格式文件均生效

@zhumin-zizhu zhumin-zizhu merged commit 42d9c27 into main Apr 11, 2026
2 checks passed
@zhumin-zizhu zhumin-zizhu deleted the fix/516-mp3-sent-as-voice branch April 11, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mp3 audio file sent as voice message instead of file attachment (v3.5.3)

1 participant