1- import { getFileExtension } from "./mime.js" ;
1+ import { getFileExtension , normalizeMimeType } from "./mime.js" ;
22
3- const VOICE_AUDIO_EXTENSIONS = new Set ( [ ".oga" , ".ogg" , ".opus" , ".mp3" , ".m4a" ] ) ;
3+ export const TELEGRAM_VOICE_AUDIO_EXTENSIONS = new Set ( [ ".oga" , ".ogg" , ".opus" , ".mp3" , ".m4a" ] ) ;
44
55/**
66 * MIME types compatible with voice messages.
77 * Telegram sendVoice supports OGG/Opus, MP3, and M4A.
88 * https://core.telegram.org/bots/api#sendvoice
99 */
10- const VOICE_MIME_TYPES = new Set ( [
10+ export const TELEGRAM_VOICE_MIME_TYPES = new Set ( [
1111 "audio/ogg" ,
1212 "audio/opus" ,
1313 "audio/mpeg" ,
@@ -17,16 +17,13 @@ const VOICE_MIME_TYPES = new Set([
1717 "audio/m4a" ,
1818] ) ;
1919
20- export function isVoiceCompatibleAudio ( opts : {
20+ export function isTelegramVoiceCompatibleAudio ( opts : {
2121 contentType ?: string | null ;
2222 fileName ?: string | null ;
2323} ) : boolean {
24- const mime = opts . contentType ?. toLowerCase ( ) . trim ( ) ;
25- if ( mime ) {
26- const baseMime = mime . split ( ";" ) [ 0 ] . trim ( ) ;
27- if ( VOICE_MIME_TYPES . has ( baseMime ) ) {
28- return true ;
29- }
24+ const mime = normalizeMimeType ( opts . contentType ) ;
25+ if ( mime && TELEGRAM_VOICE_MIME_TYPES . has ( mime ) ) {
26+ return true ;
3027 }
3128 const fileName = opts . fileName ?. trim ( ) ;
3229 if ( ! fileName ) {
@@ -36,5 +33,16 @@ export function isVoiceCompatibleAudio(opts: {
3633 if ( ! ext ) {
3734 return false ;
3835 }
39- return VOICE_AUDIO_EXTENSIONS . has ( ext ) ;
36+ return TELEGRAM_VOICE_AUDIO_EXTENSIONS . has ( ext ) ;
37+ }
38+
39+ /**
40+ * Backward-compatible alias used across plugin/runtime call sites.
41+ * Keeps existing behavior while making Telegram-specific policy explicit.
42+ */
43+ export function isVoiceCompatibleAudio ( opts : {
44+ contentType ?: string | null ;
45+ fileName ?: string | null ;
46+ } ) : boolean {
47+ return isTelegramVoiceCompatibleAudio ( opts ) ;
4048}
0 commit comments