Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(telegram): voice is resource, fix koishijs/koishi#1127 #130

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading