fix: flip audio default to file (backward compat)
- Default: sendAudio (file with metadata) - preserves old behavior - Opt-in: [[audio_as_voice]] tag for voice bubble This is non-breaking - existing integrations keep working.
This commit is contained in:
committed by
Peter Steinberger
parent
262f8a8d45
commit
2972fce02c
@@ -1,22 +1,23 @@
|
||||
/**
|
||||
* Extract audio mode tag from text.
|
||||
* Supports [[audio_as_file]] to send audio as file instead of voice bubble.
|
||||
* Supports [[audio_as_voice]] to send audio as voice bubble instead of file.
|
||||
* Default is file (preserves backward compatibility).
|
||||
*/
|
||||
export function extractAudioTag(text?: string): {
|
||||
cleaned: string;
|
||||
audioAsVoice: boolean;
|
||||
hasTag: boolean;
|
||||
} {
|
||||
if (!text) return { cleaned: "", audioAsVoice: true, hasTag: false };
|
||||
if (!text) return { cleaned: "", audioAsVoice: false, hasTag: false };
|
||||
let cleaned = text;
|
||||
let audioAsVoice = true; // default: voice bubble
|
||||
let audioAsVoice = false; // default: audio file (backward compatible)
|
||||
let hasTag = false;
|
||||
|
||||
// [[audio_as_file]] -> send as file with metadata, not voice bubble
|
||||
const fileMatch = cleaned.match(/\[\[audio_as_file\]\]/i);
|
||||
if (fileMatch) {
|
||||
cleaned = cleaned.replace(/\[\[audio_as_file\]\]/gi, " ");
|
||||
audioAsVoice = false;
|
||||
// [[audio_as_voice]] -> send as voice bubble (opt-in)
|
||||
const voiceMatch = cleaned.match(/\[\[audio_as_voice\]\]/i);
|
||||
if (voiceMatch) {
|
||||
cleaned = cleaned.replace(/\[\[audio_as_voice\]\]/gi, " ");
|
||||
audioAsVoice = true;
|
||||
hasTag = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1250,12 +1250,14 @@ async function deliverReplies(params: {
|
||||
...mediaParams,
|
||||
});
|
||||
} else if (kind === "audio") {
|
||||
const useVoice = reply.audioAsVoice === true; // default false
|
||||
const useVoice = reply.audioAsVoice === true; // default false (backward compatible)
|
||||
if (useVoice) {
|
||||
// Voice message - displays as round playable bubble (opt-in via [[audio_as_voice]])
|
||||
await bot.api.sendVoice(chatId, file, {
|
||||
...mediaParams,
|
||||
});
|
||||
} else {
|
||||
// Audio file - displays with metadata (title, duration) - DEFAULT
|
||||
await bot.api.sendAudio(chatId, file, {
|
||||
...mediaParams,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user