* Extract attachments from a Telegram message (photo, document, audio, video, voice).
(
msg: TelegramBot.Message,
channelId: string,
)
| 320 | * Extract attachments from a Telegram message (photo, document, audio, video, voice). |
| 321 | */ |
| 322 | private async extractAttachments( |
| 323 | msg: TelegramBot.Message, |
| 324 | channelId: string, |
| 325 | ): Promise<ChannelAttachment[]> { |
| 326 | if (!this.bot) return []; |
| 327 | |
| 328 | const attachments: ChannelAttachment[] = []; |
| 329 | |
| 330 | try { |
| 331 | // Photo (take highest resolution) |
| 332 | if (msg.photo && msg.photo.length > 0) { |
| 333 | const photo = msg.photo[msg.photo.length - 1]; |
| 334 | const attachment = await this.downloadTelegramFile( |
| 335 | photo.file_id, |
| 336 | channelId, |
| 337 | "photo.jpg", |
| 338 | "image/jpeg", |
| 339 | ); |
| 340 | if (attachment) attachments.push(attachment); |
| 341 | } |
| 342 | |
| 343 | // Document |
| 344 | if (msg.document) { |
| 345 | const attachment = await this.downloadTelegramFile( |
| 346 | msg.document.file_id, |
| 347 | channelId, |
| 348 | msg.document.file_name || "document", |
| 349 | msg.document.mime_type, |
| 350 | ); |
| 351 | if (attachment) attachments.push(attachment); |
| 352 | } |
| 353 | |
| 354 | // Audio |
| 355 | if (msg.audio) { |
| 356 | const attachment = await this.downloadTelegramFile( |
| 357 | msg.audio.file_id, |
| 358 | channelId, |
| 359 | (msg.audio as any).file_name || "audio.mp3", |
| 360 | msg.audio.mime_type, |
| 361 | ); |
| 362 | if (attachment) attachments.push(attachment); |
| 363 | } |
| 364 | |
| 365 | // Video |
| 366 | if (msg.video) { |
| 367 | const attachment = await this.downloadTelegramFile( |
| 368 | msg.video.file_id, |
| 369 | channelId, |
| 370 | (msg.video as any).file_name || "video.mp4", |
| 371 | msg.video.mime_type, |
| 372 | ); |
| 373 | if (attachment) attachments.push(attachment); |
| 374 | } |
| 375 | |
| 376 | // Voice |
| 377 | if (msg.voice) { |
| 378 | const attachment = await this.downloadTelegramFile( |
| 379 | msg.voice.file_id, |
no test coverage detected