From 3e891d50fd8c3eabda876cb60daa038ae2f8133b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 3 Aug 2021 11:33:52 +0600 Subject: [PATCH] downloadFile for MediaContent --- CHANGELOG.md | 2 ++ .../dev/inmo/tgbotapi/extensions/api/DownloadFile.kt | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6806ed75fa..87391ebe07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `Klock`: `2.2.0` -> `2.3.1` * `Ktor`: `1.6.1` -> `1.6.2` * `MicroUtils`: `0.5.16` -> `0.5.17` +* `API`: + * New extension `TelegramBot#downloadFile` for any `MediaContent` * `Behaviour Builder`: * New provider `defaultCoroutineScopeProvider` * Now it is not necessary to provide `CoroutineScope` to `TelegramBot#buildBehaviour` diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DownloadFile.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DownloadFile.kt index 5d6b5efee7..7f653730b6 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DownloadFile.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DownloadFile.kt @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.files.PathedFile import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent suspend fun TelegramBot.downloadFile( filePath: String @@ -30,3 +31,9 @@ suspend fun TelegramBot.downloadFile( ): ByteArray = downloadFile( getFileAdditionalInfo(file) ) + +suspend fun TelegramBot.downloadFile( + file: MediaContent +): ByteArray = downloadFile( + getFileAdditionalInfo(file.media) +)