From 763a9f365498a8e10a3231b9d6365e8d61939c7c Mon Sep 17 00:00:00 2001 From: Anillc Date: Sat, 8 Jul 2023 20:23:16 +0800 Subject: [PATCH] fix(telegram): voice is resource, fix koishijs/koishi#1127 --- adapters/telegram/src/bot.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/adapters/telegram/src/bot.ts b/adapters/telegram/src/bot.ts index 84e67d58..8454d5f9 100644 --- a/adapters/telegram/src/bot.ts +++ b/adapters/telegram/src/bot.ts @@ -125,11 +125,12 @@ export class TelegramBot exte segments.push(h('text', { content: ' ' })) } - const addResource = async (type: string, data: Telegram.Animation | Telegram.Video | Telegram.Document) => { - segments.push(h(type, { - ...await this.$getFileFromId(data.file_id), - filename: data.file_name, - })) + const addResource = async (type: string, data: Telegram.Animation | Telegram.Video | Telegram.Document | Telegram.Voice) => { + const attrs: Dict = await this.$getFileFromId(data.file_id) + if (data['file_name']) { + attrs.filename = data['file_name'] + } + segments.push(h(type, attrs)) } if (message.location) { @@ -152,7 +153,7 @@ export class TelegramBot exte segments.push(h('text', { content: `[${message.sticker.set_name || 'sticker'} ${message.sticker.emoji || ''}]` })) } } else if (message.voice) { - segments.push(h('audio', await this.internal.getFile({ file_id: message.voice.file_id }))) + await addResource('audio', message.voice) } else if (message.animation) { await addResource('image', message.animation) } else if (message.video) {