From cf1f13230c9ae7cbc719606dee9a06f12c6ebca4 Mon Sep 17 00:00:00 2001 From: idanran <96647698+idanran@users.noreply.github.com> Date: Sat, 5 Aug 2023 21:58:00 +0800 Subject: [PATCH] fix(telegram): telegram sticky file mime type (#136) --- adapters/telegram/package.json | 1 + adapters/telegram/src/bot.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/adapters/telegram/package.json b/adapters/telegram/package.json index a88bbadd..5a6d4a4e 100644 --- a/adapters/telegram/package.json +++ b/adapters/telegram/package.json @@ -33,6 +33,7 @@ "@satorijs/satori": "^2.6.0" }, "dependencies": { + "file-type": "^16.5.4", "form-data": "^4.0.0" } } diff --git a/adapters/telegram/src/bot.ts b/adapters/telegram/src/bot.ts index d8261417..585951d8 100644 --- a/adapters/telegram/src/bot.ts +++ b/adapters/telegram/src/bot.ts @@ -4,6 +4,7 @@ import { adaptAuthorMeta, adaptGuildMember, adaptMessageMeta, adaptUser } from ' import { TelegramMessageEncoder } from './message' import { HttpServer } from './server' import { HttpPolling } from './polling' +import FileType from 'file-type' const logger = new Logger('telegram') @@ -267,7 +268,10 @@ export class TelegramBot exte if (this.server) { return { url: `${this.server}/${filePath}` } } - const { mime, data } = await this.$getFile(filePath) + let { mime, data } = await this.$getFile(filePath) + if (mime === 'application/octet-stream') { + mime = await FileType.fromBuffer(data)?.mime + } const base64 = `data:${mime};base64,` + arrayBufferToBase64(data) return { url: base64 } }