feat(telegram): use sendVoice for audio with opt-out
Use Telegram's sendVoice API for audio files by default, displaying them as round playable voice bubbles instead of file attachments. Changes: - Add asVoice option to TelegramSendOpts (defaults to true) - When asVoice is true (default): use api.sendVoice() for voice bubbles - When asVoice is false: use api.sendAudio() for traditional audio files This gives callers control: voice messages for TTS/quick responses, audio files for music/podcasts with metadata display.
This commit is contained in:
committed by
Peter Steinberger
parent
857a14b097
commit
20fd9f7f67
@@ -18,6 +18,8 @@ type TelegramSendOpts = {
|
|||||||
maxBytes?: number;
|
maxBytes?: number;
|
||||||
api?: Bot["api"];
|
api?: Bot["api"];
|
||||||
retry?: RetryConfig;
|
retry?: RetryConfig;
|
||||||
|
/** Send audio as voice message (voice bubble) instead of audio file. Defaults to false. */
|
||||||
|
asVoice?: boolean;
|
||||||
/** Message ID to reply to (for threading) */
|
/** Message ID to reply to (for threading) */
|
||||||
replyToMessageId?: number;
|
replyToMessageId?: number;
|
||||||
/** Forum topic thread ID (for forum supergroups) */
|
/** Forum topic thread ID (for forum supergroups) */
|
||||||
@@ -160,6 +162,7 @@ export async function sendMessageTelegram(
|
|||||||
| Awaited<ReturnType<typeof api.sendPhoto>>
|
| Awaited<ReturnType<typeof api.sendPhoto>>
|
||||||
| Awaited<ReturnType<typeof api.sendVideo>>
|
| Awaited<ReturnType<typeof api.sendVideo>>
|
||||||
| Awaited<ReturnType<typeof api.sendAudio>>
|
| Awaited<ReturnType<typeof api.sendAudio>>
|
||||||
|
| Awaited<ReturnType<typeof api.sendVoice>>
|
||||||
| Awaited<ReturnType<typeof api.sendAnimation>>
|
| Awaited<ReturnType<typeof api.sendAnimation>>
|
||||||
| Awaited<ReturnType<typeof api.sendDocument>>;
|
| Awaited<ReturnType<typeof api.sendDocument>>;
|
||||||
if (isGif) {
|
if (isGif) {
|
||||||
@@ -184,12 +187,22 @@ export async function sendMessageTelegram(
|
|||||||
throw wrapChatNotFound(err);
|
throw wrapChatNotFound(err);
|
||||||
});
|
});
|
||||||
} else if (kind === "audio") {
|
} else if (kind === "audio") {
|
||||||
result = await request(
|
const useVoice = opts.asVoice === true; // default false (backward compatible)
|
||||||
() => api.sendAudio(chatId, file, mediaParams),
|
if (useVoice) {
|
||||||
"audio",
|
result = await request(
|
||||||
).catch((err) => {
|
() => api.sendVoice(chatId, file, mediaParams),
|
||||||
throw wrapChatNotFound(err);
|
"voice",
|
||||||
});
|
).catch((err) => {
|
||||||
|
throw wrapChatNotFound(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result = await request(
|
||||||
|
() => api.sendAudio(chatId, file, mediaParams),
|
||||||
|
"audio",
|
||||||
|
).catch((err) => {
|
||||||
|
throw wrapChatNotFound(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result = await request(
|
result = await request(
|
||||||
() => api.sendDocument(chatId, file, mediaParams),
|
() => api.sendDocument(chatId, file, mediaParams),
|
||||||
|
|||||||
Reference in New Issue
Block a user