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.
|
* 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): {
|
export function extractAudioTag(text?: string): {
|
||||||
cleaned: string;
|
cleaned: string;
|
||||||
audioAsVoice: boolean;
|
audioAsVoice: boolean;
|
||||||
hasTag: boolean;
|
hasTag: boolean;
|
||||||
} {
|
} {
|
||||||
if (!text) return { cleaned: "", audioAsVoice: true, hasTag: false };
|
if (!text) return { cleaned: "", audioAsVoice: false, hasTag: false };
|
||||||
let cleaned = text;
|
let cleaned = text;
|
||||||
let audioAsVoice = true; // default: voice bubble
|
let audioAsVoice = false; // default: audio file (backward compatible)
|
||||||
let hasTag = false;
|
let hasTag = false;
|
||||||
|
|
||||||
// [[audio_as_file]] -> send as file with metadata, not voice bubble
|
// [[audio_as_voice]] -> send as voice bubble (opt-in)
|
||||||
const fileMatch = cleaned.match(/\[\[audio_as_file\]\]/i);
|
const voiceMatch = cleaned.match(/\[\[audio_as_voice\]\]/i);
|
||||||
if (fileMatch) {
|
if (voiceMatch) {
|
||||||
cleaned = cleaned.replace(/\[\[audio_as_file\]\]/gi, " ");
|
cleaned = cleaned.replace(/\[\[audio_as_voice\]\]/gi, " ");
|
||||||
audioAsVoice = false;
|
audioAsVoice = true;
|
||||||
hasTag = true;
|
hasTag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1250,12 +1250,14 @@ async function deliverReplies(params: {
|
|||||||
...mediaParams,
|
...mediaParams,
|
||||||
});
|
});
|
||||||
} else if (kind === "audio") {
|
} else if (kind === "audio") {
|
||||||
const useVoice = reply.audioAsVoice === true; // default false
|
const useVoice = reply.audioAsVoice === true; // default false (backward compatible)
|
||||||
if (useVoice) {
|
if (useVoice) {
|
||||||
|
// Voice message - displays as round playable bubble (opt-in via [[audio_as_voice]])
|
||||||
await bot.api.sendVoice(chatId, file, {
|
await bot.api.sendVoice(chatId, file, {
|
||||||
...mediaParams,
|
...mediaParams,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// Audio file - displays with metadata (title, duration) - DEFAULT
|
||||||
await bot.api.sendAudio(chatId, file, {
|
await bot.api.sendAudio(chatId, file, {
|
||||||
...mediaParams,
|
...mediaParams,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user