Skip to content

Commit

Permalink
fix(telegram): voice is resource, fix koishijs/koishi#1127 (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anillc authored Jul 8, 2023
1 parent 3354eea commit c0bcd7a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions adapters/telegram/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ export class TelegramBot<T extends TelegramBot.Config = TelegramBot.Config> 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<string> = await this.$getFileFromId(data.file_id)
if (data['file_name']) {
attrs.filename = data['file_name']
}
segments.push(h(type, attrs))
}

if (message.location) {
Expand All @@ -152,7 +153,7 @@ export class TelegramBot<T extends TelegramBot.Config = TelegramBot.Config> 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) {
Expand Down

0 comments on commit c0bcd7a

Please sign in to comment.